@gajae-code/coding-agent 0.7.3 → 0.7.5

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 (118) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/bin/gjc.js +4 -0
  3. package/dist/types/cli/plugin-cli.d.ts +2 -0
  4. package/dist/types/commands/plugin.d.ts +6 -0
  5. package/dist/types/commands/session.d.ts +6 -0
  6. package/dist/types/config/model-profile-activation.d.ts +8 -1
  7. package/dist/types/extensibility/gjc-plugins/compiler.d.ts +19 -0
  8. package/dist/types/extensibility/gjc-plugins/constrained-hooks.d.ts +29 -0
  9. package/dist/types/extensibility/gjc-plugins/index.d.ts +9 -0
  10. package/dist/types/extensibility/gjc-plugins/injection.d.ts +9 -0
  11. package/dist/types/extensibility/gjc-plugins/installer.d.ts +13 -0
  12. package/dist/types/extensibility/gjc-plugins/mcp-policy.d.ts +26 -0
  13. package/dist/types/extensibility/gjc-plugins/observability.d.ts +27 -0
  14. package/dist/types/extensibility/gjc-plugins/prompt-appendix.d.ts +16 -0
  15. package/dist/types/extensibility/gjc-plugins/registry.d.ts +32 -0
  16. package/dist/types/extensibility/gjc-plugins/runtime-adapters.d.ts +64 -0
  17. package/dist/types/extensibility/gjc-plugins/session-validation.d.ts +42 -0
  18. package/dist/types/extensibility/gjc-plugins/types.d.ts +158 -2
  19. package/dist/types/extensibility/gjc-plugins/validation.d.ts +8 -1
  20. package/dist/types/gjc-runtime/launch-tmux.d.ts +1 -0
  21. package/dist/types/gjc-runtime/psmux-detect.d.ts +78 -0
  22. package/dist/types/gjc-runtime/team-runtime.d.ts +2 -0
  23. package/dist/types/gjc-runtime/tmux-common.d.ts +30 -2
  24. package/dist/types/gjc-runtime/tmux-sessions.d.ts +18 -0
  25. package/dist/types/main.d.ts +2 -0
  26. package/dist/types/modes/components/model-selector.d.ts +6 -0
  27. package/dist/types/notifications/html-format.d.ts +11 -0
  28. package/dist/types/notifications/index.d.ts +149 -1
  29. package/dist/types/notifications/lifecycle-commands.d.ts +72 -0
  30. package/dist/types/notifications/lifecycle-control-runtime.d.ts +98 -0
  31. package/dist/types/notifications/lifecycle-orchestrator.d.ts +144 -0
  32. package/dist/types/notifications/rate-limit-pool.d.ts +2 -0
  33. package/dist/types/notifications/recent-activity.d.ts +35 -0
  34. package/dist/types/notifications/telegram-daemon.d.ts +60 -0
  35. package/dist/types/notifications/telegram-reference.d.ts +3 -1
  36. package/dist/types/notifications/topic-registry.d.ts +10 -9
  37. package/dist/types/runtime-mcp/types.d.ts +7 -0
  38. package/dist/types/sdk.d.ts +2 -0
  39. package/dist/types/session/agent-session.d.ts +14 -4
  40. package/dist/types/session/blob-store.d.ts +25 -0
  41. package/dist/types/session/session-manager.d.ts +57 -0
  42. package/dist/types/slash-commands/helpers/fast-status-report.d.ts +6 -0
  43. package/dist/types/system-prompt.d.ts +2 -0
  44. package/dist/types/task/executor.d.ts +9 -1
  45. package/dist/types/tools/index.d.ts +3 -1
  46. package/dist/types/utils/changelog.d.ts +1 -0
  47. package/package.json +11 -9
  48. package/scripts/g004-tmux-smoke.ts +100 -0
  49. package/scripts/g005-daemon-smoke.ts +181 -0
  50. package/scripts/g011-daemon-path-smoke.ts +153 -0
  51. package/src/cli/plugin-cli.ts +66 -3
  52. package/src/cli.ts +21 -4
  53. package/src/commands/plugin.ts +4 -0
  54. package/src/commands/session.ts +18 -0
  55. package/src/config/model-profile-activation.ts +55 -7
  56. package/src/defaults/gjc/extensions/grok-cli-vendor/biome.json +1 -1
  57. package/src/defaults/gjc/skills/deep-interview/SKILL.md +3 -3
  58. package/src/defaults/gjc/skills/team/SKILL.md +5 -4
  59. package/src/defaults/gjc/skills/ultragoal/SKILL.md +41 -13
  60. package/src/export/html/index.ts +2 -2
  61. package/src/extensibility/gjc-plugins/compiler.ts +351 -0
  62. package/src/extensibility/gjc-plugins/constrained-hooks.ts +170 -0
  63. package/src/extensibility/gjc-plugins/index.ts +9 -0
  64. package/src/extensibility/gjc-plugins/injection.ts +109 -0
  65. package/src/extensibility/gjc-plugins/installer.ts +434 -0
  66. package/src/extensibility/gjc-plugins/loader.ts +3 -1
  67. package/src/extensibility/gjc-plugins/mcp-policy.ts +239 -0
  68. package/src/extensibility/gjc-plugins/observability.ts +84 -0
  69. package/src/extensibility/gjc-plugins/paths.ts +1 -1
  70. package/src/extensibility/gjc-plugins/prompt-appendix.ts +109 -0
  71. package/src/extensibility/gjc-plugins/registry.ts +180 -0
  72. package/src/extensibility/gjc-plugins/runtime-adapters.ts +234 -0
  73. package/src/extensibility/gjc-plugins/schema.ts +250 -20
  74. package/src/extensibility/gjc-plugins/session-validation.ts +147 -0
  75. package/src/extensibility/gjc-plugins/types.ts +199 -3
  76. package/src/extensibility/gjc-plugins/validation.ts +80 -0
  77. package/src/extensibility/skills.ts +15 -0
  78. package/src/gjc-runtime/launch-tmux.ts +58 -15
  79. package/src/gjc-runtime/psmux-detect.ts +239 -0
  80. package/src/gjc-runtime/team-runtime.ts +56 -23
  81. package/src/gjc-runtime/tmux-common.ts +85 -3
  82. package/src/gjc-runtime/tmux-sessions.ts +111 -9
  83. package/src/gjc-runtime/ultragoal-runtime.ts +75 -15
  84. package/src/internal-urls/docs-index.generated.ts +5 -4
  85. package/src/main.ts +14 -3
  86. package/src/modes/components/assistant-message.ts +49 -1
  87. package/src/modes/components/hook-editor.ts +1 -1
  88. package/src/modes/components/hook-selector.ts +67 -43
  89. package/src/modes/components/model-selector.ts +44 -11
  90. package/src/modes/controllers/extension-ui-controller.ts +0 -27
  91. package/src/modes/controllers/selector-controller.ts +50 -11
  92. package/src/modes/interactive-mode.ts +2 -0
  93. package/src/modes/utils/hotkeys-markdown.ts +1 -1
  94. package/src/notifications/html-format.ts +38 -0
  95. package/src/notifications/index.ts +242 -12
  96. package/src/notifications/lifecycle-commands.ts +228 -0
  97. package/src/notifications/lifecycle-control-runtime.ts +400 -0
  98. package/src/notifications/lifecycle-orchestrator.ts +358 -0
  99. package/src/notifications/rate-limit-pool.ts +19 -0
  100. package/src/notifications/recent-activity.ts +132 -0
  101. package/src/notifications/telegram-daemon.ts +433 -8
  102. package/src/notifications/telegram-reference.ts +25 -7
  103. package/src/notifications/topic-registry.ts +18 -9
  104. package/src/prompts/agents/executor.md +2 -2
  105. package/src/runtime-mcp/transports/stdio.ts +38 -4
  106. package/src/runtime-mcp/types.ts +7 -0
  107. package/src/sdk.ts +157 -10
  108. package/src/session/agent-session.ts +166 -74
  109. package/src/session/blob-store.ts +196 -8
  110. package/src/session/session-manager.ts +739 -12
  111. package/src/slash-commands/builtin-registry.ts +23 -3
  112. package/src/slash-commands/helpers/fast-status-report.ts +13 -3
  113. package/src/system-prompt.ts +9 -0
  114. package/src/task/executor.ts +31 -7
  115. package/src/task/index.ts +2 -0
  116. package/src/tools/ask.ts +5 -1
  117. package/src/tools/index.ts +3 -1
  118. package/src/utils/changelog.ts +8 -0
