@evomap/evolver-cli 2.0.0-beta.5 → 2.0.0-beta.7
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/autoDistillLlm.d.ts +6 -0
- package/dist/autoDistillLlm.js +40 -6
- package/dist/autoexec.d.ts +2 -10
- package/dist/autoexec.js +17 -25
- package/dist/autoexecConfig.d.ts +10 -0
- package/dist/autoexecConfig.js +68 -0
- package/dist/cliContracts.js +22 -1
- package/dist/dashboard.d.ts +11 -1
- package/dist/dashboard.js +173 -12
- package/dist/dispatch.js +4 -0
- package/dist/distillPrimitives.d.ts +5 -1
- package/dist/distillPrimitives.js +1 -1
- package/dist/doctor.js +16 -0
- package/dist/index.js +27 -6
- package/dist/issueReport.d.ts +7 -0
- package/dist/issueReport.js +291 -0
- package/dist/materialSnapshot.d.ts +24 -0
- package/dist/materialSnapshot.js +234 -12
- package/dist/recipe.js +7 -1
- package/dist/reuse.d.ts +5 -3
- package/dist/reuse.js +50 -3
- package/dist/setupHooks.d.ts +5 -0
- package/dist/setupHooks.js +230 -14
- package/dist/workflow.d.ts +39 -0
- package/dist/workflow.js +386 -0
- package/dist/workflowRuntime.d.ts +66 -0
- package/dist/workflowRuntime.js +631 -0
- package/package.json +7 -7
package/dist/materialSnapshot.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { hub, schema } from '@evomap/evolver-core';
|
|
3
|
+
import { summarizeSessionEvidence, } from '@evomap/evolver-runtime-adapters';
|
|
3
4
|
import { parseRuntimeSessionSources } from './runtimeSessionSource.js';
|
|
4
5
|
export const MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA = 'evolver.material.runtime_session_snapshot.v1';
|
|
5
6
|
const DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS = 24 * 1024;
|
|
7
|
+
const SNAPSHOT_AGENT_MAX_CHARS = 64;
|
|
8
|
+
const SNAPSHOT_IDENTITY_MAX_CHARS = 256;
|
|
9
|
+
const SNAPSHOT_SOURCE_MAX_COUNT = 32;
|
|
10
|
+
const SNAPSHOT_TURN_MAX_COUNT = 256;
|
|
6
11
|
function isRecord(value) {
|
|
7
12
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
8
13
|
}
|
|
@@ -20,19 +25,169 @@ function snapshotTurnText(turn) {
|
|
|
20
25
|
function fitsInline(snapshot) {
|
|
21
26
|
return Buffer.byteLength(JSON.stringify(snapshot), 'utf8') <= schema.MATERIAL_PAYLOAD_INLINE_MAX_BYTES;
|
|
22
27
|
}
|
|
28
|
+
function snapshotIdentity(value, maxChars) {
|
|
29
|
+
return hub.redactString(value).replace(/\s+/g, ' ').trim().slice(0, maxChars);
|
|
30
|
+
}
|
|
31
|
+
function appendEvidenceAggregate(aggregate, summary) {
|
|
32
|
+
const coverageCounts = aggregate
|
|
33
|
+
? { ...aggregate.coverageCounts }
|
|
34
|
+
: { complete: 0, partial: 0, empty: 0 };
|
|
35
|
+
coverageCounts[summary.coverage] += 1;
|
|
36
|
+
const counts = {};
|
|
37
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
38
|
+
counts[key] = (aggregate?.counts[key] ?? 0) + summary.counts[key];
|
|
39
|
+
}
|
|
40
|
+
const gapCodes = [];
|
|
41
|
+
if (coverageCounts.empty > 0)
|
|
42
|
+
gapCodes.push('empty_session');
|
|
43
|
+
if (counts.missingToolResults > 0)
|
|
44
|
+
gapCodes.push('missing_tool_result');
|
|
45
|
+
if (counts.unmatchedToolResults > 0)
|
|
46
|
+
gapCodes.push('unmatched_tool_result');
|
|
47
|
+
return {
|
|
48
|
+
sourceCount: (aggregate?.sourceCount ?? 0) + 1,
|
|
49
|
+
coverageCounts,
|
|
50
|
+
counts,
|
|
51
|
+
gapCodes,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const EVIDENCE_COUNT_KEYS = [
|
|
55
|
+
'nonMetaTurns',
|
|
56
|
+
'toolCalls',
|
|
57
|
+
'toolResults',
|
|
58
|
+
'matchedToolResults',
|
|
59
|
+
'missingToolResults',
|
|
60
|
+
'unmatchedToolResults',
|
|
61
|
+
'failedToolResults',
|
|
62
|
+
];
|
|
63
|
+
const EVIDENCE_GAP_CODES = new Set([
|
|
64
|
+
'empty_session',
|
|
65
|
+
'missing_tool_result',
|
|
66
|
+
'unmatched_tool_result',
|
|
67
|
+
]);
|
|
68
|
+
function evidenceSummaryFromSnapshot(value) {
|
|
69
|
+
if (!isRecord(value) || !isRecord(value['counts']) || !Array.isArray(value['gapCodes']))
|
|
70
|
+
return null;
|
|
71
|
+
const coverage = value['coverage'];
|
|
72
|
+
if (coverage !== 'complete' && coverage !== 'partial' && coverage !== 'empty')
|
|
73
|
+
return null;
|
|
74
|
+
const counts = {};
|
|
75
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
76
|
+
const count = value['counts'][key];
|
|
77
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
78
|
+
return null;
|
|
79
|
+
counts[key] = count;
|
|
80
|
+
}
|
|
81
|
+
const gapCodes = value['gapCodes'];
|
|
82
|
+
if (!gapCodes.every((gap) => (typeof gap === 'string' && EVIDENCE_GAP_CODES.has(gap))))
|
|
83
|
+
return null;
|
|
84
|
+
if (new Set(gapCodes).size !== gapCodes.length
|
|
85
|
+
|| counts.toolCalls + counts.toolResults > counts.nonMetaTurns
|
|
86
|
+
|| counts.matchedToolResults > counts.toolCalls
|
|
87
|
+
|| counts.matchedToolResults > counts.toolResults
|
|
88
|
+
|| counts.missingToolResults !== counts.toolCalls - counts.matchedToolResults
|
|
89
|
+
|| counts.unmatchedToolResults !== counts.toolResults - counts.matchedToolResults
|
|
90
|
+
|| counts.failedToolResults > counts.toolResults)
|
|
91
|
+
return null;
|
|
92
|
+
const expectedGaps = [];
|
|
93
|
+
if (counts.nonMetaTurns === 0)
|
|
94
|
+
expectedGaps.push('empty_session');
|
|
95
|
+
else {
|
|
96
|
+
if (counts.missingToolResults > 0)
|
|
97
|
+
expectedGaps.push('missing_tool_result');
|
|
98
|
+
if (counts.unmatchedToolResults > 0)
|
|
99
|
+
expectedGaps.push('unmatched_tool_result');
|
|
100
|
+
}
|
|
101
|
+
const expectedCoverage = counts.nonMetaTurns === 0
|
|
102
|
+
? 'empty'
|
|
103
|
+
: expectedGaps.length > 0 ? 'partial' : 'complete';
|
|
104
|
+
if (coverage !== expectedCoverage
|
|
105
|
+
|| gapCodes.length !== expectedGaps.length
|
|
106
|
+
|| gapCodes.some((gap, index) => gap !== expectedGaps[index]))
|
|
107
|
+
return null;
|
|
108
|
+
return { coverage, counts, gapCodes: [...gapCodes] };
|
|
109
|
+
}
|
|
110
|
+
function evidenceAggregateFromSnapshot(value) {
|
|
111
|
+
if (!isRecord(value)
|
|
112
|
+
|| !Number.isSafeInteger(value['sourceCount'])
|
|
113
|
+
|| value['sourceCount'] <= 0
|
|
114
|
+
|| !isRecord(value['coverageCounts'])
|
|
115
|
+
|| !isRecord(value['counts'])
|
|
116
|
+
|| !Array.isArray(value['gapCodes']))
|
|
117
|
+
return null;
|
|
118
|
+
const sourceCount = value['sourceCount'];
|
|
119
|
+
const coverageCounts = {};
|
|
120
|
+
for (const coverage of ['complete', 'partial', 'empty']) {
|
|
121
|
+
const count = value['coverageCounts'][coverage];
|
|
122
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
123
|
+
return null;
|
|
124
|
+
coverageCounts[coverage] = count;
|
|
125
|
+
}
|
|
126
|
+
if (coverageCounts.complete + coverageCounts.partial + coverageCounts.empty !== sourceCount)
|
|
127
|
+
return null;
|
|
128
|
+
const counts = {};
|
|
129
|
+
for (const key of EVIDENCE_COUNT_KEYS) {
|
|
130
|
+
const count = value['counts'][key];
|
|
131
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
132
|
+
return null;
|
|
133
|
+
counts[key] = count;
|
|
134
|
+
}
|
|
135
|
+
const gapCodes = value['gapCodes'];
|
|
136
|
+
if (!gapCodes.every((gap) => (typeof gap === 'string' && EVIDENCE_GAP_CODES.has(gap))) || new Set(gapCodes).size !== gapCodes.length
|
|
137
|
+
|| counts.toolCalls + counts.toolResults > counts.nonMetaTurns
|
|
138
|
+
|| counts.matchedToolResults > counts.toolCalls
|
|
139
|
+
|| counts.matchedToolResults > counts.toolResults
|
|
140
|
+
|| counts.missingToolResults !== counts.toolCalls - counts.matchedToolResults
|
|
141
|
+
|| counts.unmatchedToolResults !== counts.toolResults - counts.matchedToolResults
|
|
142
|
+
|| counts.failedToolResults > counts.toolResults)
|
|
143
|
+
return null;
|
|
144
|
+
const nonEmptySourceCount = coverageCounts.complete + coverageCounts.partial;
|
|
145
|
+
const structuralGapCount = counts.missingToolResults + counts.unmatchedToolResults;
|
|
146
|
+
if (counts.nonMetaTurns < nonEmptySourceCount
|
|
147
|
+
|| (coverageCounts.empty === sourceCount && counts.nonMetaTurns !== 0)
|
|
148
|
+
|| (coverageCounts.partial > 0) !== (structuralGapCount > 0)
|
|
149
|
+
|| structuralGapCount < coverageCounts.partial)
|
|
150
|
+
return null;
|
|
151
|
+
const expectedGaps = [];
|
|
152
|
+
if (coverageCounts.empty > 0)
|
|
153
|
+
expectedGaps.push('empty_session');
|
|
154
|
+
if (counts.missingToolResults > 0)
|
|
155
|
+
expectedGaps.push('missing_tool_result');
|
|
156
|
+
if (counts.unmatchedToolResults > 0)
|
|
157
|
+
expectedGaps.push('unmatched_tool_result');
|
|
158
|
+
if (gapCodes.length !== expectedGaps.length
|
|
159
|
+
|| gapCodes.some((gap, index) => gap !== expectedGaps[index]))
|
|
160
|
+
return null;
|
|
161
|
+
return { sourceCount, coverageCounts, counts, gapCodes: [...gapCodes] };
|
|
162
|
+
}
|
|
23
163
|
export function buildRuntimeSessionMaterialSnapshot(sources, maxChars = DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS) {
|
|
24
|
-
const safeMaxChars =
|
|
164
|
+
const safeMaxChars = Number.isFinite(maxChars)
|
|
165
|
+
? Math.max(0, Math.min(Math.trunc(maxChars), DEFAULT_MATERIAL_SNAPSHOT_MAX_CHARS))
|
|
166
|
+
: 0;
|
|
25
167
|
let remaining = safeMaxChars;
|
|
26
168
|
let truncated = false;
|
|
169
|
+
let retainedTurnCount = 0;
|
|
170
|
+
let omittedEvidenceAggregate;
|
|
27
171
|
const snapshotSources = [];
|
|
28
172
|
for (const source of sources) {
|
|
173
|
+
const evidenceSummary = summarizeSessionEvidence({ turns: source.turns });
|
|
174
|
+
if (snapshotSources.length >= SNAPSHOT_SOURCE_MAX_COUNT) {
|
|
175
|
+
omittedEvidenceAggregate = appendEvidenceAggregate(omittedEvidenceAggregate, evidenceSummary);
|
|
176
|
+
truncated = true;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
29
179
|
const turns = [];
|
|
30
180
|
for (const turn of source.turns) {
|
|
181
|
+
if (retainedTurnCount >= SNAPSHOT_TURN_MAX_COUNT) {
|
|
182
|
+
truncated = true;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
31
185
|
const rawText = snapshotTurnText(turn);
|
|
32
186
|
const trimmed = trimText(rawText, remaining);
|
|
33
187
|
remaining -= trimmed.used;
|
|
34
188
|
truncated = truncated || trimmed.truncated;
|
|
35
189
|
if (trimmed.text.length > 0) {
|
|
190
|
+
retainedTurnCount += 1;
|
|
36
191
|
turns.push({
|
|
37
192
|
role: turn.role,
|
|
38
193
|
text: trimmed.text,
|
|
@@ -46,29 +201,41 @@ export function buildRuntimeSessionMaterialSnapshot(sources, maxChars = DEFAULT_
|
|
|
46
201
|
break;
|
|
47
202
|
}
|
|
48
203
|
}
|
|
204
|
+
const safeSessionId = source.sessionId
|
|
205
|
+
? snapshotIdentity(source.sessionId, SNAPSHOT_IDENTITY_MAX_CHARS)
|
|
206
|
+
: '';
|
|
49
207
|
snapshotSources.push({
|
|
50
|
-
agent: source.agent,
|
|
51
|
-
label: source.label,
|
|
52
|
-
...(
|
|
208
|
+
agent: snapshotIdentity(source.agent, SNAPSHOT_AGENT_MAX_CHARS) || 'unknown',
|
|
209
|
+
label: snapshotIdentity(source.label, SNAPSHOT_IDENTITY_MAX_CHARS) || 'unknown',
|
|
210
|
+
...(safeSessionId ? { sessionId: safeSessionId } : {}),
|
|
211
|
+
evidenceSummary,
|
|
53
212
|
turns,
|
|
54
213
|
});
|
|
55
|
-
if (remaining <= 0)
|
|
56
|
-
break;
|
|
57
214
|
}
|
|
58
215
|
const snapshot = {
|
|
59
216
|
schema: MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA,
|
|
60
217
|
sourceKind: 'runtime_session',
|
|
61
218
|
kind: 'session_log',
|
|
62
219
|
sources: snapshotSources,
|
|
63
|
-
|
|
220
|
+
sourceCount: sources.length,
|
|
221
|
+
omittedSourceCount: omittedEvidenceAggregate?.sourceCount ?? 0,
|
|
222
|
+
...(omittedEvidenceAggregate ? { omittedEvidenceAggregate } : {}),
|
|
223
|
+
truncated: truncated || omittedEvidenceAggregate !== undefined,
|
|
64
224
|
maxChars: safeMaxChars,
|
|
65
225
|
};
|
|
226
|
+
// Source and turn caps make this loop constant-bounded even for very large Cursor databases.
|
|
66
227
|
while (!fitsInline(snapshot) && snapshot.sources.length > 0) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
228
|
+
let sourceWithTurns = snapshot.sources.length - 1;
|
|
229
|
+
while (sourceWithTurns >= 0 && snapshot.sources[sourceWithTurns]?.turns.length === 0) {
|
|
230
|
+
sourceWithTurns -= 1;
|
|
231
|
+
}
|
|
232
|
+
if (sourceWithTurns >= 0)
|
|
233
|
+
snapshot.sources[sourceWithTurns].turns.pop();
|
|
234
|
+
else {
|
|
235
|
+
const omitted = snapshot.sources.pop();
|
|
236
|
+
snapshot.omittedEvidenceAggregate = appendEvidenceAggregate(snapshot.omittedEvidenceAggregate, omitted.evidenceSummary);
|
|
237
|
+
snapshot.omittedSourceCount += 1;
|
|
238
|
+
}
|
|
72
239
|
snapshot.truncated = true;
|
|
73
240
|
}
|
|
74
241
|
return snapshot;
|
|
@@ -122,6 +289,61 @@ export function runtimeSessionSourcesFromMaterialPayload(payload) {
|
|
|
122
289
|
.map(sourceFromSnapshot)
|
|
123
290
|
.filter((source) => source !== null);
|
|
124
291
|
}
|
|
292
|
+
export function runtimeSessionEvidenceSummariesFromMaterialPayload(payload) {
|
|
293
|
+
if (!isRecord(payload))
|
|
294
|
+
return null;
|
|
295
|
+
if (payload['schema'] !== MATERIAL_RUNTIME_SESSION_SNAPSHOT_SCHEMA)
|
|
296
|
+
return null;
|
|
297
|
+
if (payload['sourceKind'] !== 'runtime_session' || payload['kind'] !== 'session_log')
|
|
298
|
+
return null;
|
|
299
|
+
const sources = Array.isArray(payload['sources']) ? payload['sources'] : [];
|
|
300
|
+
const hasCountMetadata = payload['sourceCount'] !== undefined || payload['omittedSourceCount'] !== undefined;
|
|
301
|
+
const sourceCount = hasCountMetadata ? payload['sourceCount'] : sources.length;
|
|
302
|
+
const omittedSourceCount = hasCountMetadata ? payload['omittedSourceCount'] : 0;
|
|
303
|
+
if (!Number.isSafeInteger(sourceCount)
|
|
304
|
+
|| sourceCount < sources.length
|
|
305
|
+
|| !Number.isSafeInteger(omittedSourceCount)
|
|
306
|
+
|| omittedSourceCount < 0
|
|
307
|
+
|| omittedSourceCount !== sourceCount - sources.length)
|
|
308
|
+
return null;
|
|
309
|
+
const omittedEvidenceAggregate = payload['omittedEvidenceAggregate'] === undefined
|
|
310
|
+
? undefined
|
|
311
|
+
: evidenceAggregateFromSnapshot(payload['omittedEvidenceAggregate']);
|
|
312
|
+
if (omittedSourceCount > 0) {
|
|
313
|
+
if (!omittedEvidenceAggregate || omittedEvidenceAggregate.sourceCount !== omittedSourceCount)
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
else if (payload['omittedEvidenceAggregate'] !== undefined)
|
|
317
|
+
return null;
|
|
318
|
+
const summaries = sources.flatMap((source) => {
|
|
319
|
+
if (!isRecord(source)
|
|
320
|
+
|| typeof source['agent'] !== 'string'
|
|
321
|
+
|| !source['agent'].trim()
|
|
322
|
+
|| typeof source['label'] !== 'string'
|
|
323
|
+
|| !source['label'].trim())
|
|
324
|
+
return [];
|
|
325
|
+
const summary = evidenceSummaryFromSnapshot(source['evidenceSummary']);
|
|
326
|
+
if (!summary)
|
|
327
|
+
return [];
|
|
328
|
+
const sessionId = typeof source['sessionId'] === 'string' && source['sessionId'].trim()
|
|
329
|
+
? source['sessionId']
|
|
330
|
+
: undefined;
|
|
331
|
+
return [{
|
|
332
|
+
agent: source['agent'],
|
|
333
|
+
label: source['label'],
|
|
334
|
+
...(sessionId ? { sessionId } : {}),
|
|
335
|
+
evidenceSummary: summary,
|
|
336
|
+
}];
|
|
337
|
+
});
|
|
338
|
+
if (hasCountMetadata && summaries.length !== sources.length)
|
|
339
|
+
return null;
|
|
340
|
+
return {
|
|
341
|
+
sourceCount: sourceCount,
|
|
342
|
+
omittedSourceCount: omittedSourceCount,
|
|
343
|
+
summaries,
|
|
344
|
+
...(omittedEvidenceAggregate ? { omittedEvidenceAggregate } : {}),
|
|
345
|
+
};
|
|
346
|
+
}
|
|
125
347
|
export function materialHasRuntimeSessionSnapshot(material) {
|
|
126
348
|
return runtimeSessionSourcesFromMaterialPayload(material.payload).length > 0;
|
|
127
349
|
}
|
package/dist/recipe.js
CHANGED
|
@@ -701,10 +701,16 @@ function resolveRecipeHubCredentials(env) {
|
|
|
701
701
|
* the next recipe run (H3). Kept env-pure (no events.evomapHome()) so reset stays hermetic under an injected env.
|
|
702
702
|
*/
|
|
703
703
|
export function explicitRecipeHomes(env) {
|
|
704
|
+
// Identity-first order (#555 T2): EVOMAP_HOME is THE identity home and outranks the state root
|
|
705
|
+
// (EVOLVER_HOME). This order decides BOTH the read fall-through AND rotatePersistDir (= homes[0]),
|
|
706
|
+
// so under the evox agentDir split (EVOMAP_HOME=<agentDir>/evomap, EVOLVER_HOME=<agentDir>/evolver)
|
|
707
|
+
// a hub-rotated secret persists into the evomap dir the desktop actually reads — the old
|
|
708
|
+
// EVOLVER_HOME-first order would strand it in the state root and split-brain the node on rotation.
|
|
709
|
+
// Read-your-writes holds because read and persist share this one order; single-home setups are unchanged.
|
|
704
710
|
const explicit = [
|
|
711
|
+
env['EVOMAP_HOME'],
|
|
705
712
|
env['EVOMAP_DIR'],
|
|
706
713
|
env['EVOLVER_HOME'],
|
|
707
|
-
env['EVOMAP_HOME'],
|
|
708
714
|
];
|
|
709
715
|
return uniqueStrings(explicit.map((value) => value?.trim()).filter((value) => Boolean(value)));
|
|
710
716
|
}
|
package/dist/reuse.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assetstore, hub as hubNs } from '@evomap/evolver-core';
|
|
2
|
-
import type { ConnectPublicOptions, PublicHubCapability } from '@evomap/evolver-adapter-public';
|
|
2
|
+
import type { ConnectPublicOptions, PublicHelloOptions, PublicHubCapability } from '@evomap/evolver-adapter-public';
|
|
3
3
|
declare const REUSE_CONTRACT = "reuse.v1";
|
|
4
|
-
export type ReuseStatus = 'ok' | 'dry_run' | 'invalid_arg' | 'missing_id' | 'unsupported' | 'not_found' | 'unauthorized' | 'unavailable' | 'network' | 'internal_error';
|
|
4
|
+
export type ReuseStatus = 'ok' | 'dry_run' | 'invalid_arg' | 'missing_id' | 'unsupported' | 'not_found' | 'unauthorized' | 'unavailable' | 'network' | 'rate_limited' | 'internal_error';
|
|
5
5
|
/** The stable reuse.v1 machine contract printed to stdout on success AND failure. Field set is locked by the
|
|
6
6
|
* consumer (evox-desktop `evolverReuseEnvelope`, #1008): { ok, contract, status, reason, message }. */
|
|
7
7
|
export interface ReuseEnvelope {
|
|
@@ -11,9 +11,11 @@ export interface ReuseEnvelope {
|
|
|
11
11
|
reason: string;
|
|
12
12
|
message: string;
|
|
13
13
|
}
|
|
14
|
-
/** Minimal hub surface this command needs:
|
|
14
|
+
/** Minimal hub surface this command needs: a single fetch-by-id, plus an optional trust-establishing hello
|
|
15
|
+
* (PublicHubCapability satisfies both; a bare fetcher in tests may omit hello). */
|
|
15
16
|
type AssetByIdFetcher = {
|
|
16
17
|
fetchAssetById(assetId: string): Promise<assetstore.AssetRecord | null>;
|
|
18
|
+
hello?(opts: PublicHelloOptions): Promise<unknown>;
|
|
17
19
|
};
|
|
18
20
|
export interface ReuseCliDeps {
|
|
19
21
|
store?: assetstore.AssetStoreProvider;
|
package/dist/reuse.js
CHANGED
|
@@ -14,6 +14,7 @@ import { assetstore, events, hub as hubNs, wire } from '@evomap/evolver-core';
|
|
|
14
14
|
import { AuthError, HubClientError, HubUnreachableError, connectPublicHub, isHubDryRunEnabled } from '@evomap/evolver-adapter-public';
|
|
15
15
|
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
16
16
|
import { createRecipeHubFromEnv } from './recipe.js';
|
|
17
|
+
import { getCliVersion } from './version.js';
|
|
17
18
|
const REUSE_CONTRACT = 'reuse.v1';
|
|
18
19
|
const MAX_ID_LENGTH = 200;
|
|
19
20
|
const REUSE_USAGE = [
|
|
@@ -23,6 +24,8 @@ const REUSE_USAGE = [
|
|
|
23
24
|
// Flags that consume the following token as their value. firstPositional must skip those values so a flag value
|
|
24
25
|
// (e.g. the `reference` in `--mode reference`) is never mistaken for a bare positional asset id.
|
|
25
26
|
const VALUE_FLAGS = new Set(['--id', '--mode', '--run']);
|
|
27
|
+
// Keep this list limited to Hub-only fields. `confidence` is canonical Capsule content and must
|
|
28
|
+
// survive integrity verification even though delivery rows also use a field with that name.
|
|
26
29
|
const HUB_METADATA_KEYS = new Set([
|
|
27
30
|
'credit_cost',
|
|
28
31
|
'gdi_score',
|
|
@@ -86,6 +89,12 @@ export async function runReuseCommand(argv, deps = {}) {
|
|
|
86
89
|
}
|
|
87
90
|
// 3) Pull the global asset by id, write it into the local recall library (put dedups → idempotent on repeat).
|
|
88
91
|
const hub = deps.hub ?? createRecipeHubFromEnv(env, deps.connectHub ?? connectPublicHub);
|
|
92
|
+
// One-shot CLIs never heartbeat, so the hub may hold no env fingerprint for this node and its anti-abuse
|
|
93
|
+
// layer then 403s /a2a/fetch (`bulk_fetch_blocked: IP antibody`, #555). A fingerprinted hello
|
|
94
|
+
// (rotate:false + preserveCredentials:true) neither requests nor applies credential mutation while establishing
|
|
95
|
+
// trust. Best-effort by design:
|
|
96
|
+
// a hello failure must not block the fetch — the fetch's own error path classifies precisely.
|
|
97
|
+
await establishReuseTrust(hub);
|
|
89
98
|
const asset = await hub.fetchAssetById(opts.id);
|
|
90
99
|
if (!asset)
|
|
91
100
|
return emit({ ok: false, status: 'not_found', message: `asset ${opts.id} not found on the hub` }, ctx);
|
|
@@ -159,7 +168,7 @@ export function parseReuseArgs(argv) {
|
|
|
159
168
|
return { ok: true, value: { id, mode: modeRaw === 'direct' ? 'direct' : 'reference', ...(runId ? { runId } : {}) } };
|
|
160
169
|
}
|
|
161
170
|
async function ingestHubAsset(store, deps, asset, requestedId) {
|
|
162
|
-
const cleaned = stripHubMetadata(asset);
|
|
171
|
+
const cleaned = stripHubMetadata(unwrapHubAssetContent(asset));
|
|
163
172
|
const actualAssetId = wire.computeAssetId(cleaned);
|
|
164
173
|
const contentAssetId = stringField(cleaned, 'asset_id');
|
|
165
174
|
if (!actualAssetId || !contentAssetId || actualAssetId !== contentAssetId) {
|
|
@@ -203,6 +212,13 @@ async function assertNoLocalReuseIdConflict(asset, store) {
|
|
|
203
212
|
if (incomingAssetId !== localAssetId)
|
|
204
213
|
throw new Error('local asset id conflict');
|
|
205
214
|
}
|
|
215
|
+
function unwrapHubAssetContent(asset) {
|
|
216
|
+
const payload = asset.payload;
|
|
217
|
+
if (payload && typeof payload === 'object' && !Array.isArray(payload) && stringField(payload, 'asset_id')) {
|
|
218
|
+
return payload;
|
|
219
|
+
}
|
|
220
|
+
return asset;
|
|
221
|
+
}
|
|
206
222
|
function stripHubMetadata(asset) {
|
|
207
223
|
const out = {};
|
|
208
224
|
for (const [key, value] of Object.entries(asset))
|
|
@@ -232,17 +248,48 @@ function logReuse(deps, opts, asset, source) {
|
|
|
232
248
|
extra: { source },
|
|
233
249
|
});
|
|
234
250
|
}
|
|
251
|
+
async function establishReuseTrust(hub) {
|
|
252
|
+
if (typeof hub.hello !== 'function')
|
|
253
|
+
return;
|
|
254
|
+
try {
|
|
255
|
+
await hub.hello({ rotate: false, evolverVersion: getCliVersion(), preserveCredentials: true });
|
|
256
|
+
}
|
|
257
|
+
catch { /* fetch decides the outcome */ }
|
|
258
|
+
}
|
|
259
|
+
const ANTI_ABUSE_BLOCK_MESSAGE = 'hub anti-abuse temporarily blocked asset fetch for this node; keep the local Evolver proxy running so the node builds trust, then retry';
|
|
260
|
+
function antiAbuseOutcome() {
|
|
261
|
+
return { ok: false, status: 'rate_limited', message: ANTI_ABUSE_BLOCK_MESSAGE };
|
|
262
|
+
}
|
|
263
|
+
function isAntiAbuseFetchBlock(status, code) {
|
|
264
|
+
return status === 403 && code !== undefined && /antibody|bulk_fetch|anti[-_]?abuse/i.test(code);
|
|
265
|
+
}
|
|
266
|
+
function hubErrorField(body) {
|
|
267
|
+
if (!body || typeof body !== 'object')
|
|
268
|
+
return undefined;
|
|
269
|
+
const err = body['error'];
|
|
270
|
+
return typeof err === 'string' ? err : undefined;
|
|
271
|
+
}
|
|
235
272
|
function mapError(e) {
|
|
236
|
-
if (e instanceof AuthError)
|
|
273
|
+
if (e instanceof AuthError) {
|
|
274
|
+
// hubFetch raises AuthError for BOTH 401 and 403, so the hub's anti-abuse 403
|
|
275
|
+
// (`bulk_fetch_blocked: IP antibody active`) used to be misreported as "log in" — it is an
|
|
276
|
+
// abuse-control block on a perfectly healthy credential, not an auth failure (#555).
|
|
277
|
+
if (isAntiAbuseFetchBlock(e.status, e.errorCode))
|
|
278
|
+
return antiAbuseOutcome();
|
|
237
279
|
return { ok: false, status: 'unauthorized', message: 'hub authentication failed; run `evolver login` or set EVOMAP_NODE_SECRET' };
|
|
280
|
+
}
|
|
238
281
|
if (e instanceof HubUnreachableError)
|
|
239
282
|
return { ok: false, status: 'network', message: 'hub is unreachable' };
|
|
240
283
|
if (e instanceof HubClientError) {
|
|
284
|
+
if (e.status === 429)
|
|
285
|
+
return { ok: false, status: 'rate_limited', message: 'hub rate limited the request; retry later' };
|
|
286
|
+
if (isAntiAbuseFetchBlock(e.status, hubErrorField(e.body)))
|
|
287
|
+
return antiAbuseOutcome();
|
|
241
288
|
if (e.status === 401 || e.status === 403)
|
|
242
289
|
return { ok: false, status: 'unauthorized', message: 'hub authentication failed; run `evolver login` or set EVOMAP_NODE_SECRET' };
|
|
243
290
|
if (e.status === 404)
|
|
244
291
|
return { ok: false, status: 'not_found', message: 'asset not found on the hub' };
|
|
245
|
-
if (e.status
|
|
292
|
+
if (e.status >= 500)
|
|
246
293
|
return { ok: false, status: 'network', message: 'hub is temporarily unavailable' };
|
|
247
294
|
return { ok: false, status: 'internal_error', message: 'hub rejected the reuse request' };
|
|
248
295
|
}
|
package/dist/setupHooks.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { type InstallScope } from '@evomap/evolver-mcp';
|
|
1
2
|
import { assetstore } from '@evomap/evolver-core';
|
|
2
3
|
import { maybeEmitNonGitWorkspaceNotice } from './nonGitWorkspaceNotice.js';
|
|
3
4
|
interface SetupHooksDeps {
|
|
4
5
|
emitNonGitWorkspaceNotice?: typeof maybeEmitNonGitWorkspaceNotice;
|
|
6
|
+
runtimeAvailable?: (runtime: 'opencode' | 'kiro', configRoot: string, scope: InstallScope) => boolean;
|
|
5
7
|
}
|
|
8
|
+
export declare function commandNamesForPath(command: string, platform: NodeJS.Platform, pathExt: string | undefined): string[];
|
|
9
|
+
export declare function safeSetupOperationError(error: unknown): string;
|
|
10
|
+
export declare function safeSetupResultError(error: unknown): string;
|
|
6
11
|
export declare function runSetupHooks(argv: readonly string[], store?: assetstore.AssetStoreProvider, review?: assetstore.ReviewLedger, deps?: SetupHooksDeps): Promise<number>;
|
|
7
12
|
export {};
|