@gajae-code/coding-agent 0.18.8 → 0.18.9

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 (113) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/dist/types/async/endpoint-id.d.ts +16 -0
  3. package/dist/types/async/support.d.ts +0 -14
  4. package/dist/types/commands/mcp-serve.d.ts +4 -0
  5. package/dist/types/discovery/mcp-json.d.ts +1 -0
  6. package/dist/types/eval/py/kernel.d.ts +18 -0
  7. package/dist/types/export/html/html-export-destination.d.ts +2 -0
  8. package/dist/types/extensibility/extensions/function-hooks-internal.d.ts +5 -0
  9. package/dist/types/extensibility/skill-management.d.ts +1 -0
  10. package/dist/types/gjc-runtime/psmux-detect.d.ts +3 -3
  11. package/dist/types/gjc-runtime/sidecar-bootstrap-env.d.ts +6 -0
  12. package/dist/types/gjc-runtime/state-writer.d.ts +3 -0
  13. package/dist/types/gjc-runtime/tmux-common.d.ts +8 -5
  14. package/dist/types/lsp/config.d.ts +8 -5
  15. package/dist/types/runtime-mcp/manager.d.ts +2 -1
  16. package/dist/types/runtime-mcp/mcp-redirect.d.ts +9 -0
  17. package/dist/types/runtime-mcp/oauth-public-url.d.ts +3 -1
  18. package/dist/types/runtime-mcp/project-host-values.d.ts +27 -0
  19. package/dist/types/sdk/broker/broker.d.ts +6 -1
  20. package/dist/types/sdk/broker/doctor-restart.d.ts +5 -0
  21. package/dist/types/sdk/broker/ensure.d.ts +14 -1
  22. package/dist/types/session/session-storage.d.ts +7 -0
  23. package/dist/types/skill-state/workflow-mutation-guard.d.ts +3 -0
  24. package/dist/types/task/isolation-dir.d.ts +26 -0
  25. package/dist/types/tools/ast-edit-write-path.d.ts +13 -0
  26. package/dist/types/tools/browser/cdp-url.d.ts +2 -0
  27. package/dist/types/tools/github-side-effect.d.ts +22 -0
  28. package/dist/types/tools/monitor-mutation.d.ts +9 -0
  29. package/package.json +7 -7
  30. package/src/async/endpoint-id.ts +26 -0
  31. package/src/async/job-manager.ts +19 -10
  32. package/src/async/support.ts +0 -25
  33. package/src/capability/index.ts +14 -16
  34. package/src/cli/doctor/repairs.ts +4 -1
  35. package/src/cli/doctor-supervisor.ts +3 -0
  36. package/src/cli/public-command-registry.ts +28 -6
  37. package/src/commands/mcp-serve.ts +7 -0
  38. package/src/commands/sdk.ts +453 -415
  39. package/src/config/file-lock.ts +9 -11
  40. package/src/config/model-profile-activation.ts +5 -5
  41. package/src/coordinator-mcp/server.ts +2 -0
  42. package/src/customization/inventory.ts +1 -13
  43. package/src/dap/config.ts +2 -2
  44. package/src/defaults/gjc/extensions/grok-cli-vendor/src/provider/register.ts +10 -6
  45. package/src/discovery/builtin.ts +3 -1
  46. package/src/discovery/helpers.ts +12 -9
  47. package/src/discovery/mcp-json.ts +20 -12
  48. package/src/eval/py/executor.ts +459 -77
  49. package/src/eval/py/kernel.ts +79 -13
  50. package/src/eval/py/tool-bridge.ts +4 -0
  51. package/src/export/html/html-export-destination.ts +16 -0
  52. package/src/export/html/index.ts +2 -6
  53. package/src/extensibility/extensions/function-hooks-internal.ts +27 -0
  54. package/src/extensibility/extensions/runner.ts +11 -1
  55. package/src/extensibility/gjc-plugins/mcp-policy.ts +2 -1
  56. package/src/extensibility/gjc-plugins/runtime-adapters.ts +27 -15
  57. package/src/extensibility/skill-management.ts +3 -0
  58. package/src/gjc-runtime/launch-worktree.ts +56 -5
  59. package/src/gjc-runtime/psmux-detect.ts +28 -4
  60. package/src/gjc-runtime/session-state-sidecar.ts +3 -2
  61. package/src/gjc-runtime/sidecar-bootstrap-env.ts +19 -0
  62. package/src/gjc-runtime/state-writer.ts +22 -8
  63. package/src/gjc-runtime/tmux-common.ts +8 -5
  64. package/src/internal-urls/docs-index.generated.ts +7 -7
  65. package/src/lsp/config.ts +12 -63
  66. package/src/memories/index.ts +88 -7
  67. package/src/modes/components/hook-editor.ts +1 -1
  68. package/src/modes/components/hook-selector.ts +1 -1
  69. package/src/modes/controllers/input-controller.ts +2 -2
  70. package/src/modes/controllers/runtime-mcp-command-controller.ts +21 -13
  71. package/src/modes/controllers/selector-controller.ts +3 -7
  72. package/src/modes/controllers/todo-command-controller.ts +1 -1
  73. package/src/modes/interactive-mode.ts +1 -1
  74. package/src/runtime-mcp/client.ts +4 -2
  75. package/src/runtime-mcp/json-rpc.ts +2 -1
  76. package/src/runtime-mcp/manager.ts +29 -11
  77. package/src/runtime-mcp/mcp-redirect.ts +73 -0
  78. package/src/runtime-mcp/oauth-flow.ts +11 -4
  79. package/src/runtime-mcp/oauth-public-url.ts +8 -2
  80. package/src/runtime-mcp/pool.ts +6 -0
  81. package/src/runtime-mcp/project-host-values.ts +46 -0
  82. package/src/runtime-mcp/transports/http.ts +2 -1
  83. package/src/sdk/acp/adapter.ts +2 -0
  84. package/src/sdk/broker/broker.ts +6 -0
  85. package/src/sdk/broker/doctor-restart.ts +4 -0
  86. package/src/sdk/broker/ensure.ts +29 -2
  87. package/src/sdk/host/session-runtime.test.ts +58 -9
  88. package/src/sdk/host/session-runtime.ts +65 -35
  89. package/src/sdk/router/session-router.ts +7 -6
  90. package/src/sdk/session.ts +2 -7
  91. package/src/session/agent-session.ts +59 -17
  92. package/src/session/artifacts.ts +3 -2
  93. package/src/session/internal/managed-session-scope.ts +403 -81
  94. package/src/session/internal/managed-session-storage.ts +125 -17
  95. package/src/session/session-manager.ts +12 -0
  96. package/src/session/session-storage.ts +30 -1
  97. package/src/skill-state/active-state.ts +13 -0
  98. package/src/skill-state/workflow-mutation-guard.ts +102 -10
  99. package/src/slash-commands/builtin-registry.ts +1 -1
  100. package/src/slash-commands/helpers/mcp.ts +8 -4
  101. package/src/task/isolation-dir.ts +143 -0
  102. package/src/task/worktree.ts +16 -7
  103. package/src/tools/ast-edit-write-path.ts +68 -0
  104. package/src/tools/ast-edit.ts +7 -2
  105. package/src/tools/browser/cdp-url.ts +18 -0
  106. package/src/tools/browser.ts +8 -1
  107. package/src/tools/gh.ts +10 -0
  108. package/src/tools/github-side-effect.ts +112 -0
  109. package/src/tools/monitor-mutation.ts +27 -0
  110. package/src/tools/monitor.ts +7 -0
  111. package/src/tools/python.ts +7 -6
  112. package/src/utils/external-editor.ts +3 -2
  113. package/src/web/insane/url-guard.ts +2 -1