@@ -1,3 +1,6 @@
1
+ import type { ResolvedTmuxBinary } from "./psmux-detect";
2
+ import { resolveGjcTmuxBinary } from "./psmux-detect";
3
+
1
4
  export const GJC_DEFAULT_TMUX_SESSION = "gajae_code";
2
5
  export const GJC_TMUX_SESSION_PREFIX = `${GJC_DEFAULT_TMUX_SESSION}_`;
3
6
  export const GJC_TMUX_COMMAND_ENV = "GJC_TMUX_COMMAND";
@@ -11,6 +14,7 @@ export const GJC_TMUX_PROJECT_OPTION = "@gjc-project";
11
14
  export const GJC_TMUX_SESSION_ID_OPTION = "@gjc-session-id";
12
15
  export const GJC_TMUX_SESSION_STATE_FILE_OPTION = "@gjc-session-state-file";
13
16
  export const GJC_TMUX_VERSION_OPTION = "@gjc-version";
17
+ export const GJC_PSMUX_PROFILE_FORCE_ENV = "GJC_PSMUX_PROFILE_FORCE";
14
18
 
15
19
  export interface GjcTmuxProfileCommand {
16
20
  description: string;
@@ -31,10 +35,33 @@ export function envDisabled(value: string | undefined): boolean {
31
35
  return normalized === "0" || normalized === "false" || normalized === "off" || normalized === "no";
32
36
  }
33
37
 
34
- export function resolveGjcTmuxCommand(env: NodeJS.ProcessEnv = process.env): string {
35
- return env[GJC_TMUX_COMMAND_ENV]?.trim() || env.GJC_TEAM_TMUX_COMMAND?.trim() || "tmux";
38
+ /**
39
+ * Resolve the tmux (or tmux-compatible multiplexer) command GJC should invoke.
40
+ *
41
+ * This is the shared entry point used by every GJC code path that needs to talk
42
+ * to a multiplexer: `gjc --tmux` planning, `gjc session ...`, `gjc team ...`,
43
+ * the lifecycle controller, and the harness resident owner. Routing all of
44
+ * them through the same resolver means a single `GJC_TMUX_COMMAND` override or
45
+ * a single Windows psmux / pmux detection wins for the whole process — the
46
+ * failure mode where `gjc --tmux` creates a psmux-backed session and then
47
+ * `gjc session status` fails because it queries literal `tmux` is closed off.
48
+ *
49
+ * Explicit `GJC_TMUX_COMMAND` / `GJC_TEAM_TMUX_COMMAND` overrides are honored on
50
+ * every platform. On native Windows without an override the resolver walks
51
+ * `psmux`, then `pmux`, then `tmux` and uses the first binary present on PATH.
52
+ * On POSIX the resolver returns `tmux` (the historical default) and only
53
+ * falls through to the platform-aware walker if the caller opts in.
54
+ */
55
+ export function resolveGjcTmuxCommand(
56
+ env: NodeJS.ProcessEnv = process.env,
57
+ platform: NodeJS.Platform = process.platform,
58
+ ): string {
59
+ return resolveGjcTmuxBinary({ env, platform }).command;
36
60
  }
37
61
 
62
+ export type { PsmuxProbe, ResolvedTmuxBinary, ResolveGjcTmuxBinaryOptions } from "./psmux-detect";
63
+ export { clearPsmuxDetectionCache, detectPsmux, probePsmux, resolveGjcTmuxBinary } from "./psmux-detect";
64
+
38
65
  /**
39
66
  * Build the exact-session target for tmux *option* commands
40
67
  * (`show-options` / `set-option`) and `display-message -t`.
@@ -45,7 +72,17 @@ export function resolveGjcTmuxCommand(env: NodeJS.ProcessEnv = process.env): str
45
72
  * keeps the exact-session match while giving tmux the window-qualified target
46
73
  * those commands require. See gajae-code#580.
47
74
  */
48
- export function buildGjcTmuxExactOptionTarget(sessionName: string): string {
75
+ export function buildGjcTmuxExactOptionTarget(
76
+ sessionName: string,
77
+ opts: { env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; binary?: ResolvedTmuxBinary } = {},
78
+ ): string {
79
+ const binary = opts.binary ?? resolveGjcTmuxBinary({ env: opts.env, platform: opts.platform });
80
+ // psmux 3.3.0 rejects the tmux `=NAME` exact-session prefix for option
81
+ // commands ("no server running on session '=NAME'"); bare `NAME` and
82
+ // window-qualified `NAME:` both work. tmux 3.6a needs the
83
+ // window-qualified `=NAME:` to resolve the session for option
84
+ // commands (gajae-code#580).
85
+ if (binary.isPsmux) return sessionName;
49
86
  return `=${sessionName}:`;
50
87
  }
51
88
 
@@ -146,6 +183,16 @@ export function buildGjcTmuxRequiredProfileCommands(
146
183
  return commands;
147
184
  }
148
185
 
186
+ /**
187
+ * Keys whose set-option / set-window-option round-trip is unreliable on psmux
188
+ * 3.3.0. psmux does not support the tmux `set-window-option` command at all
189
+ * (it reports "unknown command: set-window-option") and silently drops several
190
+ * `set-option` keys. The list lives here so every code path that tags a tmux
191
+ * session (gjc --tmux planning, gjc session create, gjc team bootstrap)
192
+ * applies the same filter.
193
+ */
194
+ const PSMUX_UNSUPPORTED_PROFILE_KEYS = new Set(["mouse", "set-clipboard", "mode-style"]);
195
+
149
196
  export function buildGjcTmuxProfileCommands(
150
197
  target: string,
151
198
  env: NodeJS.ProcessEnv = process.env,
@@ -157,6 +204,7 @@ export function buildGjcTmuxProfileCommands(
157
204
  sessionStateFile?: string | null;
158
205
  version?: string | null;
159
206
  } = {},
207
+ opts: { platform?: NodeJS.Platform; tmuxCommand?: string } = {},
160
208
  ): GjcTmuxProfileCommand[] {
161
209
  const commands = buildGjcTmuxRequiredProfileCommands(target, metadata);
162
210
  if (envDisabled(env[GJC_TMUX_PROFILE_ENV])) return commands;
@@ -172,6 +220,40 @@ export function buildGjcTmuxProfileCommands(
172
220
  description: "enable tmux mouse scrolling",
173
221
  args: ["set-option", "-t", target, "mouse", "on"],
174
222
  });
223
+ // psmux does not implement set-window-option and historically drops
224
+ // mouse / set-clipboard / mode-style. Filter the UX profile commands
225
+ // centrally so every code path that tags a session (gjc --tmux planning,
226
+ // gjc session create, gjc team bootstrap) drops the same set. The
227
+ // GJC_PSMUX_PROFILE_FORCE override lets the operator opt back in when
228
+ // running on a psmux build that has caught up. The ownership-tag
229
+ // round-trip (set-option @gjc-*) is never filtered, since gjc session /
230
+ // gjc team rely on it.
231
+ // The filter is opt-in: callers that explicitly pass `opts.tmuxCommand`
232
+ // name a psmux-class multiplexer (psmux / pmux) when they want the UX
233
+ // profile filtered. Auto-detect on Windows hosts where psmux happens
234
+ // to be on PATH would silently change the test output for every caller
235
+ // that does not pin the multiplexer, so we require the caller to opt
236
+ // in by naming the multiplexer. GJC_PSMUX_PROFILE_FORCE re-enables
237
+ // the UX profile commands when a psmux build catches up.
238
+ const tmuxName = (opts.tmuxCommand ?? "").toLowerCase();
239
+ const isPsmuxClass =
240
+ tmuxName === "psmux" ||
241
+ tmuxName === "pmux" ||
242
+ tmuxName.endsWith("/psmux") ||
243
+ tmuxName.endsWith("/pmux") ||
244
+ tmuxName.endsWith("\\psmux") ||
245
+ tmuxName.endsWith("\\pmux");
246
+ const dropUx = isPsmuxClass && !envDisabled(env[GJC_PSMUX_PROFILE_FORCE_ENV]);
247
+ if (dropUx) {
248
+ return commands.filter(command => {
249
+ const flag = command.args[0];
250
+ const key = command.args[command.args.length - 2];
251
+ return !(
252
+ PSMUX_UNSUPPORTED_PROFILE_KEYS.has(String(key)) &&
253
+ (flag === "set-option" || flag === "set-window-option")
254
+ );
255
+ });
256
+ }
175
257
  return commands;
176
258
  }
177
259
 
@@ -1,3 +1,4 @@
1
+ import { resolveGjcTmuxBinary } from "./psmux-detect";
1
2
  import {
2
3
  buildGjcTmuxExactOptionTarget,
3
4
  buildGjcTmuxProfileCommands,
@@ -128,10 +129,29 @@ function runListSessions(format: string, env: NodeJS.ProcessEnv = process.env):
128
129
  }
129
130
  throw error;
130
131
  }
131
- return output
132
+ const lines = output
132
133
  .split("\n")
133
134
  .map(line => line.trim())
134
135
  .filter(Boolean);
136
+ // psmux 3.3.0 silently ignores the tmux `-F` format flag and returns its
137
+ // default `name: N windows (created ...)` shape. Detect that case and
138
+ // synthesize a tab-separated row so downstream parseSessionLine /
139
+ // hydrateSessionFromExactOptions can recover the @gjc-* ownership tags
140
+ // via follow-up show-options calls. Without this fallback gjc session
141
+ // list / status return an empty list on psmux even when sessions exist.
142
+ if (lines.length > 0 && !lines[0].includes("\t")) {
143
+ const binary = resolveGjcTmuxBinary({ env });
144
+ if (binary.isPsmux) {
145
+ return lines.map(line => {
146
+ const match = line.match(/^([^:]+):\s*(\d+)\s+windows?\s+\(created\s+([^)]+)\)/);
147
+ if (!match) return line;
148
+ const [, name, windows, created] = match;
149
+ const createdEpoch = String(Math.floor(new Date(`${created} UTC`).getTime() / 1000) || 0);
150
+ return [name, windows, "0", createdEpoch, "", "", "0", "", "", "", "", "", "", ""].join("\t");
151
+ });
152
+ }
153
+ }
154
+ return lines;
135
155
  }
