@evomap/evolver-cli 2.0.46 → 2.0.48
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 +3 -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/feedbackOutbox.js +11 -1
- 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/localPublishBinding.js +5 -1
- 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 +140 -0
- package/dist/pluginBundle.d.ts +4 -0
- package/dist/pluginBundle.js +93 -0
- package/dist/pluginDshStore.d.ts +7 -0
- package/dist/pluginDshStore.js +84 -0
- package/dist/pluginHosts.d.ts +52 -0
- package/dist/pluginHosts.js +146 -0
- package/dist/pluginInspection.d.ts +24 -0
- package/dist/pluginInspection.js +248 -0
- package/dist/pluginInstall.d.ts +20 -0
- package/dist/pluginInstall.js +103 -0
- package/dist/pluginLock.d.ts +4 -0
- package/dist/pluginLock.js +52 -0
- package/dist/pluginRuntime.d.ts +32 -0
- package/dist/pluginRuntime.js +193 -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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type UserInfo } from 'node:os';
|
|
2
2
|
import { algo, util } from '@evomap/evolver-core';
|
|
3
|
+
import { type TriggerFeedbackDeliveryState, type TriggerFeedbackDeliveryStatus } from './triggerFeedbackSyncState.js';
|
|
3
4
|
export interface LocalMemoryGraphOptions {
|
|
4
5
|
dir: string;
|
|
5
6
|
userId: string;
|
|
@@ -83,6 +84,43 @@ export declare class LocalMemoryGraph implements algo.MemoryGraphProvider {
|
|
|
83
84
|
private rotationCleanupFailed;
|
|
84
85
|
constructor(options: LocalMemoryGraphOptions);
|
|
85
86
|
query(input: algo.MemoryGraphQueryInput): algo.MemoryGraphAdvice;
|
|
87
|
+
/** @internal Only the bound kernel reader supplies snapshots; CLI/MCP callers provide a run id, never a score. */
|
|
88
|
+
applyKernelTriggerFeedback(snapshot: algo.TriggerFeedbackSnapshot, destinationId?: string): {
|
|
89
|
+
committed: algo.TriggerRatingCommit | null;
|
|
90
|
+
changed: boolean;
|
|
91
|
+
resetSuppressed: boolean;
|
|
92
|
+
};
|
|
93
|
+
applyKernelTriggerFeedbackBatch(snapshots: readonly algo.TriggerFeedbackSnapshot[], destinationId?: string): Array<{
|
|
94
|
+
committed: algo.TriggerRatingCommit | null;
|
|
95
|
+
changed: boolean;
|
|
96
|
+
resetSuppressed: boolean;
|
|
97
|
+
}>;
|
|
98
|
+
readTriggerFeedback(runId: string): algo.TriggerFeedbackState | null;
|
|
99
|
+
triggerFeedbackSourceAvailable(runId: string): boolean;
|
|
100
|
+
readTriggerFeedbackDelivery(runId: string): TriggerFeedbackDeliveryState | null;
|
|
101
|
+
readTriggerFeedbackDeliveries(after?: string | null, limit?: number): Array<{
|
|
102
|
+
snapshot: algo.TriggerFeedbackSnapshot;
|
|
103
|
+
delivery: TriggerFeedbackDeliveryState;
|
|
104
|
+
}>;
|
|
105
|
+
markTriggerFeedbackSourceUnavailable(runId?: string): void;
|
|
106
|
+
authorizeTriggerFeedbackDelivery(runId: string, destinationId: string): TriggerFeedbackDeliveryState;
|
|
107
|
+
claimTriggerFeedbackDelivery(runId: string, destinationId: string, id: string): {
|
|
108
|
+
state: TriggerFeedbackDeliveryState;
|
|
109
|
+
claimed: boolean;
|
|
110
|
+
reconcile: boolean;
|
|
111
|
+
};
|
|
112
|
+
markTriggerFeedbackDispatched(runId: string, id: string): void;
|
|
113
|
+
settleTriggerFeedbackDelivery(runId: string, id: string, result: {
|
|
114
|
+
status: TriggerFeedbackDeliveryStatus;
|
|
115
|
+
revision?: number;
|
|
116
|
+
operationId?: string | null;
|
|
117
|
+
reason?: string;
|
|
118
|
+
}): TriggerFeedbackDeliveryState;
|
|
119
|
+
readTriggerFeedbackRecoveryCursor(kind?: 'native' | 'delivery'): string | null;
|
|
120
|
+
saveTriggerFeedbackRecoveryCursor(after: string | null, kind?: 'native' | 'delivery'): void;
|
|
121
|
+
private changeTriggerFeedbackDelivery;
|
|
122
|
+
private changeTriggerFeedbackFile;
|
|
123
|
+
private readTriggerFeedbackUnlocked;
|
|
86
124
|
recordOutcome(input: algo.MemoryGraphRecordInput): void;
|
|
87
125
|
importV1Outcome(workspace: string, raw: unknown, source?: string): boolean;
|
|
88
126
|
/** Builds a stable import forecast without creating or locking the target graph. */
|
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);
|
|
@@ -65,7 +65,11 @@ async function authorizeSnapshot(assets, expectedHubMode, proxy) {
|
|
|
65
65
|
catch (error) {
|
|
66
66
|
throw new LocalPublishBindingError(safeFailureReason(error, 'publish_binding_authorization_unavailable', 'binding_authorization'));
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
// binding_exempt 表示本机 ledger 按 parent 规则放行(parent Gene 已随本节点发布),
|
|
69
|
+
// 不是宿主执行回执;它与 binding_verified 一样只是本机授权结论。
|
|
70
|
+
if (response['ok'] !== true
|
|
71
|
+
|| (response['binding_verified'] !== true && response['binding_exempt'] !== true)
|
|
72
|
+
|| response['bundle_digest'] !== digest
|
|
69
73
|
|| requestDigest !== digest || hub.publishBundleDigest(requestAssets) !== requestDigest
|
|
70
74
|
|| hub.publishBundleDigest(assets) !== digest) {
|
|
71
75
|
throw new LocalPublishBindingError('publish_binding_authorization_invalid');
|
|
@@ -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>] [--trust] [--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.\n--trust says you trust the plugin's hooks; only hosts that require it (grok) accept it.\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\n(including trust_required and profile_store_mismatch); 1 conflict or 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,140 @@
|
|
|
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>] [--trust] [--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
|
+
--trust says you trust the plugin's hooks; only hosts that require it (grok) accept it.
|
|
14
|
+
With no host, only a single discovered native host is selected; otherwise choose --host.
|
|
15
|
+
Cursor, WorkBuddy and generic MCP return manual_required without writing client config.
|
|
16
|
+
Dry-run performs no download, host command or config write and proves no installed state.
|
|
17
|
+
Installation uses EvoMap/evolver-agent-plugin and does not replace setup-hooks.
|
|
18
|
+
Exit codes: 0 verified install/already-installed/list/preview; 2 action required
|
|
19
|
+
(including trust_required and profile_store_mismatch); 1 conflict or failure.
|
|
20
|
+
`;
|
|
21
|
+
function parsePluginArgs(argv) {
|
|
22
|
+
const flags = { action: 'list', json: false, dryRun: false, trust: false };
|
|
23
|
+
let index = 0;
|
|
24
|
+
if (argv[0] && !argv[0].startsWith('-')) {
|
|
25
|
+
if (argv[0] !== 'list' && argv[0] !== 'install')
|
|
26
|
+
throw new PluginInstallError('invalid_arguments', `Unknown plugin action. Use evolver plugin --help.`);
|
|
27
|
+
flags.action = argv[0];
|
|
28
|
+
index = 1;
|
|
29
|
+
}
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
for (; index < argv.length; index++) {
|
|
32
|
+
const token = argv[index];
|
|
33
|
+
if (token === '--help' || token === '-h') {
|
|
34
|
+
flags.action = 'help';
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (token === '--json' || token === '--dry-run' || token === '--trust') {
|
|
38
|
+
if (seen.has(token))
|
|
39
|
+
throw new PluginInstallError('invalid_arguments', 'A plugin option was repeated.');
|
|
40
|
+
seen.add(token);
|
|
41
|
+
if (token === '--json')
|
|
42
|
+
flags.json = true;
|
|
43
|
+
else if (token === '--trust')
|
|
44
|
+
flags.trust = true;
|
|
45
|
+
else
|
|
46
|
+
flags.dryRun = true;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const match = /^--(host|scope|root|profile)(?:=(.*))?$/.exec(token);
|
|
50
|
+
if (!match)
|
|
51
|
+
throw new PluginInstallError('invalid_arguments', 'Unknown plugin option. Use evolver plugin --help.');
|
|
52
|
+
const key = match[1];
|
|
53
|
+
if (seen.has(key))
|
|
54
|
+
throw new PluginInstallError('invalid_arguments', `--${key} was repeated.`);
|
|
55
|
+
seen.add(key);
|
|
56
|
+
const value = match[2] ?? argv[++index];
|
|
57
|
+
if (!value || !value.trim() || value.startsWith('-') || value.includes('\0'))
|
|
58
|
+
throw new PluginInstallError('invalid_arguments', `--${key} requires a non-empty value.`);
|
|
59
|
+
flags[key] = value;
|
|
60
|
+
}
|
|
61
|
+
if (flags.action === 'list' && (flags.host || flags.scope || flags.root || flags.profile || flags.dryRun || flags.trust)) {
|
|
62
|
+
throw new PluginInstallError('invalid_arguments', 'plugin list accepts only --json; use plugin install for installation options.');
|
|
63
|
+
}
|
|
64
|
+
return flags;
|
|
65
|
+
}
|
|
66
|
+
function installOptions(flags, runtime) {
|
|
67
|
+
let host = flags.host && pluginHostNamed(flags.host);
|
|
68
|
+
if (flags.host && !host)
|
|
69
|
+
throw new PluginInstallError('invalid_arguments', 'Unknown plugin host. Use evolver plugin list to see supported entries.');
|
|
70
|
+
if (!host) {
|
|
71
|
+
const found = PLUGIN_HOSTS.filter(candidate => candidate.kind !== 'manual' && candidate.command && runtime.available(candidate.command));
|
|
72
|
+
if (found.length !== 1)
|
|
73
|
+
throw new PluginInstallError('selection_required', found.length === 0
|
|
74
|
+
? 'No native plugin host was found on PATH. Choose --host explicitly; plugin list includes manual entries.'
|
|
75
|
+
: `Multiple native hosts were found (${found.map(candidate => candidate.id).join(', ')}). Choose --host; no client configuration was changed.`);
|
|
76
|
+
host = found[0];
|
|
77
|
+
}
|
|
78
|
+
const scope = flags.scope ?? 'user';
|
|
79
|
+
if (scope !== 'user' && scope !== 'project')
|
|
80
|
+
throw new PluginInstallError('invalid_arguments', '--scope must be user or project.');
|
|
81
|
+
if (!host.scopes.includes(scope))
|
|
82
|
+
throw new PluginInstallError('invalid_arguments', `${host.label} does not have a verified ${scope}-scope installer. Supported scopes: ${host.scopes.join(', ')}.`);
|
|
83
|
+
if (flags.trust && !host.requiresTrust) {
|
|
84
|
+
const trustHosts = PLUGIN_HOSTS.filter(candidate => candidate.requiresTrust).map(candidate => candidate.id).join(', ');
|
|
85
|
+
throw new PluginInstallError('invalid_arguments', `--trust is only accepted for hosts whose installer requires plugin trust (${trustHosts}); ${host.label} does not, and no host-specific argument is silently ignored.`);
|
|
86
|
+
}
|
|
87
|
+
if (flags.profile && host.id !== 'dsh')
|
|
88
|
+
throw new PluginInstallError('invalid_arguments', '--profile is only supported for dsh; no host-specific argument was silently ignored.');
|
|
89
|
+
const profile = flags.profile ?? 'dsh-tui';
|
|
90
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(profile))
|
|
91
|
+
throw new PluginInstallError('invalid_arguments', '--profile must be a simple dsh profile name, not a path or command.');
|
|
92
|
+
let root = resolve(runtime.cwd, flags.root ?? '.');
|
|
93
|
+
if (!flags.dryRun && host.kind !== 'manual') {
|
|
94
|
+
try {
|
|
95
|
+
root = realpathSync(root);
|
|
96
|
+
if (!statSync(root).isDirectory())
|
|
97
|
+
throw new Error('not a directory');
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
throw new PluginInstallError('invalid_arguments', '--root must identify an existing project/working directory.');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { host, scope: scope, root, profile, dryRun: flags.dryRun, trust: flags.trust };
|
|
104
|
+
}
|
|
105
|
+
export async function runPluginCommand(argv, deps = {}) {
|
|
106
|
+
const stdout = deps.stdout ?? (text => { process.stdout.write(text); });
|
|
107
|
+
const stderr = deps.stderr ?? (text => { process.stderr.write(text); });
|
|
108
|
+
const runtime = deps.runtime ?? createPluginRuntime();
|
|
109
|
+
let json = false;
|
|
110
|
+
try {
|
|
111
|
+
const flags = parsePluginArgs(argv);
|
|
112
|
+
json = flags.json;
|
|
113
|
+
if (flags.action === 'help') {
|
|
114
|
+
stdout(PLUGIN_USAGE);
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
if (flags.action === 'list') {
|
|
118
|
+
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, requiresTrust: Boolean(host.requiresTrust), scopes: host.scopes, instructions: host.instructions }));
|
|
119
|
+
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`);
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
const result = await installAgentPlugin(runtime, installOptions(flags, runtime));
|
|
123
|
+
if (json)
|
|
124
|
+
stdout(`${JSON.stringify(result)}\n`);
|
|
125
|
+
else {
|
|
126
|
+
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];
|
|
127
|
+
if (result.completed.length > 0 && !result.ok)
|
|
128
|
+
lines.push('Rollback (inspect the host before applying):', ...result.rollback);
|
|
129
|
+
(result.ok || result.status === 'manual_required' ? stdout : stderr)(`${lines.join('\n')}\n`);
|
|
130
|
+
}
|
|
131
|
+
return result.ok ? 0 : result.status === 'failed' || result.status === 'conflict' ? 1 : 2;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
const status = error instanceof PluginInstallError ? error.status : 'failed';
|
|
135
|
+
const message = error instanceof PluginInstallError ? error.message : 'Plugin operation failed; no verified installation was reported.';
|
|
136
|
+
const text = json || argv.includes('--json') ? `${JSON.stringify({ ok: false, status, verified: false, error: message })}\n` : `${message}\n`;
|
|
137
|
+
(json || argv.includes('--json') ? stdout : stderr)(text);
|
|
138
|
+
return status === 'failed' || status === 'conflict' ? 1 : 2;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type PluginHost } from './pluginHosts.js';
|
|
2
|
+
import { type PluginRuntime } from './pluginRuntime.js';
|
|
3
|
+
export declare function validatePackedBundle(bundle: string, host: PluginHost): void;
|
|
4
|
+
export declare function ensureAgentPluginBundle(runtime: PluginRuntime, host: PluginHost): Promise<string>;
|