@evomap/evolver-cli 2.0.46 → 2.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autoexec.d.ts +1 -2
- package/dist/autoexec.js +2 -7
- package/dist/cliEntry.js +8 -0
- package/dist/commandCatalog.d.ts +4 -0
- package/dist/commandCatalog.js +4 -0
- package/dist/dispatch.js +8 -0
- package/dist/experience.d.ts +2 -0
- package/dist/experience.js +229 -0
- package/dist/feedbackDestinationIdentity.d.ts +1 -0
- package/dist/feedbackDestinationIdentity.js +8 -0
- package/dist/kernelTriggerFeedback.d.ts +13 -0
- package/dist/kernelTriggerFeedback.js +65 -0
- package/dist/lifecycle.js +4 -1
- package/dist/lifecycleBootstrapTransaction.js +13 -7
- package/dist/localMemoryGraph.d.ts +38 -0
- package/dist/localMemoryGraph.js +192 -7
- package/dist/localTriggerFeedback.d.ts +30 -0
- package/dist/localTriggerFeedback.js +126 -0
- package/dist/mcpStdio.d.ts +1 -0
- package/dist/mcpStdio.js +9 -0
- package/dist/plugin.d.ts +8 -0
- package/dist/plugin.js +132 -0
- package/dist/pluginBundle.d.ts +3 -0
- package/dist/pluginBundle.js +94 -0
- package/dist/pluginHosts.d.ts +36 -0
- package/dist/pluginHosts.js +120 -0
- package/dist/pluginInspection.d.ts +22 -0
- package/dist/pluginInspection.js +237 -0
- package/dist/pluginInstall.d.ts +19 -0
- package/dist/pluginInstall.js +84 -0
- package/dist/pluginLock.d.ts +4 -0
- package/dist/pluginLock.js +52 -0
- package/dist/pluginRuntime.d.ts +31 -0
- package/dist/pluginRuntime.js +191 -0
- package/dist/recipe.d.ts +1 -1
- package/dist/recipe.js +14 -5
- package/dist/setupHooks.js +5 -3
- package/dist/setupHooksLifecycle.d.ts +2 -0
- package/dist/setupHooksLifecycle.js +52 -52
- package/dist/sourceQualification.js +6 -2
- package/dist/triggerFeedbackCli.d.ts +15 -0
- package/dist/triggerFeedbackCli.js +146 -0
- package/dist/triggerFeedbackDelivery.d.ts +9 -0
- package/dist/triggerFeedbackDelivery.js +29 -0
- package/dist/triggerFeedbackHub.d.ts +7 -0
- package/dist/triggerFeedbackHub.js +62 -0
- package/dist/triggerFeedbackRecovery.d.ts +15 -0
- package/dist/triggerFeedbackRecovery.js +124 -0
- package/dist/triggerFeedbackSync.d.ts +23 -0
- package/dist/triggerFeedbackSync.js +98 -0
- package/dist/triggerFeedbackSyncState.d.ts +42 -0
- package/dist/triggerFeedbackSyncState.js +112 -0
- package/package.json +7 -7
package/dist/localMemoryGraph.js
CHANGED
|
@@ -4,6 +4,8 @@ import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:pat
|
|
|
4
4
|
import { userInfo } from 'node:os';
|
|
5
5
|
import { gzipSync, gunzipSync } from 'node:zlib';
|
|
6
6
|
import { reference, algo, events, util } from '@evomap/evolver-core';
|
|
7
|
+
import { MAX_TRIGGER_FEEDBACK_BYTES, TRIGGER_FEEDBACK_FILE, readLocalTriggerFeedback, upsertLocalTriggerFeedback, triggerFeedbackRecords } from './localTriggerFeedback.js';
|
|
8
|
+
import { authorizeTriggerFeedbackDelivery, claimTriggerFeedbackDelivery, markTriggerFeedbackDispatched, settleTriggerFeedbackDelivery } from './triggerFeedbackSyncState.js';
|
|
7
9
|
const ACTIVE_FILE = 'memory_graph.v2.jsonl';
|
|
8
10
|
const COMPACT_FILE = 'memory_graph.compact.jsonl';
|
|
9
11
|
const LOCK_FILE = 'memory_graph.lock';
|
|
@@ -96,6 +98,8 @@ export class LocalMemoryGraph {
|
|
|
96
98
|
}
|
|
97
99
|
return true;
|
|
98
100
|
});
|
|
101
|
+
const feedback = this.readTriggerFeedbackUnlocked();
|
|
102
|
+
records.push(...triggerFeedbackRecords(feedback, this.readableUserScopes, workspaceScope, this.readEpochState().epochId));
|
|
99
103
|
if (this.rotationCleanupFailed)
|
|
100
104
|
diagnostics.recovery = 'degraded';
|
|
101
105
|
if (records.length === 0 && diagnostics.recovery === 'healthy')
|
|
@@ -110,6 +114,184 @@ export class LocalMemoryGraph {
|
|
|
110
114
|
throw error;
|
|
111
115
|
}
|
|
112
116
|
}
|
|
117
|
+
/** @internal Only the bound kernel reader supplies snapshots; CLI/MCP callers provide a run id, never a score. */
|
|
118
|
+
applyKernelTriggerFeedback(snapshot, destinationId) {
|
|
119
|
+
const result = this.applyKernelTriggerFeedbackBatch([snapshot], destinationId)[0];
|
|
120
|
+
if (!result)
|
|
121
|
+
throw new Error('trigger_feedback_local_unverified');
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
applyKernelTriggerFeedbackBatch(snapshots, destinationId) {
|
|
125
|
+
return this.changeTriggerFeedbackFile((file) => {
|
|
126
|
+
const epochId = this.readEpochState().epochId;
|
|
127
|
+
let current = file;
|
|
128
|
+
const result = snapshots.map((snapshot) => {
|
|
129
|
+
const workspaceScope = snapshot.workspace === null ? null : this.workspaceScope(snapshot.workspace);
|
|
130
|
+
if (snapshot.workspace !== null && workspaceScope === null)
|
|
131
|
+
throw new Error('trigger_feedback_workspace_unavailable');
|
|
132
|
+
const updated = upsertLocalTriggerFeedback(current, snapshot, { userScope: this.userScope, workspaceScope, epochId });
|
|
133
|
+
current = updated.file;
|
|
134
|
+
let changed = updated.changed;
|
|
135
|
+
if (destinationId) {
|
|
136
|
+
const delivery = authorizeTriggerFeedbackDelivery(updated.row.delivery, snapshot, epochId, destinationId);
|
|
137
|
+
changed ||= JSON.stringify(delivery) !== JSON.stringify(updated.row.delivery);
|
|
138
|
+
current = { ...current, rows: current.rows.map((row) => row.userScope === this.userScope && row.state.snapshot.runId === snapshot.runId ? { ...row, delivery } : row) };
|
|
139
|
+
}
|
|
140
|
+
return { committed: updated.row.state.snapshot.commit, changed, resetSuppressed: updated.resetSuppressed };
|
|
141
|
+
});
|
|
142
|
+
return { file: current, result };
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
readTriggerFeedback(runId) {
|
|
146
|
+
return this.withGraphLock(() => this.readTriggerFeedbackUnlocked().rows.find((row) => row.userScope === this.userScope && row.state.snapshot.runId === runId)?.state ?? null);
|
|
147
|
+
}
|
|
148
|
+
triggerFeedbackSourceAvailable(runId) {
|
|
149
|
+
if (!existsSync(join(this.dir, TRIGGER_FEEDBACK_FILE)))
|
|
150
|
+
return false;
|
|
151
|
+
return this.withGraphLock(() => {
|
|
152
|
+
const row = this.readTriggerFeedbackUnlocked().rows.find((row) => row.userScope === this.userScope && row.state.snapshot.runId === runId);
|
|
153
|
+
return Boolean(row && row.sourceAvailable !== false && row.epochId === this.readEpochState().epochId);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
readTriggerFeedbackDelivery(runId) {
|
|
157
|
+
return this.withGraphLock(() => {
|
|
158
|
+
const row = this.readTriggerFeedbackUnlocked().rows.find((row) => row.userScope === this.userScope && row.state.snapshot.runId === runId);
|
|
159
|
+
const state = row?.delivery;
|
|
160
|
+
if (state && state.consentEpoch !== this.readEpochState().epochId)
|
|
161
|
+
return { ...state, status: 'blocked', reason: 'trigger_feedback_reset_requires_consent' };
|
|
162
|
+
return state ?? null;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
readTriggerFeedbackDeliveries(after = null, limit = 25) {
|
|
166
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100)
|
|
167
|
+
throw new Error('trigger_feedback_invalid_input');
|
|
168
|
+
if (!existsSync(join(this.dir, TRIGGER_FEEDBACK_FILE)))
|
|
169
|
+
return [];
|
|
170
|
+
return this.withGraphLock(() => this.readTriggerFeedbackUnlocked().rows
|
|
171
|
+
.filter((row) => row.userScope === this.userScope && row.delivery && row.delivery.status !== 'confirmed' && (after === null || row.state.snapshot.runId > after))
|
|
172
|
+
.slice(0, limit).map((row) => ({ snapshot: row.state.snapshot, delivery: row.delivery })));
|
|
173
|
+
}
|
|
174
|
+
markTriggerFeedbackSourceUnavailable(runId) {
|
|
175
|
+
if (!existsSync(join(this.dir, TRIGGER_FEEDBACK_FILE)))
|
|
176
|
+
return;
|
|
177
|
+
this.changeTriggerFeedbackFile((file) => ({ file: { ...file, rows: file.rows.map((row) => row.userScope === this.userScope && (runId === undefined || row.state.snapshot.runId === runId) ? { ...row, sourceAvailable: false } : row) }, result: undefined }));
|
|
178
|
+
}
|
|
179
|
+
authorizeTriggerFeedbackDelivery(runId, destinationId) {
|
|
180
|
+
return this.changeTriggerFeedbackDelivery(runId, (prior, snapshot) => authorizeTriggerFeedbackDelivery(prior, snapshot, this.readEpochState().epochId, destinationId));
|
|
181
|
+
}
|
|
182
|
+
claimTriggerFeedbackDelivery(runId, destinationId, id) {
|
|
183
|
+
let claimed = false;
|
|
184
|
+
let reconcile = false;
|
|
185
|
+
const state = this.changeTriggerFeedbackDelivery(runId, (prior) => {
|
|
186
|
+
if (!prior)
|
|
187
|
+
throw new Error('trigger_feedback_consent_missing');
|
|
188
|
+
if (prior.consentEpoch !== this.readEpochState().epochId)
|
|
189
|
+
return { ...prior, status: 'blocked', reason: 'trigger_feedback_reset_requires_consent' };
|
|
190
|
+
const result = claimTriggerFeedbackDelivery(prior, destinationId, id, this.now());
|
|
191
|
+
claimed = result.claimed;
|
|
192
|
+
reconcile = result.reconcile;
|
|
193
|
+
return result.state;
|
|
194
|
+
});
|
|
195
|
+
return { state, claimed, reconcile };
|
|
196
|
+
}
|
|
197
|
+
markTriggerFeedbackDispatched(runId, id) {
|
|
198
|
+
this.changeTriggerFeedbackDelivery(runId, (prior) => {
|
|
199
|
+
if (!prior)
|
|
200
|
+
throw new Error('trigger_feedback_consent_missing');
|
|
201
|
+
if (prior.consentEpoch !== this.readEpochState().epochId)
|
|
202
|
+
throw new Error('trigger_feedback_reset_requires_consent');
|
|
203
|
+
return markTriggerFeedbackDispatched(prior, id, this.now());
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
settleTriggerFeedbackDelivery(runId, id, result) {
|
|
207
|
+
return this.changeTriggerFeedbackDelivery(runId, (prior) => {
|
|
208
|
+
if (!prior)
|
|
209
|
+
throw new Error('trigger_feedback_consent_missing');
|
|
210
|
+
return settleTriggerFeedbackDelivery(prior, id, result, this.now());
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
readTriggerFeedbackRecoveryCursor(kind = 'native') {
|
|
214
|
+
if (!existsSync(join(this.dir, TRIGGER_FEEDBACK_FILE)))
|
|
215
|
+
return null;
|
|
216
|
+
return this.withGraphLock(() => {
|
|
217
|
+
const file = this.readTriggerFeedbackUnlocked();
|
|
218
|
+
return (kind === 'native' ? file.recoveryCursors : file.deliveryCursors)?.[this.userScope] ?? null;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
saveTriggerFeedbackRecoveryCursor(after, kind = 'native') {
|
|
222
|
+
if (after !== null && (!after.trim() || Buffer.byteLength(after) > 256))
|
|
223
|
+
throw new Error('trigger_feedback_invalid_identity');
|
|
224
|
+
this.changeTriggerFeedbackFile((file) => {
|
|
225
|
+
const key = kind === 'native' ? 'recoveryCursors' : 'deliveryCursors';
|
|
226
|
+
return { file: { ...file, [key]: { ...file[key], [this.userScope]: after } }, result: undefined };
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
changeTriggerFeedbackDelivery(runId, change) {
|
|
230
|
+
return this.changeTriggerFeedbackFile((file) => {
|
|
231
|
+
const index = file.rows.findIndex((row) => row.userScope === this.userScope && row.state.snapshot.runId === runId);
|
|
232
|
+
const row = file.rows[index];
|
|
233
|
+
if (!row)
|
|
234
|
+
throw new Error('trigger_feedback_not_found');
|
|
235
|
+
const result = change(row.delivery, row.state.snapshot);
|
|
236
|
+
const rows = [...file.rows];
|
|
237
|
+
rows[index] = { ...row, delivery: result };
|
|
238
|
+
return { file: { ...file, rows }, result };
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
changeTriggerFeedbackFile(change) {
|
|
242
|
+
let published = false;
|
|
243
|
+
let completed = false;
|
|
244
|
+
let result;
|
|
245
|
+
try {
|
|
246
|
+
return this.withGraphLock(() => {
|
|
247
|
+
const current = this.readTriggerFeedbackUnlocked();
|
|
248
|
+
const next = change(current);
|
|
249
|
+
const path = join(this.dir, TRIGGER_FEEDBACK_FILE);
|
|
250
|
+
const bytes = Buffer.from(JSON.stringify(next.file));
|
|
251
|
+
if (bytes.length > MAX_TRIGGER_FEEDBACK_BYTES)
|
|
252
|
+
throw new Error('trigger_feedback_capacity');
|
|
253
|
+
if (JSON.stringify(current) !== bytes.toString('utf8')) {
|
|
254
|
+
this.writeAtomic(path, bytes, true);
|
|
255
|
+
published = true;
|
|
256
|
+
}
|
|
257
|
+
else if (existsSync(path)) {
|
|
258
|
+
const fd = openNoFollow(path, constants.O_RDWR, 0o600);
|
|
259
|
+
try {
|
|
260
|
+
fsyncSync(fd);
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
closeSync(fd);
|
|
264
|
+
}
|
|
265
|
+
this.syncGraphDirectory();
|
|
266
|
+
}
|
|
267
|
+
result = next.result;
|
|
268
|
+
completed = true;
|
|
269
|
+
return result;
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
if (published && completed && error instanceof util.LockReleaseError)
|
|
274
|
+
return result;
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
readTriggerFeedbackUnlocked() {
|
|
279
|
+
const path = join(this.dir, TRIGGER_FEEDBACK_FILE);
|
|
280
|
+
if (!existsSync(path))
|
|
281
|
+
return readLocalTriggerFeedback(null);
|
|
282
|
+
const bytes = this.readRawBounded(path, MAX_TRIGGER_FEEDBACK_BYTES);
|
|
283
|
+
if (bytes === null)
|
|
284
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
285
|
+
const fd = openNoFollow(path, constants.O_RDWR, 0o600);
|
|
286
|
+
try {
|
|
287
|
+
fsyncSync(fd);
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
closeSync(fd);
|
|
291
|
+
}
|
|
292
|
+
this.syncGraphDirectory();
|
|
293
|
+
return readLocalTriggerFeedback(bytes);
|
|
294
|
+
}
|
|
113
295
|
recordOutcome(input) {
|
|
114
296
|
if (!reference.isExecutionEligible(input, this.referenceScope))
|
|
115
297
|
return;
|
|
@@ -407,6 +589,7 @@ export class LocalMemoryGraph {
|
|
|
407
589
|
EPOCH_FILE,
|
|
408
590
|
ACTIVE_FILE,
|
|
409
591
|
COMPACT_FILE,
|
|
592
|
+
TRIGGER_FEEDBACK_FILE,
|
|
410
593
|
];
|
|
411
594
|
const state = [];
|
|
412
595
|
for (const name of names) {
|
|
@@ -499,13 +682,15 @@ export class LocalMemoryGraph {
|
|
|
499
682
|
}
|
|
500
683
|
}
|
|
501
684
|
readResetSource(file) {
|
|
502
|
-
const limit = file.name ===
|
|
503
|
-
?
|
|
504
|
-
: file.name ===
|
|
505
|
-
? this.
|
|
506
|
-
: file.name ===
|
|
507
|
-
? this.maxLineBytes
|
|
508
|
-
:
|
|
685
|
+
const limit = file.name === TRIGGER_FEEDBACK_FILE
|
|
686
|
+
? MAX_TRIGGER_FEEDBACK_BYTES
|
|
687
|
+
: file.name === ACTIVE_FILE
|
|
688
|
+
? this.maxActiveBytes + this.maxLineBytes
|
|
689
|
+
: file.name === COMPACT_FILE
|
|
690
|
+
? this.maxCompactBytes + this.maxLineBytes
|
|
691
|
+
: file.name === RECOVERY_FILE || file.name === EPOCH_FILE
|
|
692
|
+
? this.maxLineBytes
|
|
693
|
+
: this.maxActiveBytes + this.maxLineBytes;
|
|
509
694
|
if (file.identity.size > BigInt(limit))
|
|
510
695
|
throw new Error('memory_graph_reset_backup_failed');
|
|
511
696
|
const fd = openNoFollow(file.path, constants.O_RDONLY, 0o600);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { algo } from '@evomap/evolver-core';
|
|
2
|
+
import { type TriggerFeedbackDeliveryState } from './triggerFeedbackSyncState.js';
|
|
3
|
+
export declare const TRIGGER_FEEDBACK_FILE = "memory_graph.trigger_feedback.json";
|
|
4
|
+
export declare const MAX_TRIGGER_FEEDBACK_BYTES: number;
|
|
5
|
+
export interface LocalTriggerFeedbackRow {
|
|
6
|
+
userScope: string;
|
|
7
|
+
workspaceScope: string | null;
|
|
8
|
+
epochId: string;
|
|
9
|
+
state: algo.TriggerFeedbackState;
|
|
10
|
+
delivery?: TriggerFeedbackDeliveryState;
|
|
11
|
+
sourceAvailable?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface LocalTriggerFeedbackFile {
|
|
14
|
+
version: 2;
|
|
15
|
+
rows: LocalTriggerFeedbackRow[];
|
|
16
|
+
recoveryCursors?: Record<string, string | null>;
|
|
17
|
+
deliveryCursors?: Record<string, string | null>;
|
|
18
|
+
}
|
|
19
|
+
export declare function readLocalTriggerFeedback(bytes: Buffer | null): LocalTriggerFeedbackFile;
|
|
20
|
+
export declare function upsertLocalTriggerFeedback(file: LocalTriggerFeedbackFile, snapshot: algo.TriggerFeedbackSnapshot, owner: {
|
|
21
|
+
userScope: string;
|
|
22
|
+
workspaceScope: string | null;
|
|
23
|
+
epochId: string;
|
|
24
|
+
}): {
|
|
25
|
+
file: LocalTriggerFeedbackFile;
|
|
26
|
+
changed: boolean;
|
|
27
|
+
row: LocalTriggerFeedbackRow;
|
|
28
|
+
resetSuppressed: boolean;
|
|
29
|
+
};
|
|
30
|
+
export declare function triggerFeedbackRecords(file: LocalTriggerFeedbackFile, userScopes: ReadonlySet<string>, workspaceScope: string, epochId: string): algo.MemoryGraphOutcomeRecord[];
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { algo } from '@evomap/evolver-core';
|
|
2
|
+
import { advanceTriggerFeedbackDelivery, parseTriggerFeedbackDelivery } from './triggerFeedbackSyncState.js';
|
|
3
|
+
export const TRIGGER_FEEDBACK_FILE = 'memory_graph.trigger_feedback.json';
|
|
4
|
+
export const MAX_TRIGGER_FEEDBACK_BYTES = 32 * 1024 * 1024;
|
|
5
|
+
const MAX_TRIGGER_FEEDBACK_ROWS = 20_000;
|
|
6
|
+
export function readLocalTriggerFeedback(bytes) {
|
|
7
|
+
if (bytes === null)
|
|
8
|
+
return { version: 2, rows: [] };
|
|
9
|
+
if (bytes.length > MAX_TRIGGER_FEEDBACK_BYTES)
|
|
10
|
+
throw new Error('trigger_feedback_capacity');
|
|
11
|
+
const raw = JSON.parse(bytes.toString('utf8'));
|
|
12
|
+
const file = object(raw);
|
|
13
|
+
if ((file['version'] !== 1 && file['version'] !== 2) || !Array.isArray(file['rows']) || file['rows'].length > MAX_TRIGGER_FEEDBACK_ROWS)
|
|
14
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
15
|
+
const keys = new Set();
|
|
16
|
+
const rows = file['rows'].map((rawRow) => {
|
|
17
|
+
const row = object(rawRow);
|
|
18
|
+
const userScope = scope(row['userScope']);
|
|
19
|
+
const workspaceScope = row['workspaceScope'] === null ? null : scope(row['workspaceScope']);
|
|
20
|
+
const epochId = text(row['epochId']);
|
|
21
|
+
const stateRaw = object(row['state']);
|
|
22
|
+
if (stateRaw['version'] !== 1 || !Array.isArray(stateRaw['operations']) || stateRaw['operations'].length > 1024)
|
|
23
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
24
|
+
const snapshot = parseStoredSnapshot(stateRaw['snapshot']);
|
|
25
|
+
const operations = stateRaw['operations'].map((operation) => {
|
|
26
|
+
const parsed = parseStoredSnapshot({ ...snapshot, commit: operation });
|
|
27
|
+
if (!parsed.commit)
|
|
28
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
29
|
+
return parsed.commit;
|
|
30
|
+
});
|
|
31
|
+
let revision = 0;
|
|
32
|
+
const operationIds = new Set();
|
|
33
|
+
for (const operation of operations) {
|
|
34
|
+
if (operation.revision <= revision || operationIds.has(operation.operationId))
|
|
35
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
36
|
+
revision = operation.revision;
|
|
37
|
+
operationIds.add(operation.operationId);
|
|
38
|
+
}
|
|
39
|
+
if (JSON.stringify(operations.at(-1) ?? null) !== JSON.stringify(snapshot.commit))
|
|
40
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
41
|
+
const key = JSON.stringify([userScope, snapshot.runId]);
|
|
42
|
+
if (keys.has(key))
|
|
43
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
44
|
+
keys.add(key);
|
|
45
|
+
const delivery = parseTriggerFeedbackDelivery(row['delivery']);
|
|
46
|
+
if (delivery && delivery.desiredRevision > (snapshot.commit?.revision ?? 0))
|
|
47
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
48
|
+
if (row['sourceAvailable'] !== undefined && typeof row['sourceAvailable'] !== 'boolean')
|
|
49
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
50
|
+
return { userScope, workspaceScope, epochId, state: { version: 1, snapshot, operations }, ...(delivery ? { delivery } : {}), ...(row['sourceAvailable'] !== undefined ? { sourceAvailable: row['sourceAvailable'] } : {}) };
|
|
51
|
+
});
|
|
52
|
+
const parseCursors = (raw) => {
|
|
53
|
+
if (raw === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
const cursors = object(raw);
|
|
56
|
+
if (Object.keys(cursors).length > MAX_TRIGGER_FEEDBACK_ROWS)
|
|
57
|
+
throw new Error('trigger_feedback_capacity');
|
|
58
|
+
return Object.fromEntries(Object.entries(cursors).map(([user, after]) => [scope(user), after === null ? null : text(after)]));
|
|
59
|
+
};
|
|
60
|
+
const recoveryCursors = parseCursors(file['recoveryCursors']);
|
|
61
|
+
const deliveryCursors = parseCursors(file['deliveryCursors']);
|
|
62
|
+
return { version: 2, rows, ...(recoveryCursors ? { recoveryCursors } : {}), ...(deliveryCursors ? { deliveryCursors } : {}) };
|
|
63
|
+
}
|
|
64
|
+
export function upsertLocalTriggerFeedback(file, snapshot, owner) {
|
|
65
|
+
const index = file.rows.findIndex((row) => row.userScope === owner.userScope && row.state.snapshot.runId === snapshot.runId);
|
|
66
|
+
const prior = file.rows[index];
|
|
67
|
+
if (prior?.workspaceScope !== undefined && prior.workspaceScope !== null && owner.workspaceScope !== null && prior.workspaceScope !== owner.workspaceScope) {
|
|
68
|
+
throw new algo.TriggerFeedbackConflictError('baseline_conflict');
|
|
69
|
+
}
|
|
70
|
+
const state = algo.updateTriggerFeedbackState(prior?.state, snapshot);
|
|
71
|
+
const resetSuppressed = Boolean(prior && prior.epochId !== owner.epochId && (snapshot.commit?.revision ?? 0) === (prior.state.snapshot.commit?.revision ?? 0));
|
|
72
|
+
const row = {
|
|
73
|
+
...owner, workspaceScope: owner.workspaceScope ?? prior?.workspaceScope ?? null,
|
|
74
|
+
epochId: resetSuppressed ? prior.epochId : owner.epochId, state,
|
|
75
|
+
...(prior?.delivery ? { delivery: advanceTriggerFeedbackDelivery(prior.delivery, snapshot, owner.epochId) } : {}),
|
|
76
|
+
sourceAvailable: true,
|
|
77
|
+
};
|
|
78
|
+
const changed = JSON.stringify(row) !== JSON.stringify(prior);
|
|
79
|
+
if (!changed)
|
|
80
|
+
return { file, changed, row, resetSuppressed };
|
|
81
|
+
if (!prior && file.rows.length >= MAX_TRIGGER_FEEDBACK_ROWS)
|
|
82
|
+
throw new Error('trigger_feedback_capacity');
|
|
83
|
+
const rows = [...file.rows];
|
|
84
|
+
if (index >= 0)
|
|
85
|
+
rows[index] = row;
|
|
86
|
+
else
|
|
87
|
+
rows.push(row);
|
|
88
|
+
rows.sort((left, right) => left.userScope.localeCompare(right.userScope) || left.state.snapshot.runId.localeCompare(right.state.snapshot.runId));
|
|
89
|
+
return { file: { ...file, version: 2, rows }, changed, row, resetSuppressed };
|
|
90
|
+
}
|
|
91
|
+
export function triggerFeedbackRecords(file, userScopes, workspaceScope, epochId) {
|
|
92
|
+
return file.rows.flatMap((row) => {
|
|
93
|
+
if (!userScopes.has(row.userScope) || row.workspaceScope !== workspaceScope || row.epochId !== epochId || row.sourceAvailable === false)
|
|
94
|
+
return [];
|
|
95
|
+
const snapshot = row.state.snapshot;
|
|
96
|
+
const fitness = algo.triggerEffectiveScore(snapshot);
|
|
97
|
+
if (fitness === null || snapshot.evaluatedAt === null || snapshot.learningEligible === false)
|
|
98
|
+
return [];
|
|
99
|
+
const signals = algo.normalizeMemorySignals(snapshot.signals);
|
|
100
|
+
return snapshot.genes.map((geneId) => ({
|
|
101
|
+
version: 2, kind: 'outcome', provenance: 'v2_local', workspaceScope, userScope: row.userScope,
|
|
102
|
+
signalFingerprint: algo.memorySignalFingerprint(signals), signals, geneId,
|
|
103
|
+
status: snapshot.machine?.status === 'success' ? 'success' : 'failed', score: fitness, fitness, at: snapshot.evaluatedAt,
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function parseStoredSnapshot(raw) {
|
|
108
|
+
const row = object(raw);
|
|
109
|
+
const commit = row['commit'] === null ? null : object(row['commit']);
|
|
110
|
+
const machine = row['machine'] === null ? null : object(row['machine']);
|
|
111
|
+
return algo.parseKernelTriggerFeedback({
|
|
112
|
+
schema_version: row['schemaVersion'], run_id: row['runId'], trigger_id: row['triggerId'],
|
|
113
|
+
committed: commit && { run_id: commit['runId'], trigger_id: commit['triggerId'], revision: commit['revision'], operation_id: commit['operationId'], rating: commit['rating'] },
|
|
114
|
+
machine_outcome: machine && { status: machine['status'], score: machine['score'], user_override: machine['override'], override_source: { kind: machine['overrideSource'] } },
|
|
115
|
+
baseline_event_id: row['baselineEventId'], evaluated_at: row['evaluatedAt'], genes_used: row['genes'], signals: row['signals'], workspace: row['workspace'], learning_eligible: row['learningEligible'],
|
|
116
|
+
}, text(row['runId']));
|
|
117
|
+
}
|
|
118
|
+
function object(raw) {
|
|
119
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
120
|
+
throw new Error('trigger_feedback_invalid_store');
|
|
121
|
+
return raw;
|
|
122
|
+
}
|
|
123
|
+
function text(raw) { if (typeof raw !== 'string' || !raw.trim() || raw.length > 256)
|
|
124
|
+
throw new Error('trigger_feedback_invalid_store'); return raw; }
|
|
125
|
+
function scope(raw) { const value = text(raw); if (!/^sha256:[a-f0-9]{64}$/.test(value))
|
|
126
|
+
throw new Error('trigger_feedback_invalid_scope'); return value; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runMcpStdioCommand(argv: string[]): Promise<number>;
|
package/dist/mcpStdio.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export async function runMcpStdioCommand(argv) {
|
|
2
|
+
if (argv.length) {
|
|
3
|
+
process.stderr.write('usage: evolver mcp-stdio\n');
|
|
4
|
+
return 2;
|
|
5
|
+
}
|
|
6
|
+
const server = await import('@evomap/evolver-mcp/stdio');
|
|
7
|
+
await server.stdioLifetime;
|
|
8
|
+
return Number(process.exitCode ?? 0);
|
|
9
|
+
}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PluginRuntime } from './pluginRuntime.js';
|
|
2
|
+
export declare const PLUGIN_USAGE = "Usage: evolver plugin list [--json]\n evolver plugin install [--host <host>] [--scope user|project] [--root <dir>]\n [--profile <dsh-profile>] [--dry-run] [--json]\n\nHosts: claude-code, codex, grok, qoder, antigravity, opencode, dsh,\n cursor, workbuddy, mcp-generic\nDefault scope: user. dsh default profile: dsh-tui.\nWith no host, only a single discovered native host is selected; otherwise choose --host.\nCursor, WorkBuddy and generic MCP return manual_required without writing client config.\nDry-run performs no download, host command or config write and proves no installed state.\nInstallation uses EvoMap/evolver-agent-plugin and does not replace setup-hooks.\nExit codes: 0 verified install/already-installed/list/preview; 2 action required; 1 failure.\n";
|
|
3
|
+
export interface PluginCommandDeps {
|
|
4
|
+
runtime?: PluginRuntime;
|
|
5
|
+
stdout?: (text: string) => void;
|
|
6
|
+
stderr?: (text: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function runPluginCommand(argv: readonly string[], deps?: PluginCommandDeps): Promise<number>;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { PLUGIN_HOSTS, pluginHostNamed } from './pluginHosts.js';
|
|
4
|
+
import { installAgentPlugin } from './pluginInstall.js';
|
|
5
|
+
import { createPluginRuntime, PluginInstallError } from './pluginRuntime.js';
|
|
6
|
+
export const PLUGIN_USAGE = `Usage: evolver plugin list [--json]
|
|
7
|
+
evolver plugin install [--host <host>] [--scope user|project] [--root <dir>]
|
|
8
|
+
[--profile <dsh-profile>] [--dry-run] [--json]
|
|
9
|
+
|
|
10
|
+
Hosts: claude-code, codex, grok, qoder, antigravity, opencode, dsh,
|
|
11
|
+
cursor, workbuddy, mcp-generic
|
|
12
|
+
Default scope: user. dsh default profile: dsh-tui.
|
|
13
|
+
With no host, only a single discovered native host is selected; otherwise choose --host.
|
|
14
|
+
Cursor, WorkBuddy and generic MCP return manual_required without writing client config.
|
|
15
|
+
Dry-run performs no download, host command or config write and proves no installed state.
|
|
16
|
+
Installation uses EvoMap/evolver-agent-plugin and does not replace setup-hooks.
|
|
17
|
+
Exit codes: 0 verified install/already-installed/list/preview; 2 action required; 1 failure.
|
|
18
|
+
`;
|
|
19
|
+
function parsePluginArgs(argv) {
|
|
20
|
+
const flags = { action: 'list', json: false, dryRun: false };
|
|
21
|
+
let index = 0;
|
|
22
|
+
if (argv[0] && !argv[0].startsWith('-')) {
|
|
23
|
+
if (argv[0] !== 'list' && argv[0] !== 'install')
|
|
24
|
+
throw new PluginInstallError('invalid_arguments', `Unknown plugin action. Use evolver plugin --help.`);
|
|
25
|
+
flags.action = argv[0];
|
|
26
|
+
index = 1;
|
|
27
|
+
}
|
|
28
|
+
const seen = new Set();
|
|
29
|
+
for (; index < argv.length; index++) {
|
|
30
|
+
const token = argv[index];
|
|
31
|
+
if (token === '--help' || token === '-h') {
|
|
32
|
+
flags.action = 'help';
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (token === '--json' || token === '--dry-run') {
|
|
36
|
+
if (seen.has(token))
|
|
37
|
+
throw new PluginInstallError('invalid_arguments', 'A plugin option was repeated.');
|
|
38
|
+
seen.add(token);
|
|
39
|
+
if (token === '--json')
|
|
40
|
+
flags.json = true;
|
|
41
|
+
else
|
|
42
|
+
flags.dryRun = true;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const match = /^--(host|scope|root|profile)(?:=(.*))?$/.exec(token);
|
|
46
|
+
if (!match)
|
|
47
|
+
throw new PluginInstallError('invalid_arguments', 'Unknown plugin option. Use evolver plugin --help.');
|
|
48
|
+
const key = match[1];
|
|
49
|
+
if (seen.has(key))
|
|
50
|
+
throw new PluginInstallError('invalid_arguments', `--${key} was repeated.`);
|
|
51
|
+
seen.add(key);
|
|
52
|
+
const value = match[2] ?? argv[++index];
|
|
53
|
+
if (!value || !value.trim() || value.startsWith('-') || value.includes('\0'))
|
|
54
|
+
throw new PluginInstallError('invalid_arguments', `--${key} requires a non-empty value.`);
|
|
55
|
+
flags[key] = value;
|
|
56
|
+
}
|
|
57
|
+
if (flags.action === 'list' && (flags.host || flags.scope || flags.root || flags.profile || flags.dryRun)) {
|
|
58
|
+
throw new PluginInstallError('invalid_arguments', 'plugin list accepts only --json; use plugin install for installation options.');
|
|
59
|
+
}
|
|
60
|
+
return flags;
|
|
61
|
+
}
|
|
62
|
+
function installOptions(flags, runtime) {
|
|
63
|
+
let host = flags.host && pluginHostNamed(flags.host);
|
|
64
|
+
if (flags.host && !host)
|
|
65
|
+
throw new PluginInstallError('invalid_arguments', 'Unknown plugin host. Use evolver plugin list to see supported entries.');
|
|
66
|
+
if (!host) {
|
|
67
|
+
const found = PLUGIN_HOSTS.filter(candidate => candidate.kind !== 'manual' && candidate.command && runtime.available(candidate.command));
|
|
68
|
+
if (found.length !== 1)
|
|
69
|
+
throw new PluginInstallError('selection_required', found.length === 0
|
|
70
|
+
? 'No native plugin host was found on PATH. Choose --host explicitly; plugin list includes manual entries.'
|
|
71
|
+
: `Multiple native hosts were found (${found.map(candidate => candidate.id).join(', ')}). Choose --host; no client configuration was changed.`);
|
|
72
|
+
host = found[0];
|
|
73
|
+
}
|
|
74
|
+
const scope = flags.scope ?? 'user';
|
|
75
|
+
if (scope !== 'user' && scope !== 'project')
|
|
76
|
+
throw new PluginInstallError('invalid_arguments', '--scope must be user or project.');
|
|
77
|
+
if (!host.scopes.includes(scope))
|
|
78
|
+
throw new PluginInstallError('invalid_arguments', `${host.label} does not have a verified ${scope}-scope installer. Supported scopes: ${host.scopes.join(', ')}.`);
|
|
79
|
+
if (flags.profile && host.id !== 'dsh')
|
|
80
|
+
throw new PluginInstallError('invalid_arguments', '--profile is only supported for dsh; no host-specific argument was silently ignored.');
|
|
81
|
+
const profile = flags.profile ?? 'dsh-tui';
|
|
82
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(profile))
|
|
83
|
+
throw new PluginInstallError('invalid_arguments', '--profile must be a simple dsh profile name, not a path or command.');
|
|
84
|
+
let root = resolve(runtime.cwd, flags.root ?? '.');
|
|
85
|
+
if (!flags.dryRun && host.kind !== 'manual') {
|
|
86
|
+
try {
|
|
87
|
+
root = realpathSync(root);
|
|
88
|
+
if (!statSync(root).isDirectory())
|
|
89
|
+
throw new Error('not a directory');
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw new PluginInstallError('invalid_arguments', '--root must identify an existing project/working directory.');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { host, scope: scope, root, profile, dryRun: flags.dryRun };
|
|
96
|
+
}
|
|
97
|
+
export async function runPluginCommand(argv, deps = {}) {
|
|
98
|
+
const stdout = deps.stdout ?? (text => { process.stdout.write(text); });
|
|
99
|
+
const stderr = deps.stderr ?? (text => { process.stderr.write(text); });
|
|
100
|
+
const runtime = deps.runtime ?? createPluginRuntime();
|
|
101
|
+
let json = false;
|
|
102
|
+
try {
|
|
103
|
+
const flags = parsePluginArgs(argv);
|
|
104
|
+
json = flags.json;
|
|
105
|
+
if (flags.action === 'help') {
|
|
106
|
+
stdout(PLUGIN_USAGE);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
if (flags.action === 'list') {
|
|
110
|
+
const hosts = PLUGIN_HOSTS.map(host => ({ id: host.id, label: host.label, mode: host.kind === 'manual' ? 'manual' : 'native', cli: host.command ?? null, cliFound: Boolean(host.command && runtime.available(host.command)), minimumVersion: host.minimumVersion ?? null, scopes: host.scopes, instructions: host.instructions }));
|
|
111
|
+
stdout(json ? `${JSON.stringify({ ok: true, action: 'list', hosts })}\n` : `${hosts.map(host => `${host.id.padEnd(14)} ${host.mode.padEnd(7)} ${host.cliFound ? 'CLI found' : 'CLI not found / not required'}; scopes=${host.scopes.join('|')}`).join('\n')}\nCLI detection is not installation or version verification.\n`);
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
const result = await installAgentPlugin(runtime, installOptions(flags, runtime));
|
|
115
|
+
if (json)
|
|
116
|
+
stdout(`${JSON.stringify(result)}\n`);
|
|
117
|
+
else {
|
|
118
|
+
const lines = [`${result.host}: ${result.status}${result.version ? ` (${result.version})` : ''}`, ...(result.error ? [result.error] : []), ...result.commands.map(step => `${step.name}: ${JSON.stringify([step.command, ...step.args])}`), ...result.instructions];
|
|
119
|
+
if (result.completed.length > 0 && !result.ok)
|
|
120
|
+
lines.push('Rollback (inspect the host before applying):', ...result.rollback);
|
|
121
|
+
(result.ok || result.status === 'manual_required' ? stdout : stderr)(`${lines.join('\n')}\n`);
|
|
122
|
+
}
|
|
123
|
+
return result.ok ? 0 : result.status === 'failed' || result.status === 'conflict' ? 1 : 2;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
const status = error instanceof PluginInstallError ? error.status : 'failed';
|
|
127
|
+
const message = error instanceof PluginInstallError ? error.message : 'Plugin operation failed; no verified installation was reported.';
|
|
128
|
+
const text = json || argv.includes('--json') ? `${JSON.stringify({ ok: false, status, verified: false, error: message })}\n` : `${message}\n`;
|
|
129
|
+
(json || argv.includes('--json') ? stdout : stderr)(text);
|
|
130
|
+
return status === 'failed' || status === 'conflict' ? 1 : 2;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { withOwnedPluginLock } from './pluginLock.js';
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { AGENT_PLUGIN_GIT_URL, AGENT_PLUGIN_NAME, AGENT_PLUGIN_REPOSITORY, AGENT_PLUGIN_RELEASE } from './pluginHosts.js';
|
|
5
|
+
import { agentPluginRepositoryMatches } from './pluginInspection.js';
|
|
6
|
+
import { assertPluginManagedPath, checkedPluginCommand, pluginHome, PluginInstallError, readPluginJson, readPluginText } from './pluginRuntime.js';
|
|
7
|
+
const RECEIPT = '.evolver-plugin-checkout.json';
|
|
8
|
+
function validateBundle(checkout, host) {
|
|
9
|
+
const bundle = join(checkout, 'dist', host.id);
|
|
10
|
+
const root = lstatSync(bundle);
|
|
11
|
+
if (root.isSymbolicLink() || !root.isDirectory())
|
|
12
|
+
throw new PluginInstallError('failed', 'The plugin bundle root is not an ordinary owned directory.');
|
|
13
|
+
const manifest = readPluginJson(join(bundle, host.manifest));
|
|
14
|
+
const expectedName = host.id === 'opencode' ? '@evomap/evolver-opencode' : AGENT_PLUGIN_NAME;
|
|
15
|
+
if (readPluginText(join(bundle, '.evolver-packed'))?.trim() !== host.id || manifest?.['name'] !== expectedName || typeof manifest['version'] !== 'string') {
|
|
16
|
+
throw new PluginInstallError('failed', `The release branch has no valid packed ${host.label} plugin. No host installation was attempted.`);
|
|
17
|
+
}
|
|
18
|
+
const repository = typeof manifest['repository'] === 'string' ? manifest['repository'] : manifest['repository']?.url;
|
|
19
|
+
if (!agentPluginRepositoryMatches(repository))
|
|
20
|
+
throw new PluginInstallError('failed', 'The packed plugin manifest identifies another repository.');
|
|
21
|
+
const entries = host.id === 'opencode' ? ['server.mjs', 'tui.mjs'] : ['bin/hook.mjs', `hosts/${host.id}/profile.js`];
|
|
22
|
+
if (entries.some(entry => readPluginText(join(bundle, entry)) === undefined))
|
|
23
|
+
throw new PluginInstallError('failed', 'The packed plugin is missing an entry module.');
|
|
24
|
+
const queue = [bundle];
|
|
25
|
+
let count = 0;
|
|
26
|
+
while (queue.length > 0) {
|
|
27
|
+
const directory = queue.pop();
|
|
28
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
29
|
+
if (++count > 10_000 || entry.isSymbolicLink())
|
|
30
|
+
throw new PluginInstallError('failed', 'The plugin bundle contains an unsafe link or exceeds the file limit.');
|
|
31
|
+
if (entry.isDirectory())
|
|
32
|
+
queue.push(join(directory, entry.name));
|
|
33
|
+
else if (!entry.isFile())
|
|
34
|
+
throw new PluginInstallError('failed', 'The plugin bundle contains a non-regular file.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export async function ensureAgentPluginBundle(runtime, host) {
|
|
39
|
+
if (host.kind !== 'bundle')
|
|
40
|
+
throw new PluginInstallError('unsupported_capability', 'This host uses its native source installer, not the packed-checkout download path.');
|
|
41
|
+
if (!runtime.available('git'))
|
|
42
|
+
throw new PluginInstallError('host_missing', 'Git is required to fetch the packed plugin release.');
|
|
43
|
+
const remote = await checkedPluginCommand(runtime, 'git', ['ls-remote', '--heads', AGENT_PLUGIN_GIT_URL, AGENT_PLUGIN_RELEASE], runtime.cwd, 30_000);
|
|
44
|
+
const matches = remote.stdout.trim().split('\n').map(line => /^([a-f0-9]{40})\s+refs\/heads\/release$/.exec(line.trim())).filter(Boolean);
|
|
45
|
+
if (matches.length !== 1)
|
|
46
|
+
throw new PluginInstallError('failed', 'The plugin release branch did not resolve to one commit.');
|
|
47
|
+
const commit = matches[0][1];
|
|
48
|
+
const base = join(realpathSync(pluginHome(runtime)), '.evolver', 'plugins', 'evolver-agent-plugin');
|
|
49
|
+
assertPluginManagedPath(base);
|
|
50
|
+
mkdirSync(base, { recursive: true, mode: 0o700 });
|
|
51
|
+
const lockPath = join(base, `${host.id}.lock`);
|
|
52
|
+
return withOwnedPluginLock(lockPath, async () => {
|
|
53
|
+
const checkout = join(base, commit, host.id);
|
|
54
|
+
let stage;
|
|
55
|
+
let stageIdentity;
|
|
56
|
+
try {
|
|
57
|
+
assertPluginManagedPath(checkout);
|
|
58
|
+
if (existsSync(checkout)) {
|
|
59
|
+
const receipt = readPluginJson(join(checkout, RECEIPT));
|
|
60
|
+
if (receipt?.['repository'] !== AGENT_PLUGIN_REPOSITORY || receipt['commit'] !== commit || receipt['host'] !== host.id) {
|
|
61
|
+
throw new PluginInstallError('conflict', 'The plugin cache directory is not an owned, matching release checkout.');
|
|
62
|
+
}
|
|
63
|
+
validateBundle(checkout, host);
|
|
64
|
+
return join(checkout, 'dist');
|
|
65
|
+
}
|
|
66
|
+
stage = mkdtempSync(join(base, `.${host.id}-`));
|
|
67
|
+
const identity = lstatSync(stage);
|
|
68
|
+
stageIdentity = { dev: identity.dev, ino: identity.ino };
|
|
69
|
+
const source = join(stage, 'checkout');
|
|
70
|
+
const noHooks = join(stage, 'no-hooks');
|
|
71
|
+
mkdirSync(noHooks, { mode: 0o700 });
|
|
72
|
+
await checkedPluginCommand(runtime, 'git', ['-c', `core.hooksPath=${noHooks}`, 'clone', '--depth', '1', '--branch', AGENT_PLUGIN_RELEASE, '--filter=blob:none', '--sparse', AGENT_PLUGIN_GIT_URL, source], runtime.cwd, 120_000);
|
|
73
|
+
await checkedPluginCommand(runtime, 'git', ['-C', source, '-c', `core.hooksPath=${noHooks}`, 'sparse-checkout', 'set', `dist/${host.id}`], runtime.cwd, 120_000);
|
|
74
|
+
const head = await checkedPluginCommand(runtime, 'git', ['-C', source, 'rev-parse', 'HEAD']);
|
|
75
|
+
if (head.stdout.trim() !== commit)
|
|
76
|
+
throw new PluginInstallError('failed', 'The plugin release changed while downloading. Retry to use a consistent release.');
|
|
77
|
+
validateBundle(source, host);
|
|
78
|
+
writeFileSync(join(source, RECEIPT), `${JSON.stringify({ repository: AGENT_PLUGIN_REPOSITORY, commit, host: host.id })}\n`, { flag: 'wx', mode: 0o600 });
|
|
79
|
+
assertPluginManagedPath(checkout);
|
|
80
|
+
if (existsSync(checkout))
|
|
81
|
+
throw new PluginInstallError('conflict', 'The plugin cache destination appeared during the download; it was not overwritten.');
|
|
82
|
+
mkdirSync(join(base, commit), { recursive: true, mode: 0o700 });
|
|
83
|
+
renameSync(source, checkout);
|
|
84
|
+
return join(checkout, 'dist');
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
if (stage && stageIdentity && existsSync(stage)) {
|
|
88
|
+
const current = lstatSync(stage);
|
|
89
|
+
if (!current.isSymbolicLink() && current.dev === stageIdentity.dev && current.ino === stageIdentity.ino)
|
|
90
|
+
rmSync(stage, { recursive: true, force: true });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|