136
156
 
137
157
  function listSessionLines(env: NodeJS.ProcessEnv = process.env): string[] {
@@ -221,7 +241,13 @@ export function statusGjcTmuxSession(sessionName: string, env: NodeJS.ProcessEnv
221
241
  export function createGjcTmuxSession(env: NodeJS.ProcessEnv = process.env): GjcTmuxSessionStatus {
222
242
  const tmuxCommand = resolveGjcTmuxCommand(env);
223
243
  const sessionName = buildGjcTmuxSessionName(env);
224
- const command = "exec env GJC_TMUX_LAUNCHED=1 gjc";
244
+ // Build a shell-bootstrap command appropriate for the host shell. Psmux on
245
+ // Windows runs the new-session command through PowerShell, so we use the
246
+ // $env:VAR = ... assignment form there. POSIX keeps the historical exec
247
+ // env form so the launched gjc inherits GJC_TMUX_LAUNCHED without leaking
248
+ // into the parent tmux server.
249
+ const platform = process.platform;
250
+ const command = platform === "win32" ? "$env:GJC_TMUX_LAUNCHED = '1'; gjc" : "exec env GJC_TMUX_LAUNCHED=1 gjc";
225
251
  const created = Bun.spawnSync([tmuxCommand, "new-session", "-d", "-s", sessionName, command], {
226
252
  stdout: "pipe",
227
253
  stderr: "pipe",
@@ -229,7 +255,14 @@ export function createGjcTmuxSession(env: NodeJS.ProcessEnv = process.env): GjcT
229
255
  });
230
256
  if (created.exitCode !== 0) throw new Error(created.stderr.toString().trim() || "gjc_tmux_session_create_failed");
231
257
  try {
232
- for (const profileCommand of buildGjcTmuxProfileCommands(sessionName, env)) {
258
+ // psmux 3.3.0 rejects the tmux `=NAME` exact-session prefix for option
259
+ // commands, so the target is the bare session name on psmux and the
260
+ // window-qualified `=NAME:` on tmux. The ownership-tag round-trip
261
+ // (set-option @gjc-*) is preserved on both; only the UX profile commands
262
+ // (mouse / set-clipboard / mode-style / set-window-option) get filtered
263
+ // by buildGjcTmuxProfileCommands when the active binary is psmux.
264
+ const target = buildGjcTmuxExactOptionTarget(sessionName, { env });
265
+ for (const profileCommand of buildGjcTmuxProfileCommands(target, env, {}, { tmuxCommand })) {
233
266
  runTmux(profileCommand.args, env);
234
267
  }
235
268
  } catch (error) {
@@ -240,18 +273,43 @@ export function createGjcTmuxSession(env: NodeJS.ProcessEnv = process.env): GjcT
240
273
  }
241
274
 
242
275
  function readProfileForExactTarget(sessionName: string, env: NodeJS.ProcessEnv): string {
243
- return runTmux(
244
- ["show-options", "-qv", "-t", buildGjcTmuxExactOptionTarget(sessionName), GJC_TMUX_PROFILE_OPTION],
276
+ const raw = runTmux(
277
+ ["show-options", "-qv", "-t", buildGjcTmuxExactOptionTarget(sessionName, { env }), GJC_TMUX_PROFILE_OPTION],
245
278
  env,
246
279
  ).trim();
280
+ // tmux returns just the value; psmux returns `key value`. Strip the
281
+ // leading key on psmux so the GJC_TMUX_PROFILE_VALUE equality check
282
+ // against "1" works the same on both.
283
+ if (raw && resolveGjcTmuxBinary({ env }).isPsmux) {
284
+ const tokens = raw.split(/\s+/).filter(Boolean);
285
+ return tokens[tokens.length - 1] ?? raw;
286
+ }
287
+ return raw;
247
288
  }
248
289
 
249
290
  function readExactOptionForGc(sessionName: string, option: string, env: NodeJS.ProcessEnv): string | undefined {
250
291
  try {
251
- return (
252
- runTmux(["show-options", "-qv", "-t", buildGjcTmuxExactOptionTarget(sessionName), option], env).trim() ||
253
- undefined
254
- );
292
+ const raw = runTmux(
293
+ ["show-options", "-qv", "-t", buildGjcTmuxExactOptionTarget(sessionName, { env }), option],
294
+ env,
295
+ ).trim();
296
+ if (!raw) return undefined;
297
+ // tmux returns just the option value (e.g. `1` for @gjc-profile).
298
+ // psmux 3.3.0 returns `key value` (or `key "value with space"` for
299
+ // @gjc-branch etc.). On psmux, parse the last token and strip any
300
+ // surrounding double quotes so both shapes resolve to the same value.
301
+ if (resolveGjcTmuxBinary({ env }).isPsmux) {
302
+ // Prefer the last whitespace-separated token. If the value is
303
+ // quoted, find the matching close-quote and slice.
304
+ const lastQuote = raw.lastIndexOf('"');
305
+ if (lastQuote > 0 && raw[lastQuote - 1] !== "\\") {
306
+ const firstQuote = raw.lastIndexOf('"', lastQuote - 1);
307
+ if (firstQuote > 0) return raw.slice(firstQuote + 1, lastQuote);
308
+ }
309
+ const tokens = raw.split(/\s+/).filter(Boolean);
310
+ return tokens[tokens.length - 1];
311
+ }
312
+ return raw;
255
313
  } catch {
256
314
  return undefined;
257
315
  }
@@ -306,6 +364,50 @@ export function removeGjcTmuxSession(sessionName: string, env: NodeJS.ProcessEnv
306
364
  return session;
307
365
  }
308
366
 
367
+ /**
368
+ * Force-close a GJC-managed tmux session, even if a live pane is attached.
369
+ *
370
+ * This is the lifecycle-control counterpart to {@link removeGjcTmuxSession}: it
371
+ * intentionally does NOT refuse live/attached panes (hard-kill is the contract),
372
+ * but it keeps every safety check so it can only ever kill a genuinely
373
+ * GJC-managed session:
374
+ * - re-reads the exact tmux profile immediately before kill (never a non-GJC
375
+ * session, even one that collides by name);
376
+ * - when `expectedSessionId` is given, requires the `@gjc-session-id` tag match;
377
+ * - when `expectedStateFile` is given, requires the `@gjc-session-state-file`
378
+ * tag match.
379
+ *
380
+ * Returns the prior status (for audit). Throws a tagged error otherwise:
381
+ * `gjc_tmux_session_not_found`, `gjc_tmux_session_not_managed`,
382
+ * `gjc_tmux_session_id_mismatch`, or `gjc_tmux_session_state_file_mismatch`.
383
+ */
384
+ export function forceCloseGjcTmuxSession(
385
+ sessionName: string,
386
+ env: NodeJS.ProcessEnv = process.env,
387
+ expectedSessionId?: string,
388
+ expectedStateFile?: string,
389
+ ): GjcTmuxSessionStatus {
390
+ const session = statusGjcTmuxSession(sessionName, env);
391
+ if (readProfileForExactTarget(session.name, env) !== GJC_TMUX_PROFILE_VALUE) {
392
+ throw new Error(`gjc_tmux_session_not_managed:${sessionName}`);
393
+ }
394
+ if (expectedSessionId !== undefined) {
395
+ const actual = readExactOptionForGc(session.name, GJC_TMUX_SESSION_ID_OPTION, env);
396
+ if (actual !== expectedSessionId) {
397
+ throw new Error(`gjc_tmux_session_id_mismatch:${sessionName}`);
398
+ }
399
+ }
400
+ if (expectedStateFile !== undefined) {
401
+ const actual = readExactOptionForGc(session.name, GJC_TMUX_SESSION_STATE_FILE_OPTION, env);
402
+ if (actual !== expectedStateFile) {
403
+ throw new Error(`gjc_tmux_session_state_file_mismatch:${sessionName}`);
404
+ }
405
+ }
406
+ // Intentionally NOT refusing live/attached panes — force-close is hard-kill.
407
+ runTmux(["kill-session", "-t", `=${session.name}`], env);
408
+ return session;
409
+ }
410
+
309
411
  export function attachGjcTmuxSession(sessionName: string, env: NodeJS.ProcessEnv = process.env): never {
310
412
  const session = statusGjcTmuxSession(sessionName, env);
311
413
  const tmuxCommand = resolveGjcTmuxCommand(env);
@@ -1,11 +1,12 @@
1
1
  import * as crypto from "node:crypto";
2
2
  import * as path from "node:path";
3
3
  import { inflateSync } from "node:zlib";
4
-
4
+ import { normalizeGoal } from "../goals/state";
5
+ import { buildSessionContext, loadEntriesFromFile, type SessionEntry } from "../session/session-manager";
5
6
  import type { WorkflowHudSummary } from "../skill-state/active-state";
6
7
  import { buildUltragoalHudSummary as buildWorkflowUltragoalHudSummary } from "../skill-state/workflow-hud";
7
8
  import { renderCliWriteReceipt } from "./cli-write-receipt";
8
- import { DEFAULT_ULTRAGOAL_OBJECTIVE } from "./goal-mode-request";
9
+ import { DEFAULT_ULTRAGOAL_OBJECTIVE, GJC_SESSION_FILE_ENV } from "./goal-mode-request";
9
10
  import { gjcRoot, sessionUltragoalDir } from "./session-layout";
10
11
  import { resolveGjcSessionForRead, resolveGjcSessionForWrite, writeSessionActivityMarker } from "./session-resolution";
11
12
  import { renderUltragoalStatusMarkdown } from "./state-renderer";
@@ -831,6 +832,14 @@ function normalizedEvidenceKind(row: JsonObject): string {
831
832
  function evidenceKindMatches(kind: string, words: string[]): boolean {
832
833
  return words.some(word => kind.includes(word));
833
834
  }
835
+ function formatActualArtifactKinds(artifactIds: string[], kinds: string[]): string {
836
+ if (artifactIds.length === 0) return "none";
837
+ return artifactIds.map((id, index) => `${id}=${kinds[index] ?? "<missing-kind>"}`).join(", ");
838
+ }
839
+
840
+ function formatExpectedKindWords(words: string[]): string {
841
+ return words.map(word => `"${word}"`).join(", ");
842
+ }
834
843
 
835
844
  type SurfaceFamily = "web" | "cli" | "native" | "api-package" | "algorithm-math" | "unknown";
836
845
 
@@ -899,9 +908,18 @@ function categorizeComputerChangePath(value: string): UltragoalChangeCategory {
899
908
  }
900
909
 
901
910
  function isComputerControlSurfaceCategory(category: UltragoalChangeCategory): boolean {
902
- return (
903
- category === "code" || category === "generated-binding" || category === "tool" || category === "settings-registry"
904
- );
911
+ // The computer-use red-team suite is conditional, not universal (see the
912
+ // ultragoal SKILL): require it only when the change actually touches
913
+ // computer-control source — the computer tool (`tool`), its settings/registry
914
+ // wiring (`settings-registry`), or computer Rust (`code`). A bare regeneration
915
+ // of the SHARED native binding (`generated-binding`: packages/natives/native/
916
+ // index.{d.ts,js}) is NOT by itself a computer-use change: that file is
917
+ // generated from Rust, so any real computer-use behavior change must also
918
+ // touch one of the categories above and will still trigger the suite. Treating
919
+ // the regenerated aggregate binding as a computer surface forced the suite on
920
+ // unrelated features (e.g. notifications), which the SKILL explicitly warns
921
+ // against, so it is excluded here.
922
+ return category === "code" || category === "tool" || category === "settings-registry";
905
923
  }
906
924
 
907
925
  function isComputerControlSurfaceChangePath(row: UltragoalChangeSetPath): boolean {
@@ -967,7 +985,7 @@ function validateSurfaceArtifactCompatibility(
967
985
  const hasVisual = kinds.some(kind => evidenceKindMatches(kind, ["screenshot", "image", "visual"]));
968
986
  if (!hasBrowser || !hasVisual) {
969
987
  throw new Error(
970
- `qualityGate ${fieldName} for GUI/web surfaces must reference browser automation plus screenshot or image-verdict artifacts`,
988
+ `qualityGate ${fieldName} for GUI/web surfaces must reference browser automation plus screenshot or image-verdict artifacts; surface "${surface}" expected one artifact kind containing one of ${formatExpectedKindWords(["browser", "playwright", "pandawright", "automation"])} and one containing one of ${formatExpectedKindWords(["screenshot", "image", "visual"])}; actual artifact kinds: ${formatActualArtifactKinds(artifactIds, kinds)}`,
971
989
  );
972
990
  }
973
991
  return;
@@ -994,7 +1012,7 @@ function validateSurfaceArtifactCompatibility(
994
1012
  const expected = surfaceFamilies[family];
995
1013
  if (!kinds.some(kind => evidenceKindMatches(kind, expected.evidence))) {
996
1014
  throw new Error(
997
- `qualityGate ${fieldName} for ${expected.label} surfaces must reference compatible artifact kinds`,
1015
+ `qualityGate ${fieldName} for ${expected.label} surfaces must reference compatible artifact kinds; surface "${surface}" expected at least one artifact kind containing one of ${formatExpectedKindWords(expected.evidence)}; actual artifact kinds: ${formatActualArtifactKinds(artifactIds, kinds)}`,
998
1016
  );
999
1017
  }
1000
1018
  }
@@ -1490,6 +1508,20 @@ function isAllowedCliReplayCommand(command: readonly string[]): boolean {
1490
1508
  if (executable === "gjc") return args.length === 1 && ["read", "status"].includes(args[0] ?? "");
1491
1509
  return false;
1492
1510
  }
1511
+ function summarizeBlockedCliReplayCommand(command: readonly string[]): string {
1512
+ const executable = command[0] ? basenameCommand(command[0]) : "<missing>";
1513
+ const argCount = Math.max(0, command.length - 1);
1514
+ return `${JSON.stringify(executable)} with ${argCount} arg${argCount === 1 ? "" : "s"}`;
1515
+ }
1516
+
1517
+ function cliReplayAllowlistDescription(): string {
1518
+ return [
1519
+ '`bun --version`, `node --version`, or deterministic `bun/node -e "console.log(...)"`',
1520
+ "`npm|pnpm|yarn --version` or `npm|pnpm|yarn list`",
1521
+ "read-only `git status|rev-parse|merge-base|diff|show|log` with safe args",
1522
+ "`gjc read` or `gjc status`",
1523
+ ].join("; ");
1524
+ }
1493
1525
 
1494
1526
  function resolveCliReplayCommand(command: string[]): string[] {
1495
1527
  if (basenameCommand(command[0]!) === "bun") return [process.execPath, ...command.slice(1)];
@@ -1578,8 +1610,11 @@ function parseCliReplayRecord(
1578
1610
  if (!command) throw new Error(`qualityGate ${fieldName}.command must be a non-empty string array`);
1579
1611
  if (record.replaySafe !== true)
1580
1612
  throw new Error(`qualityGate ${fieldName}.replaySafe must be true before CLI replay executes`);
1581
- if (!isAllowedCliReplayCommand(command))
1582
- throw new Error(`qualityGate ${fieldName}.command is not in the conservative CLI replay allowlist`);
1613
+ if (!isAllowedCliReplayCommand(command)) {
1614
+ throw new Error(
1615
+ `qualityGate ${fieldName}.command is not in the conservative CLI replay allowlist; command ${summarizeBlockedCliReplayCommand(command)} is blocked. Allowed replay commands: ${cliReplayAllowlistDescription()}. For other commands, provide audited replayExempt metadata with reasonCode, reason, approvedBy, and fallbackArtifactRefs that point to a structurally valid fallback artifact.`,
1616
+ );
1617
+ }
1583
1618
  if (record.normalization !== undefined && record.normalization !== "default") {
1584
1619
  throw new Error(`qualityGate ${fieldName}.normalization must be default when provided`);
1585
1620
  }
@@ -2231,6 +2266,28 @@ function snapshotUpdatedAtMilliseconds(value: unknown): number | null {
2231
2266
  const parsed = Date.parse(trimmed);
2232
2267
  return Number.isFinite(parsed) ? parsed : null;
2233
2268
  }
2269
+
2270
+ function singleSessionLeafId(entries: readonly SessionEntry[]): string | undefined {
2271
+ if (entries.length === 0) return undefined;
2272
+ const parentIds = new Set(
2273
+ entries.map(entry => entry.parentId).filter((parentId): parentId is string => typeof parentId === "string"),
2274
+ );
2275
+ const leafIds = entries.map(entry => entry.id).filter(id => !parentIds.has(id));
2276
+ return leafIds.length === 1 ? leafIds[0] : undefined;
2277
+ }
2278
+
2279
+ async function readCurrentSessionGjcGoalSnapshot(): Promise<unknown | undefined> {
2280
+ const sessionFile = process.env[GJC_SESSION_FILE_ENV]?.trim();
2281
+ if (!sessionFile) return undefined;
2282
+ const fileEntries = await loadEntriesFromFile(sessionFile);
2283
+ const entries = fileEntries.filter((entry): entry is SessionEntry => entry.type !== "session");
2284
+ const leafId = singleSessionLeafId(entries);
2285
+ if (!leafId) return undefined;
2286
+ const context = buildSessionContext(entries, leafId);
2287
+ if (context.mode !== "goal" && context.mode !== "goal_paused") return undefined;
2288
+ const goal = normalizeGoal(context.modeData?.goal);
2289
+ return goal ? { goal } : undefined;
2290
+ }
2234
2291
  async function readGjcGoalSnapshot(input: {
2235
2292
  cwd: string;
2236
2293
  value: string | undefined;
@@ -2240,13 +2297,15 @@ async function readGjcGoalSnapshot(input: {
2240
2297
  errorPrefix: string;
2241
2298
  allowCompletedLegacyBlocker?: boolean;
2242
2299
  }): Promise<unknown> {
2243
- if (!input.value?.trim()) {
2300
+ const snapshot = input.value?.trim()
2301
+ ? await readStructuredValue(input.cwd, input.value)
2302
+ : await readCurrentSessionGjcGoalSnapshot();
2303
+ if (snapshot === undefined) {
2244
2304
  if (!input.required) return undefined;
2245
2305
  throw new Error(
2246
- `${input.errorPrefix} require --gjc-goal-json from a fresh active goal({"op":"get"}) snapshot; this is the GJC goal-mode receipt, not the .gjc/ultragoal/goals.json goal record`,
2306
+ `${input.errorPrefix} require an active GJC goal-mode snapshot from the current session or --gjc-goal-json; this is the GJC goal-mode receipt, not the .gjc/ultragoal/goals.json goal record`,
2247
2307
  );
2248
2308
  }
2249
- const snapshot = await readStructuredValue(input.cwd, input.value);
2250
2309
  const snapshotObject = qualityGateObject(snapshot);
2251
2310
  const detailsObject = qualityGateObject(snapshotObject?.details);
2252
2311
  const goalObject = qualityGateObject(snapshotObject?.goal) ?? qualityGateObject(detailsObject?.goal);
@@ -3331,18 +3390,19 @@ function renderUltragoalHelp(args: readonly string[]): string | null {
3331
3390
  " --status=<value> pending|active|complete|failed|blocked|review_blocked|superseded",
3332
3391
  " --evidence=<value> Completion or checkpoint evidence text",
3333
3392
  " --quality-gate-json=<value> JSON string or path for complete checkpoints",
3334
- ' --gjc-goal-json=<value> JSON string or path containing the current goal({"op":"get"}) snapshot',
3393
+ " --gjc-goal-json=<value> Optional JSON/path override for current goal snapshot; omitted complete checkpoints read current session goal state",
3335
3394
  " --json Output a machine-readable receipt",
3336
3395
  "",
3337
3396
  "COMPLETE CHECKPOINT RECEIPTS",
3338
3397
  " --quality-gate-json must be an object with architectReview, executorQa, and iteration.",
3339
3398
  " executorQa.contractCoverage[] rows require an obligation field; description is not a substitute.",
3340
- ' --gjc-goal-json must contain the active GJC goal-mode snapshot from goal({"op":"get"}), not the .gjc/ultragoal/goals.json goal record.',
3399
+ " Complete checkpoints use the current session's active GJC goal-mode snapshot when --gjc-goal-json is omitted.",
3400
+ " Explicit --gjc-goal-json values must contain an active GJC goal-mode snapshot, not the .gjc/ultragoal/goals.json goal record.",
3341
3401
  " goal.updatedAt may be epoch milliseconds or an ISO timestamp and must be fresh.",
3342
3402
  "",
3343
3403
  "EXAMPLES",
3344
3404
  ' $ gjc ultragoal checkpoint --goal-id G001 --status blocked --evidence "waiting on review"',
3345
- ' $ gjc ultragoal checkpoint --goal-id G001 --status complete --evidence "tests passed" --gjc-goal-json ./goal.json --quality-gate-json ./quality-gate.json --json',
3405
+ ' $ gjc ultragoal checkpoint --goal-id G001 --status complete --evidence "tests passed" --quality-gate-json ./quality-gate.json --json',
3346
3406
  "",
3347
3407
  ].join("\n");
3348
3408
  }