@gajae-code/coding-agent 0.18.5 → 0.18.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.
Files changed (133) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/dist/types/capability/types.d.ts +4 -0
  3. package/dist/types/cli-commands.d.ts +10 -0
  4. package/dist/types/cli-ordinary.d.ts +13 -0
  5. package/dist/types/cli.d.ts +12 -3
  6. package/dist/types/commands/contribution-prep.d.ts +0 -3
  7. package/dist/types/commands/sdk.d.ts +3 -0
  8. package/dist/types/commands/update.d.ts +1 -0
  9. package/dist/types/config/model-profile-activation.d.ts +19 -0
  10. package/dist/types/config/settings.d.ts +4 -0
  11. package/dist/types/coordinator-mcp/session-reaper.d.ts +5 -0
  12. package/dist/types/discovery/helpers.d.ts +2 -2
  13. package/dist/types/edit/modes/replace.d.ts +3 -3
  14. package/dist/types/edit/streaming.d.ts +2 -2
  15. package/dist/types/exec/bash-shell-supervisor.d.ts +12 -0
  16. package/dist/types/runtime-mcp/elicitation.d.ts +12 -0
  17. package/dist/types/sdk/broker/discovery.d.ts +8 -0
  18. package/dist/types/sdk/broker/ensure.d.ts +1 -0
  19. package/dist/types/sdk/broker/lifecycle-ledger.d.ts +4 -0
  20. package/dist/types/sdk/broker/lifecycle.d.ts +9 -0
  21. package/dist/types/sdk/broker/runtime.d.ts +1 -1
  22. package/dist/types/sdk/broker/task-artifact-owner-validation.d.ts +55 -0
  23. package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +1 -1
  24. package/dist/types/sdk/bus/telegram-daemon.d.ts +4 -2
  25. package/dist/types/sdk/cli/diagnostics-cli.d.ts +18 -0
  26. package/dist/types/sdk/diagnostics/observe-broker.d.ts +185 -0
  27. package/dist/types/sdk/host/control/operations.d.ts +1 -1
  28. package/dist/types/sdk/host/host.d.ts +6 -0
  29. package/dist/types/sdk/index.d.ts +1 -0
  30. package/dist/types/sdk/router/session-router.d.ts +9 -0
  31. package/dist/types/sdk/session.d.ts +13 -0
  32. package/dist/types/session/agent-session.d.ts +5 -1
  33. package/dist/types/session/internal/managed-session-storage.d.ts +11 -1
  34. package/dist/types/session/internal/task-artifact-owner-access.d.ts +17 -0
  35. package/dist/types/session/internal/task-artifact-owner-transcript.d.ts +3 -0
  36. package/dist/types/session/session-retirement.d.ts +47 -0
  37. package/dist/types/session/session-storage.d.ts +0 -46
  38. package/dist/types/session/session-transcript-header.d.ts +2 -0
  39. package/dist/types/session/task-artifact-owner-codec.d.ts +107 -0
  40. package/dist/types/session/task-artifact-owner-retirement.d.ts +7 -0
  41. package/dist/types/session/task-artifact-owner.d.ts +10 -0
  42. package/dist/types/tools/ask-contract.d.ts +75 -254
  43. package/dist/types/tools/bash.d.ts +1 -1
  44. package/package.json +7 -7
  45. package/scripts/build-sdk-package-smoke.ts +5 -0
  46. package/scripts/resident-memory-bench.ts +174 -20
  47. package/src/capability/index.ts +1 -0
  48. package/src/capability/types.ts +4 -0
  49. package/src/cli/config-cli.ts +8 -18
  50. package/src/cli/public-command-entry.ts +5 -0
  51. package/src/cli/ssh-cli.ts +6 -3
  52. package/src/cli/web-search-cli.ts +9 -3
  53. package/src/cli-commands.ts +14 -0
  54. package/src/cli-main.ts +7 -8
  55. package/src/cli-ordinary.ts +197 -0
  56. package/src/cli.ts +25 -182
  57. package/src/commands/contribution-prep.ts +1 -3
  58. package/src/commands/sdk.ts +171 -21
  59. package/src/commands/update.ts +15 -1
  60. package/src/config/file-lock.ts +91 -2
  61. package/src/config/model-profile-activation.ts +70 -4
  62. package/src/config/model-profile-contract.ts +4 -1
  63. package/src/config/model-profiles.ts +23 -31
  64. package/src/config/model-resolver.ts +9 -1
  65. package/src/config/settings.ts +44 -4
  66. package/src/coordinator-mcp/event-webhook.ts +19 -14
  67. package/src/coordinator-mcp/policy.ts +14 -4
  68. package/src/coordinator-mcp/server.ts +142 -7
  69. package/src/coordinator-mcp/session-reaper.ts +9 -1
  70. package/src/defaults/gjc/skills/deep-interview/SKILL.md +1 -1
  71. package/src/discovery/helpers.ts +9 -3
  72. package/src/discovery/ssh.ts +8 -3
  73. package/src/edit/modes/replace.ts +6 -6
  74. package/src/edit/streaming.ts +15 -15
  75. package/src/exec/bash-shell-supervisor.ts +60 -3
  76. package/src/gjc-runtime/gc-runtime.ts +2 -1
  77. package/src/hindsight/config.ts +9 -3
  78. package/src/internal-urls/docs-index.generated.ts +11 -10
  79. package/src/memories/index.ts +8 -2
  80. package/src/modes/acp/acp-agent.ts +724 -370
  81. package/src/modes/components/tool-execution.ts +1 -1
  82. package/src/prompts/tools/ask.md +2 -0
  83. package/src/runtime-mcp/client.ts +13 -4
  84. package/src/runtime-mcp/elicitation.ts +142 -0
  85. package/src/sdk/broker/broker.ts +54 -1
  86. package/src/sdk/broker/daemon-entry.ts +67 -6
  87. package/src/sdk/broker/discovery.ts +8 -0
  88. package/src/sdk/broker/ensure.ts +156 -20
  89. package/src/sdk/broker/lifecycle-ledger.ts +110 -12
  90. package/src/sdk/broker/lifecycle.ts +334 -348
  91. package/src/sdk/broker/runtime.ts +5 -1
  92. package/src/sdk/broker/task-artifact-owner-validation.ts +259 -0
  93. package/src/sdk/broker/transport.ts +5 -1
  94. package/src/sdk/bus/chat-daemon-control.ts +2 -2
  95. package/src/sdk/bus/chat-daemon-runtime.ts +3 -0
  96. package/src/sdk/bus/index.ts +3 -3
  97. package/src/sdk/bus/telegram-daemon-contract.ts +1 -1
  98. package/src/sdk/bus/telegram-daemon-control.ts +15 -12
  99. package/src/sdk/bus/telegram-daemon.ts +38 -3
  100. package/src/sdk/cli/diagnostics-cli.ts +247 -0
  101. package/src/sdk/diagnostics/observe-broker.ts +654 -0
  102. package/src/sdk/host/control/dispatch.ts +52 -4
  103. package/src/sdk/host/control/operations.ts +1 -1
  104. package/src/sdk/host/host.ts +6 -0
  105. package/src/sdk/host/session-runtime.test.ts +83 -4
  106. package/src/sdk/host/session-runtime.ts +15 -7
  107. package/src/sdk/index.ts +1 -0
  108. package/src/sdk/lifecycle-session.ts +1 -0
  109. package/src/sdk/mcp/server.ts +15 -3
  110. package/src/sdk/protocol/operation-registry.ts +1 -1
  111. package/src/sdk/router/session-router.ts +26 -3
  112. package/src/sdk/session.ts +51 -8
  113. package/src/session/agent-session.ts +169 -43
  114. package/src/session/blob-store.ts +78 -33
  115. package/src/session/internal/managed-session-storage.ts +203 -4
  116. package/src/session/internal/task-artifact-owner-access.ts +229 -0
  117. package/src/session/internal/task-artifact-owner-transcript.ts +68 -0
  118. package/src/session/session-retirement.ts +155 -0
  119. package/src/session/session-storage.ts +1 -160
  120. package/src/session/session-transcript-header.ts +17 -0
  121. package/src/session/task-artifact-owner-codec.ts +578 -0
  122. package/src/session/task-artifact-owner-retirement.ts +475 -0
  123. package/src/session/task-artifact-owner.ts +289 -0
  124. package/src/setup/hermes/templates/operator-instructions.v1.md +19 -1
  125. package/src/setup/hermes-setup.ts +4 -1
  126. package/src/slash-commands/builtin-registry.ts +8 -5
  127. package/src/tools/ask-contract.test.ts +76 -1
  128. package/src/tools/ask-contract.ts +57 -6
  129. package/src/tools/ask.ts +16 -7
  130. package/src/tools/bash.ts +38 -29
  131. package/src/tools/descriptors.test.ts +29 -0
  132. package/src/tools/tool-catalog.generated.ts +7 -4
  133. package/src/web/search/index.ts +2 -2