@@ -3443,16 +3443,22 @@ export class AsyncJobManager {
3443
3443
  return;
3444
3444
  }
3445
3445
 
3446
- this.#deliveryLoop = this.#runDeliveryLoop()
3446
+ const completion = Promise.withResolvers<void>();
3447
+ const promise = completion.promise;
3448
+ this.#deliveryLoop = promise;
3449
+ const operation = this.#runDeliveryLoop()
3447
3450
  .catch(error => {
3448
3451
  logger.error("Async job delivery loop crashed", { error: String(error) });
3449
3452
  })
3450
3453
  .finally(() => {
3451
- this.#deliveryLoop = undefined;
3452
- if (!this.#disposed && this.#hasDeliverable()) {
3453
- this.#ensureDeliveryLoop();
3454
+ if (this.#deliveryLoop === promise) {
3455
+ this.#deliveryLoop = undefined;
3456
+ if (!this.#disposed && this.#hasDeliverable()) {
3457
+ this.#ensureDeliveryLoop();
3458
+ }
3454
3459
  }
3455
3460
  });
3461
+ void operation.then(completion.resolve, completion.reject);
3456
3462
  }
3457
3463
 
3458
3464
  async #runDeliveryLoop(): Promise<void> {
@@ -3472,14 +3478,15 @@ export class AsyncJobManager {
3472
3478
  continue;
3473
3479
 
3474
3480
  this.#deliveries.splice(index, 1);
3475
- this.#notifyChange();
3476
3481
  await this.#deliverDelivery(delivery);
3477
3482
  }
