@evomap/evolver-cli 2.0.0-beta.17 → 2.0.0-beta.19

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.
Files changed (64) hide show
  1. package/dist/antiGeneRollout.js +7 -3
  2. package/dist/assetTrust.js +14 -1
  3. package/dist/atp.d.ts +8 -3
  4. package/dist/atp.js +82 -11
  5. package/dist/atpAutoBuyer.d.ts +120 -0
  6. package/dist/atpAutoBuyer.js +814 -0
  7. package/dist/atpAutoDeliver.js +2 -2
  8. package/dist/autoDistillLlm.js +2 -1
  9. package/dist/autoDistillTranscript.js +3 -2
  10. package/dist/autoexec.d.ts +90 -13
  11. package/dist/autoexec.js +731 -84
  12. package/dist/cli.js +13 -0
  13. package/dist/cliContracts.d.ts +5 -2
  14. package/dist/cliContracts.js +135 -8
  15. package/dist/commands.d.ts +1 -0
  16. package/dist/commands.js +1 -0
  17. package/dist/curriculumCapabilityGaps.d.ts +6 -0
  18. package/dist/curriculumCapabilityGaps.js +24 -0
  19. package/dist/cycleConsumer.d.ts +4 -0
  20. package/dist/cycleConsumer.js +175 -20
  21. package/dist/dashboard.js +47 -9
  22. package/dist/dispatch.js +6 -2
  23. package/dist/distillPrimitives.js +18 -6
  24. package/dist/doctor.js +63 -5
  25. package/dist/identityHome.js +2 -1
  26. package/dist/index.d.ts +67 -39
  27. package/dist/index.js +504 -185
  28. package/dist/learningTrace.d.ts +4 -0
  29. package/dist/learningTrace.js +30 -3
  30. package/dist/lifecycle.d.ts +54 -1
  31. package/dist/lifecycle.js +489 -37
  32. package/dist/materialSnapshot.d.ts +9 -1
  33. package/dist/materialSnapshot.js +23 -6
  34. package/dist/migrate/envTranslate.d.ts +26 -0
  35. package/dist/migrate/envTranslate.js +145 -0
  36. package/dist/migrate/oauthImport.d.ts +66 -0
  37. package/dist/migrate/oauthImport.js +667 -0
  38. package/dist/migrate/v1Import.d.ts +13 -1
  39. package/dist/migrate/v1Import.js +621 -122
  40. package/dist/promptRecallHook.d.ts +24 -0
  41. package/dist/promptRecallHook.js +425 -0
  42. package/dist/recallVerifyReport.d.ts +37 -0
  43. package/dist/recallVerifyReport.js +244 -0
  44. package/dist/requiredSandboxValidation.d.ts +5 -0
  45. package/dist/requiredSandboxValidation.js +4 -0
  46. package/dist/reuse.d.ts +1 -0
  47. package/dist/reuse.js +45 -37
  48. package/dist/runtimeCapabilities.js +13 -13
  49. package/dist/runtimeSessionSource.d.ts +3 -2
  50. package/dist/runtimeSessionSource.js +63 -11
  51. package/dist/sessionIngest.d.ts +37 -0
  52. package/dist/sessionIngest.js +156 -0
  53. package/dist/setupHooks.js +95 -1
  54. package/dist/skill2gep.d.ts +4 -7
  55. package/dist/skill2gep.js +4 -21
  56. package/dist/solo/mode.js +1 -0
  57. package/dist/sync.js +125 -23
  58. package/dist/thesis.d.ts +1 -1
  59. package/dist/thesis.js +18 -3
  60. package/dist/trajectoryExport.js +21 -3
  61. package/dist/v1Compat.d.ts +1 -0
  62. package/dist/v1Compat.js +9 -0
  63. package/dist/workflowRuntime.js +24 -18
  64. package/package.json +10 -7
package/dist/cli.js CHANGED
@@ -1,11 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
  import { settleCliProcess } from './cliLifecycle.js';
3
+ import { bootstrap } from '@evomap/evolver-core';
3
4
  const argv = process.argv.slice(2);