@@ -2,24 +2,25 @@
2
2
  * Pinned, child-isolated resident-cache benchmark.
3
3
  *
4
4
  * Each `--runs` repetition executes in a fresh Bun child. The default fixture is
5
- * 5,000 deterministic, unique 48 KiB messages; use the small overrides only for
6
- * local smoke checks, not performance comparisons.
5
+ * 500 deterministic, unique 48 KiB messages; it stays inside the product's
6
+ * eager-resume ceiling so a default run completes, and larger scales are explicit
7
+ * `--entries`/`--bytes-per-entry` overrides that fail closed above that ceiling.
7
8
  *
8
9
  * Normal measurements (five child runs per command):
9
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode rss --runs 5
10
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode put-latency --runs 5
11
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode read-churn --runs 5
10
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode rss --runs 5
11
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode put-latency --runs 5
12
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode read-churn --runs 5
12
13
  *
13
14
  * HEAD forced-rebuild baseline (copy this script to the pinned HEAD worktree):
14
15
  * git worktree add /tmp/gjc-bench-head 3649db42e
15
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode read-churn --baseline forced-rebuild --runs 5
16
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode read-churn --baseline forced-rebuild --runs 5
16
17
  *
17
18
  * Small smoke fixture and deliberate invalid-run demonstration:
18
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode rss --entries 8 --bytes-per-entry 4096 --runs 1
19
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode put-latency --puts 64 --runs 1
20
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode read-churn --entries 8 --bytes-per-entry 4096 --cache-cap-bytes 1024 --runs 1
21
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode read-churn --entries 8 --bytes-per-entry 4096 --cache-cap-bytes 1024 --skip-gc --runs 1
22
- * TMPDIR="$HOME/tmp-gjc-tests/" GJC_CODING_AGENT_DIR="$(mktemp -d)" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode rss --force-memory-only --runs 1
19
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode rss --entries 8 --bytes-per-entry 4096 --runs 1
20
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode put-latency --puts 64 --runs 1
21
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode read-churn --entries 8 --bytes-per-entry 4096 --cache-cap-bytes 1024 --runs 1
22
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode read-churn --entries 8 --bytes-per-entry 4096 --cache-cap-bytes 1024 --skip-gc --runs 1
23
+ * TMPDIR="$HOME/tmp-gjc-tests/" NO_COLOR=1 bun packages/coding-agent/scripts/resident-memory-bench.ts --mode rss --force-memory-only --runs 1
23
24
  *
24
25
  * `--skip-gc` deliberately bypasses the required turn boundary and forced GC;
25
26
  * the --skip-gc command must exit non-zero with the invalid-run diagnostic. Do not
@@ -28,9 +29,17 @@
28
29
  * exercise the existing fallback and is not a supported product configuration.
29
30
  * RSS mode reports append-phase and fresh-process reopen measurements with the full
30
31
  * `process.memoryUsage()` breakdown, plus repeated forced-GC idle-turn reclaim samples.
