@neurcode-ai/cli 0.20.0 → 0.20.1

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 (50) hide show
  1. package/dist/commands/brain.d.ts.map +1 -1
  2. package/dist/commands/brain.js +63 -26
  3. package/dist/commands/brain.js.map +1 -1
  4. package/dist/commands/runtime-doctor.d.ts.map +1 -1
  5. package/dist/commands/runtime-doctor.js +17 -0
  6. package/dist/commands/runtime-doctor.js.map +1 -1
  7. package/dist/commands/session-hook.d.ts +16 -1
  8. package/dist/commands/session-hook.d.ts.map +1 -1
  9. package/dist/commands/session-hook.js +142 -10
  10. package/dist/commands/session-hook.js.map +1 -1
  11. package/dist/commands/session.d.ts +3 -1
  12. package/dist/commands/session.d.ts.map +1 -1
  13. package/dist/commands/session.js +5 -0
  14. package/dist/commands/session.js.map +1 -1
  15. package/dist/index.js +11 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/runtime-build.json +5 -5
  18. package/dist/utils/agent-session-launcher.d.ts.map +1 -1
  19. package/dist/utils/agent-session-launcher.js +142 -97
  20. package/dist/utils/agent-session-launcher.js.map +1 -1
  21. package/dist/utils/brain-lifecycle.d.ts +25 -6
  22. package/dist/utils/brain-lifecycle.d.ts.map +1 -1
  23. package/dist/utils/brain-lifecycle.js +305 -60
  24. package/dist/utils/brain-lifecycle.js.map +1 -1
  25. package/dist/utils/command-budget.d.ts +10 -0
  26. package/dist/utils/command-budget.d.ts.map +1 -0
  27. package/dist/utils/command-budget.js +203 -0
  28. package/dist/utils/command-budget.js.map +1 -0
  29. package/dist/utils/runtime-companion.d.ts +2 -0
  30. package/dist/utils/runtime-companion.d.ts.map +1 -1
  31. package/dist/utils/runtime-companion.js +3 -0
  32. package/dist/utils/runtime-companion.js.map +1 -1
  33. package/dist/utils/runtime-live.d.ts.map +1 -1
  34. package/dist/utils/runtime-live.js +14 -6
  35. package/dist/utils/runtime-live.js.map +1 -1
  36. package/dist/utils/runtime-outbox.d.ts.map +1 -1
  37. package/dist/utils/runtime-outbox.js +40 -0
  38. package/dist/utils/runtime-outbox.js.map +1 -1
  39. package/dist/utils/runtime-state.d.ts +7 -35
  40. package/dist/utils/runtime-state.d.ts.map +1 -1
  41. package/dist/utils/runtime-state.js +203 -134
  42. package/dist/utils/runtime-state.js.map +1 -1
  43. package/dist/utils/session-start-transaction.d.ts +31 -0
  44. package/dist/utils/session-start-transaction.d.ts.map +1 -0
  45. package/dist/utils/session-start-transaction.js +207 -0
  46. package/dist/utils/session-start-transaction.js.map +1 -0
  47. package/dist/utils/v0-governance.d.ts.map +1 -1
  48. package/dist/utils/v0-governance.js +81 -11
  49. package/dist/utils/v0-governance.js.map +1 -1
  50. package/package.json +4 -2