5
+ // Emit deprecation warnings for any V1 env vars still present in the environment.
6
+ bootstrap.checkV1EnvCompat(process.env);
4
7
  async function main() {
5
8
  if (argv[0] === 'proxy-token') {
6
9
  const { runProxyToken } = await import('./proxyToken.js');
7
10
  return runProxyToken(argv.slice(1));
8
11
  }
12
+ if (argv[0] === 'inject' && argv[1] === 'prompt-recall') {
13
+ const recallMode = String(process.env['EVOLVER_RECALL_MODE'] ?? '').trim().toLowerCase();
14
+ const hasEnvFile = Boolean(process.env['EVOLVER_ENV_FILE']?.trim());
15
+ if (!hasEnvFile && recallMode !== 'shadow' && recallMode !== 'enforce') {
16
+ process.stdout.write('{}\n');
17
+ return 0;
18
+ }
19
+ const { runPromptRecallHook } = await import('./promptRecallHook.js');
20
+ return runPromptRecallHook(argv.slice(2));
21
+ }
9
22
  const { dispatch } = await import('./dispatch.js');
10
23
  // Single dispatch path (registry in dispatch.ts): async handler if the verb is registered, else the runCli core.
11
24
  // Promise.resolve normalizes the sync (runCli → number) and async (handler → Promise<number>) branches to one exit.
@@ -1,8 +1,8 @@
1
- import { assetstore } from '@evomap/evolver-core';
1
+ import { assetstore, hub } from '@evomap/evolver-core';
2
2
  type WritableLike = {
3
3
  write(chunk: string): unknown;
4
4
  };
5
- type ContractReason = 'missing_id' | 'cli_unavailable' | 'auth_required' | 'not_found' | 'network_error' | 'unsupported' | 'internal_error' | 'redaction_unavailable' | 'leak_detected' | 'schema_invalid' | 'bundle_required' | 'quality_gate_failed' | 'gene_unproven' | 'insufficient_credits';
5
+ type ContractReason = 'missing_id' | 'cli_unavailable' | 'auth_required' | 'not_found' | 'network_error' | 'unsupported' | 'internal_error' | 'redaction_unavailable' | 'leak_detected' | 'schema_invalid' | 'bundle_required' | 'quality_gate_failed' | 'gene_unproven' | 'insufficient_credits' | 'unsafe_validation_command';
6
6
  export interface ReuseParseResult {
7
7
  ok: boolean;
8
8
  assetId?: string;
@@ -24,6 +24,7 @@ interface GateSummary {
24
24
  schema?: 'pass' | 'fail';
25
25
  bundle?: 'pass' | 'fail';
26
26
  quality?: 'pass' | 'fail';
27
+ validation_command?: 'pass' | 'fail';
27
28
  }
28
29
  interface PublishAssetSummary {
29
30
  asset_id?: string;
@@ -34,6 +35,7 @@ export type PublishBundleResult = {
34
35
  original: assetstore.AssetRecord[];
35
36
  sanitized: assetstore.AssetRecord[];
36
37
  blockReasons: ContractReason[];
38
+ blockMessages?: Partial<Record<ContractReason, string>>;
37
39
  gates: GateSummary;
38
40
  assets: PublishAssetSummary[];
39
41
  } | {
@@ -77,6 +79,7 @@ export interface CliContractDeps {
77
79
  fetchAssetById?: (assetId: string) => Promise<assetstore.AssetRecord | null>;
78
80
  validate?: (bundle: readonly assetstore.AssetRecord[]) => Promise<HubCallResult>;
79
81
  publish?: (bundle: readonly assetstore.AssetRecord[]) => Promise<HubCallResult>;
82
+ callLog?: Pick<hub.AssetCallLog, 'append'>;
80
83
  /** Test seam for private-mode proxy discovery. Production resolves the loopback proxy from env/settings. */
81
84
  resolveProxyClient?: (env: NodeJS.ProcessEnv) => PrivateContractProxy | undefined;
82
85
  }
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, statSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { inspect, format } from 'node:util';
4
- import { assetstore, events, hub, wire, algo } from '@evomap/evolver-core';
4
+ import { assetstore, events, hub, wire, algo, verify } from '@evomap/evolver-core';
5
5
  import { AuthError, HubClientError, HubFetch, HubUnreachableError, connectPublicHub, gepEnvelope, globalFetchLike, resolveHubUrl, } from '@evomap/evolver-adapter-public';
6
6
  import { loadEnvFileFromEnv, proxyClientFromEnv } from '@evomap/evolver-mcp';
7
7
  import { resolveAtpSenderId } from './atp.js';
@@ -30,6 +30,7 @@ const STABLE_CONTRACT_REASONS = new Set([
30
30
  'quality_gate_failed',
31
31
  'gene_unproven',
32
32
  'insufficient_credits',
33
+ 'unsafe_validation_command',
33
34
  ]);
34
35
  const HUB_METADATA_KEYS = new Set([
35
36
  'credit_cost',
@@ -156,7 +157,8 @@ export async function runPublishCommand(args, deps = {}) {
156
157
  if (parsed.dryRun)
157
158
  return write(dryRunEnvelope(bundle), 0);
158
159
  const reason = bundle.blockReasons[0] ?? 'internal_error';
159
- return write(publishFailure(reason, publishReasonMessage(reason), {
160
+ const detailMessage = bundle.blockMessages?.[reason];
161
+ return write(publishFailure(reason, detailMessage ?? publishReasonMessage(reason), {
160
162
  retryable: false,
161
163
  mode: 'publish',
162
164
  gates: bundle.gates,
@@ -240,6 +242,7 @@ export async function runPublishCommand(args, deps = {}) {
240
242
  }
241
243
  const receiptId = stringField(payload, 'receipt_id');
242
244
  const bundleId = stringField(payload, 'bundle_id');
245
+ appendPublishedCapsuleCall(bundle, deps, { status, receiptId, bundleId });
243
246
  return write({
244
247
  ok: true,
245
248
  contract: PUBLISH_CONTRACT,
@@ -262,6 +265,35 @@ export async function runPublishCommand(args, deps = {}) {
262
265
  }
263
266
  });
264
267
  }
268
+ function appendPublishedCapsuleCall(bundle, deps, receipt) {
269
+ const capsuleIndex = bundle.sanitized.findIndex((asset) => asset.type === 'Capsule');
270
+ if (capsuleIndex < 0)
271
+ return;
272
+ const publishedCapsule = bundle.sanitized[capsuleIndex];
273
+ const originalCapsule = bundle.original[capsuleIndex];
274
+ if (!publishedCapsule)
275
+ return;
276
+ const tokensSpent = hub.assetDerivationTokenCost(originalCapsule);
277
+ const trigger = Array.isArray(publishedCapsule['trigger'])
278
+ ? publishedCapsule['trigger'].filter((value) => typeof value === 'string')
279
+ : undefined;
280
+ try {
281
+ const callLog = deps.callLog ?? new hub.AssetCallLog(events.assetCallLogPath(deps.env ?? process.env));
282
+ callLog.append({
283
+ action: 'asset_publish',
284
+ asset_id: publishedCapsule.asset_id,
285
+ asset_type: 'Capsule',
286
+ ...(trigger ? { signals: trigger } : {}),
287
+ ...(tokensSpent !== undefined ? { tokens_spent: tokensSpent } : {}),
288
+ extra: {
289
+ status: receipt.status,
290
+ ...(receipt.receiptId ? { receipt_id: receipt.receiptId } : {}),
291
+ ...(receipt.bundleId ? { bundle_id: receipt.bundleId } : {}),
292
+ },
293
+ });
294
+ }
295
+ catch { /* a local audit failure must never change an accepted Hub publish */ }
296
+ }
265
297
  export function parseReuseArgs(args) {
266
298
  let id;
267
299
  let jsonOut = false;
@@ -372,23 +404,36 @@ export async function buildPublishBundle(refs, deps = {}) {
372
404
  // with a precise reason. Read-only: aggregates the local capsule history.
373
405
  const geneEvidence = await assessPublishGeneEvidence(original, deps);
374
406
  const geneProven = geneEvidence?.eligible ?? true;
407
+ // Local quality gate: validation command safety check.
408
+ // Only applies to Gene assets. Checks that all validation commands are safe
409
+ // (e.g., no `node -e`, no shell metacharacters).
410
+ const validationCommandResult = checkValidationCommands(original);
375
411
  const gates = {
376
412
  redaction: 'pass',
377
413
  leak: leak.blocked ? 'fail' : 'pass',
378
414
  schema: 'pass',
379
415
  bundle: 'pass',
380
416
  quality: geneProven ? 'pass' : 'fail',
417
+ validation_command: validationCommandResult.allowed ? 'pass' : 'fail',
381
418
  };
382
419
  const blockReasons = [];
420
+ const blockMessages = {};
383
421
  if (leak.blocked)
384
422
  blockReasons.push('leak_detected');
385
423
  if (!geneProven)
386
424
  blockReasons.push('gene_unproven');
425
+ if (!validationCommandResult.allowed) {
426
+ blockReasons.push('unsafe_validation_command');
427
+ if (validationCommandResult.message) {
428
+ blockMessages['unsafe_validation_command'] = validationCommandResult.message;
429
+ }
430
+ }
387
431
  return {
388
432
  ok: true,
389
433
  original,
390
434
  sanitized,
391
435
  blockReasons,
436
+ blockMessages,
392
437
  gates,
393
438
  assets: summarizePublishAssets(sanitized),
394
439
  };
@@ -410,12 +455,25 @@ async function assessPublishGeneEvidence(original, deps) {
410
455
  const store = deps.assetStore ?? new assetstore.LocalJsonlProvider(contractAssetsDir(deps));
411
456
  const primary = await algo.assessGenePublishEvidence(store, geneId);
412
457
  // Capsules key their `gene` link by the gene's business id in production;
413
- // some stores (and legacy fixtures) key it by asset_id. If the business-id
414
- // lookup found no history, retry by asset_id before concluding "unproven".
415
- if (primary.total === 0 && assetId && assetId !== geneId) {
458
+ // some stores (and legacy fixtures) key it by asset_id. Mixed histories can
459
+ // contain failures under the business id and a success under asset_id, so
460
+ // both aliases must contribute to the gate rather than only falling back
461
+ // when the primary alias has no rows at all.
462
+ if (assetId && assetId !== geneId) {
416
463
  const byAssetId = await algo.assessGenePublishEvidence(store, assetId);
417
- if (byAssetId.total > 0)
418
- return byAssetId;
464
+ const combined = {
465
+ success: primary.success + byAssetId.success,
466
+ failed: primary.failed + byAssetId.failed,
467
+ inert: primary.inert + byAssetId.inert,
468
+ total: primary.total + byAssetId.total,
469
+ };
470
+ const eligible = algo.isGenePublishEligible(combined);
471
+ return {
472
+ geneId,
473
+ ...combined,
474
+ eligible,
475
+ reason: eligible ? 'eligible' : 'no_proven_success',
476
+ };
419
477
  }
420
478
  return primary;
421
479
  }
@@ -423,6 +481,64 @@ async function assessPublishGeneEvidence(original, deps) {
423
481
  return null;
424
482
  }
425
483
  }
484
+ /**
485
+ * 检查 Gene 资产中的验证命令是否安全。
486
+ * 只检查 Gene 类型的资产,不影响 Capsule 或 EvolutionEvent。
487
+ * 如果 Gene 有 validation 数组,会检查每条命令是否符合安全策略。
488
+ * 不安全的命令(如 `node -e`、包含 shell 元字符等)会阻止发布。
489
+ */
490
+ function checkValidationCommands(original) {
491
+ const gene = original.find((asset) => asset.type === 'Gene');
492
+ if (!gene)
493
+ return { allowed: true, unsafeCommands: [] };
494
+ const validation = gene['validation'];
495
+ if (!Array.isArray(validation) || validation.length === 0) {
496
+ return { allowed: true, unsafeCommands: [] };
497
+ }
498
+ const unsafeCommands = [];
499
+ for (const cmd of validation) {
500
+ if (typeof cmd !== 'string')
501
+ continue;
502
+ if (!verify.isValidationCommandAllowed(cmd)) {
503
+ unsafeCommands.push(cmd);
504
+ }
505
+ }
506
+ if (unsafeCommands.length === 0) {
507
+ return { allowed: true, unsafeCommands: [] };
508
+ }
509
+ // 构建诊断信息(不暴露原始命令文本,避免泄露安全策略细节)
510
+ const reasons = new Set();
511
+ for (const cmd of unsafeCommands) {
512
+ if (/`|\$\(/.test(cmd)) {
513
+ reasons.add('command_substitution');
514
+ continue;
515
+ }
516
+ const stripped = cmd.replace(/"[^"]*"/g, '').replace(/'[^']*'/g, '');
517
+ if (verify.SHELL_METACHARS.test(stripped)) {
518
+ reasons.add('shell_metacharacters');
519
+ continue;
520
+ }
521
+ const tokens = cmd.split(/\s+/);
522
+ const executable = tokens[0] ?? '';
523
+ const args = tokens.slice(1);
524
+ const badFlag = verify.isNodeExecutable(executable) ? verify.nodeFlagViolation(executable, args) : null;
525
+ if (badFlag) {
526
+ reasons.add('blocked_node_flag');
527
+ continue;
528
+ }
529
+ if (!cmd.trim().startsWith('node ')) {
530
+ reasons.add('non_node_command');
531
+ }
532
+ else {
533
+ reasons.add('unsafe_pattern');
534
+ }
535
+ }
536
+ return {
537
+ allowed: false,
538
+ unsafeCommands,
539
+ message: `validation command rejected: ${[...reasons].join(', ')}`,
540
+ };
541
+ }
426
542
  function sanitizePublishBundle(original) {
427
543
  const sanitized = original.map((asset) => hub.sanitizeAsset(stripPublishMetadata(asset)));
428
544
  const finalGeneIdByOriginalRef = new Map();
@@ -587,6 +703,16 @@ function contractAssetsDir(deps) {
587
703
  }
588
704
  function dryRunEnvelope(bundle, credits, blockDetail) {
589
705
  const suppressPayload = bundle.blockReasons.includes('leak_detected');
706
+ // Collect detailed messages for block reasons
707
+ const blockDetails = [];
708
+ if (blockDetail)
709
+ blockDetails.push(blockDetail);
710
+ for (const reason of bundle.blockReasons) {
711
+ const detailMessage = bundle.blockMessages?.[reason];
712
+ if (detailMessage && !blockDetails.includes(detailMessage)) {
713
+ blockDetails.push(detailMessage);
714
+ }
715
+ }
590
716
  return {
591
717
  ok: true,
592
718
  contract: PUBLISH_CONTRACT,
@@ -594,7 +720,7 @@ function dryRunEnvelope(bundle, credits, blockDetail) {
594
720
  reversibility: REVERSIBILITY,
595
721
  blocked: bundle.blockReasons.length > 0,
596
722
  block_reasons: bundle.blockReasons,
597
- ...(blockDetail ? { block_details: [blockDetail] } : {}),
723
+ ...(blockDetails.length > 0 ? { block_details: blockDetails } : {}),
598
724
  assets: bundle.assets,
599
725
  ...(suppressPayload ? {} : { payload: { assets: bundle.sanitized } }),
600
726
  gates: bundle.gates,
@@ -913,6 +1039,7 @@ function publishReasonMessage(reason) {
913
1039
  quality_gate_failed: 'Hub quality gate failed',
914
1040
  gene_unproven: 'gene has no proven success yet — run it to a successful outcome before publishing',
915
1041
  insufficient_credits: 'insufficient credits',
1042
+ unsafe_validation_command: 'validation command contains unsafe patterns (e.g., node -e, shell metacharacters) blocked by sandbox security policy',
916
1043
  };
917
1044
  return map[reason] ?? map.internal_error;
918
1045
  }
@@ -5,5 +5,6 @@ export declare const listCycles: typeof events.listCycles;
5
5
  export declare const showCycle: typeof events.showCycle;
6
6
  export declare const listTriggers: typeof events.listTriggers;
7
7
  export declare const dailySummary: typeof events.dailySummary;
8
+ export declare const dailyCapsuleCount: typeof events.dailyCapsuleCount;
8
9
  export declare const buildNarrativeSnapshot: typeof events.buildNarrativeSnapshot;
9
10
  export declare const buildRetentionReport: typeof events.buildRetentionReport;
package/dist/commands.js CHANGED
@@ -6,5 +6,6 @@ export const listCycles = events.listCycles;
6
6
  export const showCycle = events.showCycle;
7
7
  export const listTriggers = events.listTriggers;
8
8
  export const dailySummary = events.dailySummary;
9
+ export const dailyCapsuleCount = events.dailyCapsuleCount;
9
10
  export const buildNarrativeSnapshot = events.buildNarrativeSnapshot;
10
11
  export const buildRetentionReport = events.buildRetentionReport;
@@ -0,0 +1,6 @@
1
+ type CapabilityGapsEnv = Readonly<Record<string, string | undefined>>;
2
+ export declare function resolveCurriculumMailboxPath(env?: CapabilityGapsEnv): string;
3
+ /** Read one immutable lifecycle snapshot per curriculum preparation without creating a proxy database. */
4
+ export declare function readPersistedCapabilityGaps(env?: CapabilityGapsEnv): string[];
5
+ export declare function makeCurriculumCapabilityGapsProvider(env?: CapabilityGapsEnv): () => readonly string[];
6
+ export {};
@@ -0,0 +1,24 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { events, mailbox, signals } from '@evomap/evolver-core';
4
+ export function resolveCurriculumMailboxPath(env = process.env) {
5
+ const configured = env['EVOLVER_PROXY_STORE']?.trim();
6
+ return configured && configured.length > 0
7
+ ? configured
8
+ : join(events.evomapHome(env), 'proxy', 'mailbox.db');
9
+ }
10
+ /** Read one immutable lifecycle snapshot per curriculum preparation without creating a proxy database. */
11
+ export function readPersistedCapabilityGaps(env = process.env) {
12
+ const path = resolveCurriculumMailboxPath(env);
13
+ if (!existsSync(path))
14
+ return [];
15
+ try {
16
+ return signals.capabilityGapsFromState(mailbox.readMailboxState(path, signals.CAPABILITY_GAPS_STATE_KEY));
17
+ }
18
+ catch {
19
+ return [];
20
+ }
21
+ }
22
+ export function makeCurriculumCapabilityGapsProvider(env = process.env) {
23
+ return () => readPersistedCapabilityGaps(env);
24
+ }
@@ -60,6 +60,8 @@ export interface MaterialCycleOptions {
60
60
  validationCmds?: readonly string[];
61
61
  validate?: exec.AutoExecDeps['validate'];
62
62
  runner?: RunnerName;
63
+ /** Resume the single native Claude Code or Cursor session represented by each material. Default false. */
64
+ resume?: boolean;
63
65
  timeoutMs?: number;
64
66
  signal?: AbortSignal;
65
67
  safety?: Partial<exec.AutonomousSafety>;
@@ -91,6 +93,8 @@ export interface MaterialCycleDeps {
91
93
  safety?: Partial<exec.AutonomousSafety>;
92
94
  sleep?: SleepFn;
93
95
  watchStateWriter?: (path: string, state: MaterialCycleWatchState) => void;
96
+ /** User home whose native runtime directories may contribute resumable session identities. */
97
+ nativeSessionHome?: string;
94
98
  }
95
99
  export declare function cycleIdForMaterial(materialId: string): string;
96
100
  export declare function cycleLockPathForMaterial(materialStorePath: string, materialId: string): string;