31
- * AC-1 passes only when append steady-state RSS delta stays within 100 MiB; a
32
- * post-reclaim result within that limit is separately labeled documented evidence. AC-2
33
- * measures direct `putSync` calls over pre-generated unique Buffers into a
32
+ * AC-1 passes only when all three ceilings hold: the append steady-state RSS delta stays
33
+ * within 100 MiB; the read-path residual (post-read forced-GC delta) stays within
34
+ * max(READ_PATH_RESIDUAL_FLOOR_BYTES, READ_PATH_RESIDUAL_TRANSCRIPT_RATIO_LIMIT x the
35
+ * fixture's persisted transcript); and the reclaim contract holds
36
+ * (RECLAIM_ALLOCATOR_FLOOR_BYTES, post-reclaim delta inside the append limit). A reclaim
37
+ * proof only excuses a steady-state miss: the read-path ceiling and the reclaim contract
38
+ * are hard gates, so a failed read path exits non-zero instead of being relabeled
39
+ * documented evidence. The harness always runs against its own throwaway agent dir, so
40
+ * nothing has to be pre-set, an ambient `GJC_CODING_AGENT_DIR` is ignored, and the
41
+ * operator's `~/.gjc` is never read; `GJC_RESIDENT_MEMORY_BENCH_AGENT_DIR` pins it.
42
+ * AC-2 measures direct `putSync` calls over pre-generated unique Buffers into a
34
43
  * canonical MemoryBlobStore and an adopted verified EphemeralBlobStore.
35
44
  * SessionManager append figures are separate `e2eAppend` diagnostics. A direct
36
45
  * store ratio above 1.5x is documented evidence, not a relaxation of the
@@ -43,6 +52,7 @@ import { createRequire, syncBuiltinESMExports } from "node:module";
43
52
  import * as os from "node:os";
44
53
  import * as path from "node:path";
45
54
  import { EphemeralBlobStore, MemoryBlobStore, openVerifiedResidentCacheInstanceDir } from "../src/session/blob-store";
55
+ import { MANAGED_ARTIFACT_MAX_FILE_BYTES } from "../src/session/internal/managed-session-storage";
46
56
  import type {
47
57
  SessionManagerObservabilityStats,
48
58
  SessionManager as SessionManagerType,
@@ -54,14 +64,50 @@ const { SessionManager } = sessionManagerModule;
54
64
  const SCHEMA_VERSION = 4;
55
65
  const SYNTHETIC_SEED = 0x5eedc0de;
56
66
  const DEFAULT_RUNS = 5;
57
- const RSS_ENTRY_COUNT = 5_000;
67
+ /**
68
+ * Default fixture. It has to stay inside the eager-resume ceiling, and at the default
69
+ * scale the append steady state has to stay inside AC-1: the previous 5_000 x 48 KiB
70
+ * default persisted about 234 MiB, so every default run died with the product's
71
+ * oversized-transcript recovery message before it could report anything. Larger scales
72
+ * are explicit opt-in through `--entries`/`--bytes-per-entry`, bounded by
73
+ * `assertFixtureWithinEagerResumeCeiling`.
74
+ */
75
+ const RSS_ENTRY_COUNT = 500;
58
76
  const RSS_BYTES_PER_ENTRY = 48 * 1024;
77
+ /**
78
+ * The eager-resume ceiling the product enforces, imported rather than copied so a
79
+ * product-side change is reflected here instead of silently invalidating the fixture.
80
+ */
81
+ const EAGER_RESUME_TRANSCRIPT_CEILING_BYTES = MANAGED_ARTIFACT_MAX_FILE_BYTES;
82
+ /** Measured per-entry framing overhead of the persisted JSONL transcript. */
83
+ const SYNTHETIC_ENTRY_OVERHEAD_BYTES = 160;
59
84
  const READ_CHURN_CYCLES = 100;
60
85
  const PUT_WARMUP_ITERATIONS = 1_000;
61
86
  const PUT_MEASURE_ITERATIONS = 10_000;
62
87
  const PUT_BYTES = 4 * 1024;
63
88
  const BASELINE_MARKER_BYTES = 128;
64
89
  const AC1_APPEND_PHASE_RSS_LIMIT_BYTES = 100 * 1024 * 1024;
90
+ /**
91
+ * Read-path residual ceiling: after the read plus the forced-GC idle turns the append
92
+ * phase must not still hold more than `max(READ_PATH_RESIDUAL_FLOOR_BYTES, ratio x the
93
+ * fixture's persisted transcript)` above the pre-append baseline. Expressing the ceiling
94
+ * against the fixture keeps an `--entries` override from walking out from under it, and
95
+ * the absolute floor covers the part of the residual that does not scale with the
96
+ * fixture: on a tiny smoke fixture the forced-GC delta is a few MiB of ordinary runtime
97
+ * overhead, which a pure ratio would flag as a failure. AC-1 gates only the append steady
98
+ * state, so without this second ceiling a retention regression on the read path can keep
99
+ * a large block of RSS and still report pass. The current tree measures about 5x on the
100
+ * default fixture (about 121 MiB retained over a 24 MiB transcript).
101
+ */
102
+ const READ_PATH_RESIDUAL_TRANSCRIPT_RATIO_LIMIT = 8;
103
+ const READ_PATH_RESIDUAL_FLOOR_BYTES = 32 * 1024 * 1024;
104
+ /**
105
+ * Bun's allocator retains freed pages, so the forced-GC reclaim returns nothing on this
106
+ * runtime. The floor is an explicit contract instead of an unexplained zero: the reclaim
107
+ * must never increase RSS, and the post-reclaim delta must stay inside the append limit,
108
+ * or the run fails closed.
109
+ */
110
+ const RECLAIM_ALLOCATOR_FLOOR_BYTES = 0;
65
111
  const MEMORY_RECLAIM_GC_ROUNDS = 4;
66
112
  const SYNTHETIC_TEXT_PATTERN =
67
113
  "gjc-resident-cache-fixture-abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789";
@@ -353,11 +399,34 @@ function parseArgs(argv: string[]): CliArgs {
353
399
  }
354
400
 
355
401
  function fixtureFor(args: CliArgs): FixtureDimensions {
356
- return {
402
+ const fixture: FixtureDimensions = {
357
403
  seed: SYNTHETIC_SEED,
358
404
  entries: args.entries ?? RSS_ENTRY_COUNT,
359
405
  bytesPerEntry: args.bytesPerEntry ?? RSS_BYTES_PER_ENTRY,
360
406
  };
407
+ assertFixtureWithinEagerResumeCeiling(fixture);
408
+ return fixture;
409
+ }
410
+
411
+ /**
412
+ * Fail closed before the run instead of dying inside the product: a fixture whose
413
+ * persisted transcript exceeds the eager-resume ceiling cannot be re-opened by the
414
+ * fresh-open phase, and the failure otherwise surfaces as the product's oversized-
415
+ * transcript recovery message with no hint that the fixture size is the cause.
416
+ */
417
+ /** Estimated persisted JSONL size of a fixture; the ceiling and read-path gates share it. */
418
+ function estimatedTranscriptBytes(fixture: FixtureDimensions): number {
419
+ return fixture.entries * (fixture.bytesPerEntry + SYNTHETIC_ENTRY_OVERHEAD_BYTES);
420
+ }
421
+
422
+ function assertFixtureWithinEagerResumeCeiling(fixture: FixtureDimensions): void {
423
+ const estimatedBytes = estimatedTranscriptBytes(fixture);
424
+ if (estimatedBytes <= EAGER_RESUME_TRANSCRIPT_CEILING_BYTES) return;
425
+ const estimatedMiB = Math.round(estimatedBytes / (1024 * 1024));
426
+ const ceilingMiB = Math.round(EAGER_RESUME_TRANSCRIPT_CEILING_BYTES / (1024 * 1024));
427
+ throw new Error(
428
+ `--entries/--bytes-per-entry would persist about ${estimatedMiB} MiB of transcript, above the ${ceilingMiB} MiB eager-resume ceiling; lower the fixture so the fresh-open phase can re-open it.`,
429
+ );
361
430
  }
362
431
 
363
432
  function fixtureForMode(args: CliArgs): FixtureDimensions {
@@ -539,6 +608,34 @@ async function withPersistentFixture<T>(
539
608
  }
540
609
  }
541
610
 
611
+ /**
612
+ * The harness runs against its own throwaway agent dir so it never reads or writes the
613
+ * operator's `~/.gjc` — an ambient `GJC_CODING_AGENT_DIR` (an agent session exports one)
614
+ * must not redirect a benchmark into live state, and the resident-cache poison that
615
+ * `--force-memory-only` relies on is only meaningful in a fresh directory anyway.
616
+ * `GJC_RESIDENT_MEMORY_BENCH_AGENT_DIR` is the explicit opt-in for pinning the directory.
617
+ */
618
+ let isolatedAgentDir: string | undefined;
619
+
620
+ async function ensureIsolatedAgentDir(): Promise<void> {
621
+ const pinned = process.env.GJC_RESIDENT_MEMORY_BENCH_AGENT_DIR;
622
+ if (pinned) {
623
+ process.env.GJC_CODING_AGENT_DIR = pinned;
624
+ process.env.PI_CODING_AGENT_DIR ??= pinned;
625
+ return;
626
+ }
627
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), "gjc-resident-memory-agent-"));
628
+ process.env.GJC_CODING_AGENT_DIR = dir;
629
+ process.env.PI_CODING_AGENT_DIR = dir;
630
+ isolatedAgentDir = dir;
631
+ }
632
+
633
+ async function cleanupIsolatedAgentDir(): Promise<void> {
634
+ const dir = isolatedAgentDir;
635
+ isolatedAgentDir = undefined;
636
+ if (dir) await fs.rm(dir, { recursive: true, force: true });
637
+ }
638
+
542
639
  async function forceResidentCacheMemoryFallback(): Promise<void> {
543
640
  const agentDir = process.env.GJC_CODING_AGENT_DIR;
544
641
  if (!agentDir) throw new Error("--force-memory-only requires GJC_CODING_AGENT_DIR to be set.");
@@ -590,7 +687,10 @@ async function settleAndForceGcTwice(): Promise<void> {
590
687
 
591
688
  /**
592
689
  * Let the collector and allocator reclaim after an idle turn without injecting a
593
- * larger temporary allocation that itself becomes an RSS high-water artifact.
690
+ * larger temporary allocation that itself becomes an RSS high-water artifact. The
691
+ * allocator retains the pages it already mapped, so this is expected to release
692
+ * `RECLAIM_ALLOCATOR_FLOOR_BYTES`; the AC-1 report gates that contract instead of
693
+ * printing a bare zero.
594
694
  */
595
695
  async function reclaimAfterMemoryPressure(): Promise<MemoryPressureReclaim> {
596
696
  for (let round = 0; round < MEMORY_RECLAIM_GC_ROUNDS; round++) {
@@ -635,6 +735,9 @@ async function runFreshOpenRss(args: CliArgs): Promise<FreshOpenRssWorkerResult>
635
735
  try {
636
736
  await settleFreshOpenRss();
637
737
  const baseline = memorySample();
738
+ // `fixtureFor` already proved the persisted transcript stays under the eager-resume
739
+ // ceiling, so this is the ordinary resume path the product takes for a session a
740
+ // user would actually reopen.
638
741
  manager = await SessionManager.open(sessionFile);
639
742
  const postOpen = memorySample();
640
743
  const diskBytes = await residentCacheDiskBytes();
@@ -1113,11 +1216,24 @@ function summarizeAc1(runs: readonly RssWorkerResult[]): {
1113
1216
  postReclaimRssDelta: number;
1114
1217
  classification: "documented-evidence";
1115
1218
  };
1219
+ readPathResidual: {
1220
+ postReadGcRssDelta: number;
1221
+ limitBytes: number;
1222
+ floorBytes: number;
1223
+ ratioLimit: number;
1224
+ passes: boolean;
1225
+ };
1226
+ reclaimFloor: {
1227
+ allocatorFloorBytes: number;
1228
+ postReclaimWithinLimit: boolean;
1229
+ passes: boolean;
1230
+ };
1116
1231
  verdict: "pass" | "documented-evidence-with-reclaim-proof" | "fail";
1117
1232
  } {
1118
1233
  const appendSteadyDelta = summarize(runs.map(run => run.appendPhase.steadyStateDelta.rssBytes));
1119
1234
  const postReclaimDelta = summarize(runs.map(run => run.appendPhase.postReclaimDelta.rssBytes));
1120
1235
  const reclaimedBytes = summarize(runs.map(run => run.appendPhase.reclaimedBytes));
1236
+ const readPathResidualDelta = summarize(runs.map(run => run.appendPhase.postReadGcDelta.rssBytes));
1121
1237
  const steadyStateExternal = summarize(runs.map(run => run.appendPhase.steadyState.externalBytes));
1122
1238
  const postReclaimExternal = summarize(runs.map(run => run.appendPhase.postReclaim.externalBytes));
1123
1239
  const postReclaimExternalDelta = summarize(runs.map(run => run.appendPhase.postReclaimDelta.externalBytes));
@@ -1127,7 +1243,19 @@ function summarizeAc1(runs: readonly RssWorkerResult[]): {
1127
1243
  const freshOpenRssDelta = summarize(runs.map(run => run.freshOpenPhase.steadyStateDelta.rssBytes));
1128
1244
  const freshOpenPostReclaimRssDelta = summarize(runs.map(run => run.freshOpenPhase.postReclaimDelta.rssBytes));
1129
1245
  const passesSteadyStateGate = appendSteadyDelta.median <= AC1_APPEND_PHASE_RSS_LIMIT_BYTES;
1130
- const hasReclaimProof = postReclaimDelta.median <= AC1_APPEND_PHASE_RSS_LIMIT_BYTES && reclaimedBytes.median > 0;
1246
+ const readPathResidualLimitBytes = Math.max(
1247
+ READ_PATH_RESIDUAL_FLOOR_BYTES,
1248
+ estimatedTranscriptBytes(runs[0]?.fixture ?? { seed: SYNTHETIC_SEED, entries: 0, bytesPerEntry: 0 }) *
1249
+ READ_PATH_RESIDUAL_TRANSCRIPT_RATIO_LIMIT,
1250
+ );
1251
+ const passesReadPathGate = readPathResidualDelta.median <= readPathResidualLimitBytes;
1252
+ const postReclaimWithinLimit = postReclaimDelta.median <= AC1_APPEND_PHASE_RSS_LIMIT_BYTES;
1253
+ const passesReclaimFloorGate = reclaimedBytes.median >= RECLAIM_ALLOCATOR_FLOOR_BYTES && postReclaimWithinLimit;
1254
+ const hasReclaimProof = postReclaimWithinLimit && reclaimedBytes.median > 0;
1255
+ // The reclaim proof excuses the steady-state ceiling only. The read-path ceiling and
1256
+ // the reclaim contract are hard gates, so a proof must not relabel a failed read path
1257
+ // as documented evidence and let the process exit zero.
1258
+ const reclaimProofExcusesOnlySteadyState = hasReclaimProof && passesReadPathGate && passesReclaimFloorGate;
1131
1259
  return {
1132
1260
  appendSteadyDelta: appendSteadyDelta.median,
1133
1261
  postReclaimDelta: postReclaimDelta.median,
@@ -1147,7 +1275,24 @@ function summarizeAc1(runs: readonly RssWorkerResult[]): {
1147
1275
  postReclaimRssDelta: freshOpenPostReclaimRssDelta.median,
1148
1276
  classification: "documented-evidence",
1149
1277
  },
1150
- verdict: passesSteadyStateGate ? "pass" : hasReclaimProof ? "documented-evidence-with-reclaim-proof" : "fail",
1278
+ readPathResidual: {
1279
+ postReadGcRssDelta: readPathResidualDelta.median,
1280
+ limitBytes: readPathResidualLimitBytes,
1281
+ floorBytes: READ_PATH_RESIDUAL_FLOOR_BYTES,
1282
+ ratioLimit: READ_PATH_RESIDUAL_TRANSCRIPT_RATIO_LIMIT,
1283
+ passes: passesReadPathGate,
1284
+ },
1285
+ reclaimFloor: {
1286
+ allocatorFloorBytes: RECLAIM_ALLOCATOR_FLOOR_BYTES,
1287
+ postReclaimWithinLimit,
1288
+ passes: passesReclaimFloorGate,
1289
+ },
1290
+ verdict:
1291
+ passesSteadyStateGate && passesReadPathGate && passesReclaimFloorGate
1292
+ ? "pass"
1293
+ : reclaimProofExcusesOnlySteadyState
1294
+ ? "documented-evidence-with-reclaim-proof"
1295
+ : "fail",
1151
1296
  };
1152
1297
  }
1153
1298
 
@@ -1323,6 +1468,10 @@ async function runParent(args: CliArgs): Promise<void> {
1323
1468
  runResults: runs,
1324
1469
  };
1325
1470
  process.stdout.write(`${JSON.stringify(output)}\n`);
1471
+ // A failed RSS acceptance verdict has to fail the process, otherwise the declared
1472
+ // ceilings are only advisory and nothing downstream can gate on them.
1473
+ if (args.mode === "rss" && (acceptanceReport as { ac1: { verdict: string } }).ac1.verdict === "fail")
1474
+ process.exitCode = 1;
1326
1475
  }
1327
1476
 
1328
1477
  async function main(): Promise<void> {
@@ -1332,7 +1481,12 @@ async function main(): Promise<void> {
1332
1481
  process.stdout.write(`${JSON.stringify(result)}\n`);
1333
1482
  return;
1334
1483
  }
1335
- await runParent(args);
1484
+ await ensureIsolatedAgentDir();
1485
+ try {
1486
+ await runParent(args);
1487
+ } finally {
1488
+ await cleanupIsolatedAgentDir();
1489
+ }
1336
1490
  }
1337
1491
 
1338
1492
  await main().catch(error => {
@@ -429,6 +429,7 @@ export async function loadCapability<T>(capabilityId: string, options: LoadOptio
429
429
  repoRoot,
430
430
  isolatedHome: false,
431
431
  settings: ordinaryOptions.settings,
432
+ bypassCache: ordinaryOptions.bypassCache,
432
433
  };
433
434
  const providers = filterProviders(capability, ordinaryOptions);
434
435
 
@@ -40,6 +40,8 @@ export interface LoadContext {
40
40
  repoRoot: string | null;
41
41
  /** Whether discovery must remain isolated to the supplied home boundary. */
42
42
  isolatedHome?: boolean;
43
+ /** Bypass lexical filesystem caches for this discovery operation. */
44
+ bypassCache?: boolean;
43
45
  /** Owning session settings for provider policy decisions. */
44
46
  settings?: Settings;
45
47
  }
@@ -112,6 +114,8 @@ export interface LoadOptions {
112
114
  includeDisabledProviders?: boolean;
113
115
  /** Explicit disabled extension IDs to apply instead of settings. */
114
116
  disabledExtensions?: string[];
117
+ /** Bypass lexical filesystem caches for this discovery operation. */
118
+ bypassCache?: boolean;
115
119
  /** Session settings whose provider policy applies to this load. */
116
120
  settings?: Settings;
117
121
  /** Internal: prevent explicit-home loads from consulting process-global policy. */
@@ -63,29 +63,19 @@ type CliSettingDef = {
63
63
  const ALL_SETTING_PATHS = Object.keys(SETTINGS_SCHEMA) as SettingPath[];
64
64
  const REDACTED_SECRET_VALUE = "<redacted>";
65
65
  const SECRET_SETTING_WORDS = new Set(["token", "secret", "password", "passwd", "pwd", "credential", "credentials"]);
66
- const SECRET_SETTING_COMPOUND_PREFIXES = [
67
- "api",
68
- "auth",
69
- "access",
70
- "refresh",
71
- "bearer",
72
- "session",
73
- "client",
74
- "broker",
75
- "bot",
76
- "basic",
77
- ];
78
- const SECRET_SETTING_COMPOUND_SUFFIXES = ["token", "secret", "password", "credential"];
66
+ /**
67
+ * camelCase segments (`appToken`, `basicPassword`) do not split on `-`/`_`, so any segment whose
68
+ * normalized form ends in a secret word is secret. Plural budget names (`maxTokens`) and words that
69
+ * merely contain one (`showTokenUsage`) stay visible.
70
+ */
71
+ const SECRET_SETTING_SUFFIX = /(?:token|secret|password|passwd|pwd|credentials?)$/;
79
72
 
80
73
  function isSecretSettingSegment(segment: string): boolean {
81
74
  const normalized = segment.toLowerCase();
82
- if (SECRET_SETTING_WORDS.has(normalized)) return true;
75
+ if (SECRET_SETTING_SUFFIX.test(normalized)) return true;
83
76
  if (/api[-_]?key/i.test(segment)) return true;
84
77
  const words = normalized.split(/[-_]/).filter(Boolean);
85
- if (words.some(word => SECRET_SETTING_WORDS.has(word))) return true;
86
- return SECRET_SETTING_COMPOUND_PREFIXES.some(prefix =>
87
- SECRET_SETTING_COMPOUND_SUFFIXES.some(suffix => normalized === `${prefix}${suffix}`),
88
- );
78
+ return words.some(word => SECRET_SETTING_WORDS.has(word));
89
79
  }
90
80
 
91
81
  function isSecretSettingPath(path: string): boolean {
@@ -288,6 +288,11 @@ export function isSdkInternalArgv(argv: readonly string[]): boolean {
288
288
  return (
289
289
  (argv[0] === "session-host-internal" && argv.length === 1) ||
290
290
  (argv[0] === "broker-internal" &&
291
+ argv.length === 3 &&
292
+ argv[1] === "--agent-dir" &&
293
+ typeof argv[2] === "string" &&
294
+ isSafeSdkInternalAgentDir(argv[2])) ||
295
+ (argv[0] === "broker-trampoline-internal" &&
291
296
  argv.length === 3 &&
292
297
  argv[1] === "--agent-dir" &&
293
298
  typeof argv[2] === "string" &&
@@ -74,9 +74,12 @@ async function handleAdd(cmd: SSHCommandArgs): Promise<void> {
74
74
  return;
75
75
  }
76
76
 
77
- // Validate port if provided
77
+ // Validate port if provided. `Number.parseInt` accepts trailing garbage
78
+ // (parseInt("22oops") === 22, parseInt("2222.5") === 2222), so require
79
+ // the whole token to be digits before parsing.
80
+ let port: number | undefined;
78
81
  if (cmd.flags.port !== undefined) {
79
- const port = Number.parseInt(cmd.flags.port, 10);
82
+ port = /^\d+$/.test(cmd.flags.port) ? Number.parseInt(cmd.flags.port, 10) : Number.NaN;
80
83
  if (Number.isNaN(port) || port < 1 || port > 65535) {
81
84
  process.stdout.write(chalk.red("Error: Port must be an integer between 1 and 65535\n"));
82
85
  process.exitCode = 1;
@@ -86,7 +89,7 @@ async function handleAdd(cmd: SSHCommandArgs): Promise<void> {
86
89
 
87
90
  const hostConfig: SSHHostConfig = { host };
88
91
  if (cmd.flags.user) hostConfig.username = cmd.flags.user;
89
- if (cmd.flags.port) hostConfig.port = Number.parseInt(cmd.flags.port, 10);
92
+ if (port !== undefined) hostConfig.port = port;
90
93
  if (cmd.flags.key) hostConfig.keyPath = cmd.flags.key;
91
94
  if (cmd.flags.desc) hostConfig.description = cmd.flags.desc;
92
95
  if (cmd.flags.compat) hostConfig.compat = true;
@@ -95,7 +95,10 @@ export function parseSearchArgs(args: string[]): SearchCommandArgs | undefined {
95
95
  result.recency = value() as SearchCommandArgs["recency"];
96
96
  consumeSeparateValue();
97
97
  } else if (arg === "--limit" || arg === "-l") {
98
- result.limit = Number.parseInt(value(), 10);
98
+ const raw = value();
99
+ // `Number.parseInt` accepts trailing garbage ("5x" -> 5); leave
100
+ // anything that is not plain digits as NaN so it is rejected below.
101
+ result.limit = /^\d+$/.test(raw) ? Number.parseInt(raw, 10) : Number.NaN;
99
102
  consumeSeparateValue();
100
103
  } else if (arg === "--xai-mode") {
101
104
  result.xaiSearchMode = value() as SearchCommandArgs["xaiSearchMode"];
@@ -164,8 +167,11 @@ export async function runSearchCommand(cmd: SearchCommandArgs): Promise<void> {
164
167
  process.exit(1);
165
168
  }
166
169
 
167
- if (cmd.limit !== undefined && Number.isNaN(cmd.limit)) {
168
- process.stderr.write(`${chalk.red("Error: --limit must be a number")}\n`);
170
+ // `Flags.integer` accepts `0` and negative values; providers forward them
171
+ // as `num_results` and several slice sources with them (`slice(0, -3)`
172
+ // silently drops the last three results).
173
+ if (cmd.limit !== undefined && (!Number.isSafeInteger(cmd.limit) || cmd.limit < 1)) {
174
+ process.stderr.write(`${chalk.red("Error: --limit must be a positive integer")}\n`);
169
175
  process.exit(1);
170
176
  }
171
177
 
@@ -0,0 +1,14 @@
1
+ import type { CommandEntry } from "@gajae-code/utils/cli";
2
+
3
+ /**
4
+ * Public-family hooks kept available for private-worker tests without loading the
5
+ * full registry.
6
+ *
7
+ * This is the single shared array: the inert entry (`cli.ts`) and the ordinary
8
+ * dispatcher (`cli-ordinary.ts`) both re-export THIS object, so a test that
9
+ * mutates or injects an entry keeps affecting the dispatcher.
10
+ */
11
+ export const commands: CommandEntry[] = [
12
+ { name: "sdk", load: () => import("./commands/sdk").then(module => module.default) },
13
+ { name: "daemon", load: () => import("./commands/daemon").then(module => module.default) },
14
+ ];
package/src/cli-main.ts CHANGED
@@ -8,19 +8,12 @@ import "@gajae-code/utils/postmortem";
8
8
  import { Args, type CliConfig, Command, type CommandEntry, run } from "@gajae-code/utils/cli";
9
9
  import { APP_NAME, formatBunRuntimeError, MIN_BUN_VERSION, VERSION } from "@gajae-code/utils/dirs";
10
10
  import { time } from "@gajae-code/utils/logger";
11
- import { runFixtureReport } from "./cli/fixture-report";
12
11
  import { ROOT_LAUNCH_FLAGS } from "./cli/root-flags";
13
- import QuickLane from "./commands/quick-lane";
14
- import { runBashShellGuardian } from "./exec/bash-shell-guardian";
15
- import { runBashShellSupervisor } from "./exec/bash-shell-supervisor";
16
- import { runBashShellWorker } from "./exec/bash-shell-worker";
17
12
  import {
18
13
  BASH_SHELL_RUNTIME_ARG,
19
14
  BASH_SHELL_SUPERVISOR_ARG,
20
15
  BASH_SHELL_WORKER_ARG,
21
16
  } from "./exec/bash-shell-worker-protocol";
22
- import { smokeTestIsolatedShell } from "./exec/isolated-shell";
23
- import { smokeTestTabWorker } from "./tools/browser/tab-worker-smoke";
24
17
 
25
18
  if (Bun.semver.order(Bun.version, MIN_BUN_VERSION) < 0) {
26
19
  process.stderr.write(
@@ -81,7 +74,7 @@ export const commands: CommandEntry[] = [
81
74
  { name: "plugin", load: () => import("./commands/plugin").then(m => m.default) },
82
75
  { name: "completion", load: () => import("./commands/completion").then(m => m.default) },
83
76
  { name: "launch", load: () => import("./commands/launch").then(m => m.default) },
84
- { name: "quick-lane", load: async () => QuickLane },
77
+ { name: "quick-lane", load: () => import("./commands/quick-lane").then(m => m.default) },
85
78
  ];
86
79
 
87
80
  async function showHelp(config: CliConfig): Promise<void> {
@@ -346,6 +339,8 @@ async function runSmokeTest(): Promise<void> {
346
339
  await smokeTestSyncWorker();
347
340
  const { runNativeSmokeTest } = await import("./cli/native-smoke");
348
341
  await runNativeSmokeTest();
342
+ const { smokeTestTabWorker } = await import("./tools/browser/tab-worker-smoke");
343
+ const { smokeTestIsolatedShell } = await import("./exec/isolated-shell");
349
344
  await smokeTestTabWorker();
350
345
  await smokeTestIsolatedShell();
351
346
  process.stdout.write("smoke-test: ok\n");
@@ -401,14 +396,17 @@ export function routeRootArgv(argv: readonly string[]): string[] {
401
396
  /** Run the CLI with the given argv (no `process.argv` prefix). */
402
397
  export async function runCliAfterAdmission(argv: string[]): Promise<void> {
403
398
  if (argv.length === 1 && argv[0] === BASH_SHELL_WORKER_ARG) {
399
+ const { runBashShellGuardian } = await import("./exec/bash-shell-guardian");
404
400
  await runBashShellGuardian();
405
401
  return;
406
402
  }
407
403
  if (argv.length === 1 && argv[0] === BASH_SHELL_SUPERVISOR_ARG) {
404
+ const { runBashShellSupervisor } = await import("./exec/bash-shell-supervisor");
408
405
  await runBashShellSupervisor();
409
406
  return;
410
407
  }
411
408
  if (argv.length === 1 && argv[0] === BASH_SHELL_RUNTIME_ARG) {
409
+ const { runBashShellWorker } = await import("./exec/bash-shell-worker");
412
410
  await runBashShellWorker();
413
411
  return;
414
412
  }
@@ -478,6 +476,7 @@ export async function runCliAfterAdmission(argv: string[]): Promise<void> {
478
476
  process.exitCode = 1;
479
477
  return;
480
478
  }
479
+ const { runFixtureReport } = await import("./cli/fixture-report");
481
480
  process.exitCode = await runFixtureReport(id);
482
481
  return;
483
482
  }