3478
3483
  }
3479
3484
 
3480
3485
  #deliverDelivery(delivery: AsyncJobDelivery): Promise<void> {
3481
- const promise = (async () => {
3482
- this.#inFlightDeliveries.push(delivery);
3486
+ const completion = Promise.withResolvers<void>();
3487
+ delivery.promise = completion.promise;
3488
+ this.#inFlightDeliveries.push(delivery);
3489
+ const operation = (async () => {
3483
3490
  this.#notifyChange();
3484
3491
  try {
3485
3492
  const currentJob = this.#jobs.get(delivery.jobId);
@@ -3532,12 +3539,14 @@ export class AsyncJobManager {
3532
3539
  if (!this.#disposed && this.#hasDeliverable()) this.#ensureDeliveryLoop();
3533
3540
  }
3534
3541
  })();
3535
- delivery.promise = promise;
3536
- return promise;
3542
+ void operation.then(completion.resolve, completion.reject);
3543
+ return completion.promise;
3537
3544
  }
3538
3545
 
3539
3546
  async #waitForDeliveryPromise(promise: Promise<void> | undefined, deadline: number): Promise<boolean> {
3540
- if (!promise) return true;
3547
+ // Missing an enrolled in-flight future is uncertainty, never evidence of
3548
+ // successful settlement.
3549
+ if (!promise) return false;
3541
3550
  if (deadline === Number.POSITIVE_INFINITY) {
3542
3551
  await promise;
3543
3552
  return true;
@@ -1,31 +1,6 @@
1
- import * as path from "node:path";
2
- import { resolveEquivalentPath } from "@gajae-code/utils";
3
1
  import type { Settings } from "../config/settings";
4
2
 
5
3
  export function isBackgroundJobSupportEnabled(settings: Pick<Settings, "get">): boolean {
6
4
  void settings;
7
5
  return true;
8
6
  }
9
-
10
- /**
11
- * Single source of truth for the AsyncJobManager endpoint key.
12
- *
13
- * A session with an explicit provider session id is keyed by (provider id,
14
- * transcript path); everything else is keyed by its logical session id. The
15
- * transcript component is canonicalized so a path alias — symlink, `..`
16
- * segment, or unresolved relative path — cannot register the manager under one
17
- * key at construction and look it up under another across a session-identity
18
- * transition, stranding ownership.
19
- *
20
- * Both the SDK constructor and AgentSession's transition rekeying must derive
21
- * the key here; duplicating the shape lets the two drift apart silently.
22
- */
23
- export function asyncJobEndpointId(
24
- providerSessionId: string | undefined,
25
- sessionId: string,
26
- sessionFile: string | undefined,
27
- ): string {
28
- return providerSessionId !== undefined && sessionFile !== undefined
29
- ? JSON.stringify(["async-job-endpoint", providerSessionId, resolveEquivalentPath(path.resolve(sessionFile))])
30
- : sessionId;
31
- }
@@ -22,7 +22,7 @@ import {
22
22
  } from "@gajae-code/utils";
23
23
 
24
24
  import type { Settings } from "../config/settings";
25
- import { resolveGlobalUserSkillLinkTrust } from "../config/skill-settings-defaults";
25
+ import { resolveGlobalUserSkillLinkTrust, resolveSkillScopeTrust } from "../config/skill-settings-defaults";
26
26
  import { clearCache as clearFsCache, findRepoRoot, cacheStats as fsCacheStats, invalidate as invalidateFs } from "./fs";
27
27
  import type {
28
28
  Capability,
@@ -74,6 +74,17 @@ const EXPLICIT_HOME_PROVIDER_ROOTS = [
74
74
 
75
75
  const ANCESTOR_SCOPED_PROJECT_PROVIDERS = new Set(["agents", "agents-md", "cline"]);
76
76
 
77
+ function resolveExternalUserSkillSymlinkTrust(settings: Settings | undefined): boolean {
78
+ const userOwnedTrust = resolveGlobalUserSkillLinkTrust({
79
+ trustUserSkills:
80
+ typeof settings?.getGlobal === "function" ? settings.getGlobal("skills.trustUserSkills") : undefined,
81
+ enablePiUser: typeof settings?.getGlobal === "function" ? settings.getGlobal("skills.enablePiUser") : undefined,
82
+ });
83
+ const effectiveScopeTrust =
84
+ typeof settings?.getGroup === "function" ? resolveSkillScopeTrust(settings.getGroup("skills"), "user") : true;
85
+ return userOwnedTrust && effectiveScopeTrust;
86
+ }
87
+
77
88
  function isWithinOrEqual(root: string, candidate: string): boolean {
78
89
  const relative = path.relative(root, candidate);
79
90
  return relative === "" || (!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative));
@@ -415,7 +426,6 @@ export async function loadCapability<T>(capabilityId: string, options: LoadOptio
415
426
  const cwd = ordinaryOptions.cwd ?? getProjectDir();
416
427
  const home = getTrustedHomeDir();
417
428
  const activeSettings = ordinaryOptions.settings ?? settingsByCwd.get(path.normalize(cwd));
418
- const globalSettings = typeof activeSettings?.getGlobal === "function" ? activeSettings : undefined;
419
429
  const userAgentDir = ordinaryOptions.agentDir ? path.resolve(ordinaryOptions.agentDir) : getAgentDir();
420
430
  const profileAuthority =
421
431
  ordinaryOptions.profileAuthority ??
@@ -432,10 +442,7 @@ export async function loadCapability<T>(capabilityId: string, options: LoadOptio
432
442
  repoRoot,
433
443
  isolatedHome: false,
434
444
  settings: ordinaryOptions.settings,
435
- allowExternalUserSkillSymlinks: resolveGlobalUserSkillLinkTrust({
436
- trustUserSkills: globalSettings?.getGlobal("skills.trustUserSkills"),
437
- enablePiUser: globalSettings?.getGlobal("skills.enablePiUser"),
438
- }),
445
+ allowExternalUserSkillSymlinks: resolveExternalUserSkillSymlinkTrust(activeSettings),
439
446
  bypassCache: ordinaryOptions.bypassCache,
440
447
  };
441
448
  const providers = filterProviders(capability, ordinaryOptions);
@@ -528,16 +535,7 @@ export async function loadCapabilityForHome<T>(
528
535
  isolatedHome,
529
536
  homeIdentity,
530
537
  settings: isolatedOptions.settings,
531
- allowExternalUserSkillSymlinks: resolveGlobalUserSkillLinkTrust({
532
- trustUserSkills:
533
- typeof isolatedOptions.settings?.getGlobal === "function"
534
- ? isolatedOptions.settings.getGlobal("skills.trustUserSkills")
535
- : undefined,
536
- enablePiUser:
537
- typeof isolatedOptions.settings?.getGlobal === "function"
538
- ? isolatedOptions.settings.getGlobal("skills.enablePiUser")
539
- : undefined,
540
- }),
538
+ allowExternalUserSkillSymlinks: resolveExternalUserSkillSymlinkTrust(isolatedOptions.settings),
541
539
  };
542
540
 
543
541
  return await loadImpl(capability, providers, ctx, isolatedOptions);
@@ -954,7 +954,10 @@ export async function executeSelectedDoctorRepair(
954
954
  },
955
955
  afterChecks,
956
956
  };
957
- const preEffect = outcome.kind === "owner_unavailable" || outcome.kind === "prepare_refused";
957
+ const preEffect =
958
+ outcome.kind === "owner_unavailable" ||
959
+ outcome.kind === "prepare_refused" ||
960
+ outcome.kind === "attach_only_refused";
958
961
  return {
959
962
  repair: {
960
963
  ...plan,
@@ -74,6 +74,9 @@ const WORKER_ENV_KEYS = [
74
74
  "XDG_DATA_HOME",
75
75
  "XDG_STATE_HOME",
76
76
  "XDG_CACHE_HOME",
77
+ // SDK_BROKER_AUTOSTART_ENV (sdk/broker/ensure.ts), kept literal so this supervisor stays
78
+ // import-light. A supervisor-owned broker must stay unrestartable from the doctor worker.
79
+ "GJC_SDK_BROKER_AUTOSTART",
77
80
  ] as const;
78
81
 
79
82
  const COMPILED = /(?:\/\$bunfs\/|\/~BUN\/|\/%7EBUN\/)/i.test(import.meta.url);
@@ -81,6 +81,9 @@ const argument = (description: string, extra: Partial<PublicArgumentDescriptor>
81
81
  ...extra,
82
82
  });
83
83
  const agentDir = stringFlag("SDK broker/state directory (default: the configured agent directory).");
84
+ const attachOnly = booleanFlag(
85
+ "Attach only to a live SDK broker; never start, retire or restart one (same as GJC_SDK_BROKER_AUTOSTART=0).",
86
+ );
84
87
  const repo = stringFlag("Workspace directory for scope or saved-session resolution (default: current directory).");
85
88
  const exactSessionRepo = stringFlag(
86
89
  "Accepted for compatibility only; ignored because the exact session ID selects the broker target.",
@@ -187,7 +190,8 @@ function node(path: string, input: NodeInput): PublicCommandDescriptor {
187
190
  examples: [{ syntax: example ?? `gjc ${path} --help --json`, executable: false }],
188
191
  };
189
192
  }
190
- const sessionFlags = { "agent-dir": agentDir };
193
+ const guideFlags = { "agent-dir": agentDir };
194
+ const sessionFlags = { "agent-dir": agentDir, "attach-only": attachOnly };
191
195
  const observeDaemonFlags = {
192
196
  all: booleanFlag("Target all registered daemon kinds."),
193
197
  verbose: booleanFlag("Show runtime detail and the full roots list.", { char: "v" }),
@@ -212,7 +216,7 @@ const daemonArgs = {
212
216
  export const PUBLIC_COMMANDS: readonly PublicCommandDescriptor[] = [
213
217
  node("sdk", {
214
218
  description: "Discover SDK transports, sessions, search, spawn and advisory guides.",
215
- children: ["serve", "search", "spawn", "session", "guides"],
219
+ children: ["serve", "broker", "search", "spawn", "session", "guides"],
216
220
  syntax: "<command>",
217
221
  constraints: [
218
222
  "A public child command is required unless requesting help or root evidence retrieval.",
@@ -242,6 +246,24 @@ export const PUBLIC_COMMANDS: readonly PublicCommandDescriptor[] = [
242
246
  ],
243
247
  example: "gjc sdk serve --stdio",
244
248
  }),
249
+ node("sdk broker", {
250
+ description: "Run the SDK broker under an external supervisor.",
251
+ children: ["run"],
252
+ syntax: "<command>",
253
+ }),
254
+ node("sdk broker run", {
255
+ description:
256
+ "Run the SDK broker in the foreground for a supervisor (systemd, launchd); stable contract, never detaches.",
257
+ flags: { "agent-dir": agentDir },
258
+ syntax: "[--agent-dir <dir>]",
259
+ risk: "Owns the broker for the agent directory; clients should run attach-only (GJC_SDK_BROKER_AUTOSTART=0) so they never start a competing one.",
260
+ constraints: [
261
+ "Stays in the foreground until SIGTERM or SIGINT, stops gracefully, then exits with the signal status (143 or 130).",
262
+ "Exits 1 without serving when another live broker owns the agent directory (it never retires it) or startup fails.",
263
+ "Exits 1 if it loses its discovery root or cannot renew its heartbeat while serving; a broker.shutdown request exits 0.",
264
+ ],
265
+ example: "gjc sdk broker run --agent-dir ~/.gjc/agent",
266
+ }),
245
267
  node("sdk search", {
246
268
  description: "Search broker-visible sessions in an exact repo, pwd or global scope.",
247
269
  syntax: "[--scope repo|pwd|global] [--repo <dir>] [--limit <N>] [--cursor <cursor>]",
@@ -442,7 +464,7 @@ export const PUBLIC_COMMANDS: readonly PublicCommandDescriptor[] = [
442
464
  node("sdk guides refresh", {
443
465
  description: "Fetch and verify an allowlisted HTTPS guide manifest and advisory cache.",
444
466
  flags: {
445
- ...sessionFlags,
467
+ ...guideFlags,
446
468
  url: stringFlag("HTTPS allowlisted manifest URL.", { required: true }),
447
469
  "timeout-ms": positive("Bounded refresh timeout in milliseconds."),
448
470
  },
@@ -451,14 +473,14 @@ export const PUBLIC_COMMANDS: readonly PublicCommandDescriptor[] = [
451
473
  "A fallback cache or bundled selection is an operational refresh failure, not online refresh success.",
452
474
  ],
453
475
  }),
454
- node("sdk guides list", { description: "List guides from the verified advisory selection.", flags: sessionFlags }),
476
+ node("sdk guides list", { description: "List guides from the verified advisory selection.", flags: guideFlags }),
455
477
  node("sdk guides show", {
456
478
  description: "Read a verified guide by ID.",
457
479
  args: { guideId: argument("Exact guide ID from guides list.") },
458
- flags: sessionFlags,
480
+ flags: guideFlags,
459
481
  syntax: "<guideId>",
460
482
  }),
461
- node("sdk guides status", { description: "Report guide cache and selection status.", flags: sessionFlags }),
483
+ node("sdk guides status", { description: "Report guide cache and selection status.", flags: guideFlags }),
462
484
  node("sdk guides trust", { description: "Show the static guide trust policy; no refresh or cache mutation." }),
463
485
  node("daemon", {
464
486
  description: "Manage Telegram, Discord and Slack background daemons, not the SDK broker.",
@@ -7,6 +7,7 @@ import {
7
7
  } from "../coordinator/contract";
8
8
  import { runCoordinatorMcpStdio } from "../coordinator-mcp/server";
9
9
  import { type BrokerDiscovery, readBrokerDiscovery } from "../sdk/broker/discovery";
10
+ import { SDK_BROKER_AUTOSTART_ENV } from "../sdk/broker/ensure";
10
11
  import { UnsupportedStateVersionError } from "../sdk/broker/state-version";
11
12
  import { runSdkMcpStdio, SDK_MCP_TOOL_NAMES } from "../sdk/mcp/server";
12
13
 
@@ -104,6 +105,10 @@ export default class McpServe extends Command {
104
105
  static flags = {
105
106
  json: Flags.boolean({ char: "j", description: "Emit machine-readable JSON", default: false }),
106
107
  check: Flags.boolean({ description: "Validate server configuration and print a smoke summary", default: false }),
108
+ "attach-only": Flags.boolean({
109
+ description: "Attach only to a live SDK broker; never start one (same as GJC_SDK_BROKER_AUTOSTART=0)",
110
+ default: false,
111
+ }),
107
112
  };
108
113
 
109
114
  async run(): Promise<void> {
@@ -122,6 +127,8 @@ export default class McpServe extends Command {
122
127
  return;
123
128
  }
124
129
 
130
+ if (flags["attach-only"]) process.env[SDK_BROKER_AUTOSTART_ENV] = "0";
131
+
125
132
  if (flags.check) {
126
133
  if (!flags.json) {
127
134
  const serverName = server === "sdk" ? "gjc-sdk-mcp" : COORDINATOR_MCP_SERVER_NAME;