@@ -1 +1 @@
1
- {"version":3,"file":"brain.d.ts","sourceRoot":"","sources":["../../src/commands/brain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4gBpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA2iEnD"}
1
+ {"version":3,"file":"brain.d.ts","sourceRoot":"","sources":["../../src/commands/brain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAshBpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAglEnD"}
@@ -92,8 +92,13 @@ function safeFileSize(path) {
92
92
  function refreshActivatedProfileAfterBrain(repoRoot) {
93
93
  if (!(0, cli_runtime_1.readActivatedRuntimeManifest)(repoRoot))
94
94
  return;
95
- const profile = (0, v0_governance_1.buildCurrentGovernanceProfile)(repoRoot, { bypassCache: true });
96
- (0, cli_runtime_1.updateActivatedRuntimeManifestProfileHash)(repoRoot, profile.profileHash);
95
+ // Repository graph construction must not trigger a second whole-repository
96
+ // profile scan after the graph is already durable. Brain facts are consumed
97
+ // independently by runtime intelligence; preserve the activated profile until
98
+ // an explicit/profile-staleness refresh recomposes it.
99
+ const profile = (0, v0_governance_1.readGovernanceProfile)(repoRoot).profile;
100
+ if (profile)
101
+ (0, cli_runtime_1.updateActivatedRuntimeManifestProfileHash)(repoRoot, profile.profileHash);
97
102
  }
98
103
  function countOccurrences(haystack, needle) {
99
104
  if (!haystack || !needle)
@@ -321,9 +326,12 @@ function repositoryGraphError(error, json) {
321
326
  process.exitCode = payload.exitCode;
322
327
  }
323
328
  function printRepositoryGraphIndexResult(repoRoot, result, json) {
329
+ const graphPath = result.graph.storage.format === 'atomic_json'
330
+ ? (0, brain_1.legacyRepositoryGraphPath)(repoRoot)
331
+ : (0, brain_1.repositoryGraphPath)(repoRoot);
324
332
  const payload = {
325
333
  ok: true,
326
- graphPath: (0, brain_1.repositoryGraphPath)(repoRoot),
334
+ graphPath,
327
335
  schemaVersion: result.graph.schemaVersion,
328
336
  graphId: result.graph.graphId,
329
337
  generation: result.graph.generation,
@@ -734,26 +742,37 @@ function brainCommand(program) {
734
742
  .option('--json', 'Output stable machine-readable JSON')
735
743
  .action(async (options) => {
736
744
  const scope = getBrainScope();
745
+ let jobId;
737
746
  try {
738
- (0, brain_lifecycle_1.markBrainBuilding)(scope.cwd);
739
747
  const limits = {
740
748
  ...(Number.isFinite(options.maxFiles) ? { maxFiles: options.maxFiles } : {}),
741
749
  ...(Number.isFinite(options.maxTotalBytes) ? { maxTotalBytes: options.maxTotalBytes } : {}),
742
750
  ...(Number.isFinite(options.maxBytesPerFile) ? { maxBytesPerFile: options.maxBytesPerFile } : {}),
743
751
  };
752
+ const lifecycle = await (0, brain_lifecycle_1.beginBrainIndex)(scope.cwd, {
753
+ source: process.env.NEURCODE_BRAIN_INDEX_SOURCE === 'auto' ? 'auto' : 'manual',
754
+ requestedLimits: limits,
755
+ jobId: process.env.NEURCODE_BRAIN_JOB_ID,
756
+ });
757
+ jobId = lifecycle.jobId ?? undefined;
744
758
  const result = await (0, brain_1.indexRepositoryGraph)({
745
759
  repoRoot: scope.cwd,
746
760
  changedPaths: splitChangedPathList(options.changed),
747
761
  deletedPaths: splitChangedPathList(options.deleted),
748
762
  renamedPaths: parseRenameList(options.rename),
749
763
  limits,
764
+ onProgress: jobId
765
+ ? (progress) => { (0, brain_lifecycle_1.recordBrainProgress)(scope.cwd, jobId, progress); }
766
+ : undefined,
750
767
  });
751
- (0, brain_lifecycle_1.markBrainIndexResult)(scope.cwd, result);
768
+ (0, brain_lifecycle_1.markBrainIndexResult)(scope.cwd, result, jobId);
752
769
  refreshActivatedProfileAfterBrain(scope.cwd);
753
770
  printRepositoryGraphIndexResult(scope.cwd, result, options.json);
754
771
  }
755
772
  catch (error) {
756
- (0, brain_lifecycle_1.markBrainFailed)(scope.cwd, error instanceof brain_1.RepositoryGraphLockedError ? 'index_locked' : 'index_failed');
773
+ if (jobId) {
774
+ (0, brain_lifecycle_1.markBrainFailed)(scope.cwd, error instanceof brain_1.RepositoryGraphLockedError ? 'index_locked' : 'index_failed', jobId);
775
+ }
757
776
  repositoryGraphError(error, options.json);
758
777
  }
759
778
  });
@@ -766,18 +785,30 @@ function brainCommand(program) {
766
785
  .option('--json', 'Output stable machine-readable JSON')
767
786
  .action(async (options) => {
768
787
  const scope = getBrainScope();
788
+ let jobId;
769
789
  try {
790
+ const lifecycle = await (0, brain_lifecycle_1.beginBrainIndex)(scope.cwd, {
791
+ source: 'manual',
792
+ requestedLimits: {},
793
+ });
794
+ jobId = lifecycle.jobId ?? undefined;
770
795
  const result = await (0, brain_1.indexRepositoryGraph)({
771
796
  repoRoot: scope.cwd,
772
797
  changedPaths: splitChangedPathList(options.changed),
773
798
  deletedPaths: splitChangedPathList(options.deleted),
774
799
  renamedPaths: parseRenameList(options.rename),
800
+ onProgress: jobId
801
+ ? (progress) => { (0, brain_lifecycle_1.recordBrainProgress)(scope.cwd, jobId, progress); }
802
+ : undefined,
775
803
  });
776
- (0, brain_lifecycle_1.markBrainIndexResult)(scope.cwd, result);
804
+ (0, brain_lifecycle_1.markBrainIndexResult)(scope.cwd, result, jobId);
777
805
  refreshActivatedProfileAfterBrain(scope.cwd);
778
806
  printRepositoryGraphIndexResult(scope.cwd, result, options.json);
779
807
  }
780
808
  catch (error) {
809
+ if (jobId) {
810
+ (0, brain_lifecycle_1.markBrainFailed)(scope.cwd, error instanceof brain_1.RepositoryGraphLockedError ? 'index_locked' : 'index_failed', jobId);
811
+ }
781
812
  repositoryGraphError(error, options.json);
782
813
  }
783
814
  });
@@ -789,21 +820,24 @@ function brainCommand(program) {
789
820
  const scope = getBrainScope();
790
821
  try {
791
822
  const freshness = await (0, brain_1.repositoryGraphStatus)(scope.cwd);
792
- const graph = (0, brain_1.readRepositoryGraph)(scope.cwd);
823
+ const metadata = (0, brain_1.readRepositoryGraphMetadata)(scope.cwd);
793
824
  const payload = {
794
825
  ok: freshness.state !== 'corrupt',
795
826
  repoRoot: scope.cwd,
796
- graphPath: (0, brain_1.repositoryGraphPath)(scope.cwd),
827
+ graphPath: metadata?.storageFormat === 'atomic_json'
828
+ ? (0, brain_1.legacyRepositoryGraphPath)(scope.cwd)
829
+ : (0, brain_1.repositoryGraphPath)(scope.cwd),
797
830
  freshness,
798
- graph: graph ? {
799
- schemaVersion: graph.schemaVersion,
800
- graphId: graph.graphId,
801
- generation: graph.generation,
802
- updatedAt: graph.updatedAt,
803
- coverage: graph.coverage,
804
- nodeCount: graph.nodes.length,
805
- edgeCount: graph.edges.length,
806
- privacy: graph.privacy,
831
+ graph: metadata ? {
832
+ schemaVersion: metadata.schemaVersion,
833
+ graphId: metadata.graphId,
834
+ generation: metadata.generation,
835
+ updatedAt: metadata.updatedAt,
836
+ coverage: metadata.coverage,
837
+ nodeCount: metadata.nodeCount,
838
+ edgeCount: metadata.edgeCount,
839
+ graphBytes: metadata.graphBytes,
840
+ storageFormat: metadata.storageFormat,
807
841
  } : null,
808
842
  };
809
843
  if (options.json) {
@@ -816,11 +850,12 @@ function brainCommand(program) {
816
850
  console.log(chalk.dim(`Stale files: ${freshness.staleFileCount}`));
817
851
  console.log(chalk.dim(`Unsupported files: ${freshness.unsupportedFileCount}`));
818
852
  console.log(chalk.dim(`Reason codes: ${freshness.reasonCodes.join(', ') || 'none'}`));
819
- if (graph) {
820
- console.log(chalk.dim(`Generation: ${graph.generation}`));
821
- console.log(chalk.dim(`Nodes / edges: ${graph.nodes.length} / ${graph.edges.length}`));
822
- console.log(chalk.dim(`Unsupported: ${graph.coverage.unsupportedPercent}%`));
823
- for (const language of graph.coverage.languages) {
853
+ if (metadata) {
854
+ console.log(chalk.dim(`Generation: ${metadata.generation}`));
855
+ console.log(chalk.dim(`Nodes / edges: ${metadata.nodeCount} / ${metadata.edgeCount}`));
856
+ console.log(chalk.dim(`Graph bytes: ${metadata.graphBytes}`));
857
+ console.log(chalk.dim(`Unsupported: ${metadata.coverage.unsupportedPercent}%`));
858
+ for (const language of metadata.coverage.languages) {
824
859
  console.log(chalk.dim(` ${language.language}: ${language.depth}; ${language.filesAnalyzed}/${language.filesSeen} analyzed`));
825
860
  }
826
861
  }
@@ -845,7 +880,9 @@ function brainCommand(program) {
845
880
  }
846
881
  console.log(chalk.bold('\n🧠 Repo Brain Lifecycle\n'));
847
882
  console.log(chalk.dim(`State: ${lifecycle.state}`));
848
- console.log(chalk.dim(`Progress: ${lifecycle.progress.filesIndexed}/${lifecycle.progress.totalFiles ?? '?'} files${lifecycle.progress.percent === null ? '' : ` (${lifecycle.progress.percent}%)`}`));
883
+ console.log(chalk.dim(`Job: ${lifecycle.jobId ?? 'none'} · ${lifecycle.source ?? 'not running'} · pid ${lifecycle.pid ?? 'none'}`));
884
+ console.log(chalk.dim(`Progress: ${lifecycle.progress.filesIndexed}/${lifecycle.progress.totalFiles ?? '?'} files${lifecycle.progress.percent === null ? '' : ` (${lifecycle.progress.percent}%)`} · ${lifecycle.progress.bytesScanned} bytes · ${lifecycle.progress.nodes}/${lifecycle.progress.edges} nodes/edges`));
885
+ console.log(chalk.dim(`Elapsed/RSS: ${lifecycle.elapsedMs ?? 'n/a'} ms · ${lifecycle.peakRssMb ?? 'unavailable'} MB (${lifecycle.peakRssMeasurement})`));
849
886
  console.log(chalk.dim(`Freshness: ${lifecycle.freshness?.state ?? 'not evaluated'}`));
850
887
  console.log(chalk.dim(`Unsupported: ${lifecycle.unsupportedFacts.join(', ') || 'none disclosed'}`));
851
888
  console.log(chalk.dim(`Retry: ${lifecycle.recoveryCommands.retry}`));
@@ -857,9 +894,9 @@ function brainCommand(program) {
857
894
  .command('cancel')
858
895
  .description('Cancel a scheduled or building Repo Brain index without deleting the last usable graph')
859
896
  .option('--json', 'Output stable source-free JSON')
860
- .action((options) => {
897
+ .action(async (options) => {
861
898
  const scope = getBrainScope();
862
- const lifecycle = (0, brain_lifecycle_1.cancelBrainIndex)(scope.cwd);
899
+ const lifecycle = await (0, brain_lifecycle_1.cancelBrainIndex)(scope.cwd);
863
900
  if (options.json)
864
901
  console.log(JSON.stringify({ ok: true, lifecycle }, null, 2));
865
902
  else