-
Notifications
You must be signed in to change notification settings - Fork 2
159 lines (145 loc) · 5.7 KB
/
agent-memory-sync.yml
File metadata and controls
159 lines (145 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Agent / Memory / Sync GitHub Artifacts
on:
workflow_dispatch:
inputs:
since:
description: "Optional ISO timestamp override for the sync window"
required: false
default: ""
lookback_days:
description: "Fallback lookback window in days when no prior sync state exists"
required: false
default: "30"
memory_ref:
description: "Memory branch to update"
required: false
default: agent/memory
schedule:
- cron: "17 */6 * * *"
permissions:
contents: write
discussions: read
issues: read
pull-requests: read
id-token: write # required for GitHub Actions OIDC broker exchange
concurrency:
group: agent-memory-${{ github.repository }}-sync
cancel-in-progress: false
jobs:
gate:
if: vars.AGENT_ENABLED != 'false'
runs-on: ${{ fromJson(vars.AGENT_RUNS_ON || '["ubuntu-latest"]') }}
outputs:
skip: ${{ steps.gate.outputs.skip }}
mode: ${{ steps.gate.outputs.mode }}
reason: ${{ steps.gate.outputs.reason }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
persist-credentials: false
ref: ${{ github.event.repository.default_branch }}
token: ${{ github.token }}
- name: Resolve scheduled activity gate
id: gate
uses: ./.github/actions/scheduled-activity-gate
with:
github_token: ${{ github.token }}
schedule_policy: ${{ vars.AGENT_SCHEDULE_POLICY || '' }}
workflow: agent-memory-sync.yml
sync:
needs: gate
if: vars.AGENT_ENABLED != 'false' && needs.gate.outputs.skip != 'true'
runs-on: ${{ fromJson(vars.AGENT_RUNS_ON || '["ubuntu-latest"]') }}
env:
MEMORY_REF: ${{ inputs.memory_ref || vars.AGENT_MEMORY_REF || 'agent/memory' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event.repository.default_branch }}
token: ${{ github.token }}
- name: Resolve GitHub auth
id: auth
uses: ./.github/actions/resolve-github-auth
with:
app_id: ${{ secrets.AGENT_APP_ID }}
app_private_key: ${{ secrets.AGENT_APP_PRIVATE_KEY }}
pat: ${{ secrets.AGENT_PAT }}
fallback_token: ${{ github.token }}
- name: Setup agent runtime
id: runtime
uses: ./.github/actions/setup-agent-runtime
- name: Read memory sync state
id: state
env:
GH_TOKEN: ${{ steps.auth.outputs.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
INPUT_GITHUB_TOKEN: ${{ steps.auth.outputs.token }}
run: node .agent/dist/cli/memory/read-sync-state.js
- name: Resolve sync window
id: window
env:
LOOKBACK_DAYS: ${{ inputs.lookback_days || '30' }}
PREVIOUS_LAST_SYNC: ${{ steps.state.outputs.last_sync_at }}
SINCE_OVERRIDE: ${{ inputs.since || '' }}
run: |
set -euo pipefail
started_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
if [ -n "$SINCE_OVERRIDE" ]; then
since="$SINCE_OVERRIDE"
elif [ -n "$PREVIOUS_LAST_SYNC" ]; then
since="$PREVIOUS_LAST_SYNC"
else
since=""
fi
echo "started_at=$started_at" >> "$GITHUB_OUTPUT"
echo "since=$since" >> "$GITHUB_OUTPUT"
- name: Download memory branch
id: memory
uses: ./.github/actions/download-agent-memory
with:
github_token: ${{ steps.auth.outputs.token }}
ref: ${{ env.MEMORY_REF }}
path: ${{ runner.temp }}/agent-memory
continue_on_missing: "true"
bootstrap_if_missing: "true"
- name: Sync GitHub artifacts into memory
id: sync
env:
GH_TOKEN: ${{ steps.auth.outputs.token }}
GITHUB_TOKEN: ${{ steps.auth.outputs.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
INPUT_GITHUB_TOKEN: ${{ steps.auth.outputs.token }}
MEMORY_DIR: ${{ runner.temp }}/agent-memory
MEMORY_SYNC_LOOKBACK_DAYS: ${{ inputs.lookback_days || '30' }}
MEMORY_SYNC_SINCE: ${{ steps.window.outputs.since }}
MEMORY_SYNC_STARTED_AT: ${{ steps.window.outputs.started_at }}
REPO_SLUG: ${{ github.repository }}
run: node .agent/dist/cli/memory/sync-github-artifacts.js
- name: Commit and push memory branch
if: steps.sync.outcome == 'success'
working-directory: ${{ runner.temp }}/agent-memory
env:
BRANCH: ${{ env.MEMORY_REF }}
COMMIT_CWD: ${{ runner.temp }}/agent-memory
COMMIT_MESSAGE: "chore(memory): sync github artifacts"
GITHUB_REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ steps.auth.outputs.token }}
SET_UPSTREAM: "true"
run: node ${{ github.workspace }}/.agent/dist/cli/commit.js
- name: Write memory sync state
if: steps.sync.outcome == 'success'
env:
GITHUB_REPOSITORY: ${{ github.repository }}
INPUT_GITHUB_TOKEN: ${{ steps.auth.outputs.token }}
REPO_SLUG: ${{ github.repository }}
SYNC_COMMIT_CURSOR: ${{ steps.sync.outputs.commit_cursor }}
SYNC_DISCUSSION_CURSOR: ${{ steps.sync.outputs.discussion_cursor }}
SYNC_ISSUE_CURSOR: ${{ steps.sync.outputs.issue_cursor }}
SYNC_LAST_ACTIVITY_AT: ${{ steps.sync.outputs.last_activity_at }}
SYNC_LAST_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SYNC_LAST_SYNC_AT: ${{ steps.window.outputs.started_at }}
SYNC_PULL_CURSOR: ${{ steps.sync.outputs.pull_cursor }}
run: node .agent/dist/cli/memory/write-sync-state.js