@gajae-code/coding-agent 0.4.2 → 0.4.3

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 (76) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/types/async/job-manager.d.ts +25 -0
  3. package/dist/types/commit/model-selection.d.ts +1 -1
  4. package/dist/types/config/model-registry.d.ts +3 -1
  5. package/dist/types/config/model-resolver.d.ts +1 -19
  6. package/dist/types/config/models-config-schema.d.ts +12 -0
  7. package/dist/types/config/settings-schema.d.ts +15 -1
  8. package/dist/types/gjc-runtime/goal-mode-request.d.ts +8 -1
  9. package/dist/types/harness-control-plane/types.d.ts +7 -2
  10. package/dist/types/modes/acp/acp-event-mapper.d.ts +2 -0
  11. package/dist/types/modes/components/custom-editor.d.ts +7 -0
  12. package/dist/types/modes/shared/agent-wire/command-contract.d.ts +18 -0
  13. package/dist/types/modes/shared/agent-wire/event-contract.d.ts +84 -0
  14. package/dist/types/modes/shared/agent-wire/event-envelope.d.ts +14 -7
  15. package/dist/types/modes/shared/agent-wire/event-observation.d.ts +37 -0
  16. package/dist/types/modes/shared/agent-wire/protocol.d.ts +13 -34
  17. package/dist/types/session/agent-session.d.ts +12 -1
  18. package/dist/types/session/session-manager.d.ts +1 -1
  19. package/dist/types/tools/bash.d.ts +2 -0
  20. package/dist/types/tools/browser/actions.d.ts +54 -0
  21. package/dist/types/tools/browser.d.ts +80 -0
  22. package/dist/types/tools/image-gen.d.ts +1 -0
  23. package/dist/types/tools/index.d.ts +3 -1
  24. package/dist/types/tools/job.d.ts +1 -1
  25. package/package.json +7 -7
  26. package/src/async/job-manager.ts +120 -1
  27. package/src/commands/ultragoal.ts +7 -1
  28. package/src/commit/agentic/index.ts +2 -2
  29. package/src/commit/model-selection.ts +7 -22
  30. package/src/commit/pipeline.ts +2 -2
  31. package/src/config/model-registry.ts +17 -9
  32. package/src/config/model-resolver.ts +14 -84
  33. package/src/config/models-config-schema.ts +2 -0
  34. package/src/config/settings-schema.ts +14 -1
  35. package/src/gjc-runtime/goal-mode-request.ts +21 -1
  36. package/src/harness-control-plane/owner.ts +3 -3
  37. package/src/harness-control-plane/rpc-adapter.ts +7 -1
  38. package/src/harness-control-plane/types.ts +8 -11
  39. package/src/internal-urls/docs-index.generated.ts +3 -3
  40. package/src/memories/index.ts +1 -1
  41. package/src/modes/acp/acp-agent.ts +17 -9
  42. package/src/modes/acp/acp-event-mapper.ts +33 -1
  43. package/src/modes/components/custom-editor.ts +19 -3
  44. package/src/modes/controllers/input-controller.ts +27 -7
  45. package/src/modes/controllers/selector-controller.ts +7 -1
  46. package/src/modes/interactive-mode.ts +3 -1
  47. package/src/modes/rpc/rpc-client.ts +16 -3
  48. package/src/modes/rpc/rpc-mode.ts +5 -2
  49. package/src/modes/shared/agent-wire/command-contract.ts +18 -0
  50. package/src/modes/shared/agent-wire/event-contract.ts +147 -0
  51. package/src/modes/shared/agent-wire/event-envelope.ts +35 -16
  52. package/src/modes/shared/agent-wire/event-observation.ts +397 -0
  53. package/src/modes/shared/agent-wire/protocol.ts +24 -81
  54. package/src/modes/utils/context-usage.ts +2 -2
  55. package/src/prompts/agents/explore.md +1 -1
  56. package/src/prompts/agents/plan.md +1 -1
  57. package/src/prompts/agents/reviewer.md +1 -1
  58. package/src/prompts/tools/browser.md +3 -2
  59. package/src/runtime-mcp/manager.ts +15 -2
  60. package/src/sdk.ts +3 -1
  61. package/src/session/agent-session.ts +60 -4
  62. package/src/session/session-manager.ts +1 -1
  63. package/src/task/agents.ts +1 -1
  64. package/src/tools/bash.ts +6 -1
  65. package/src/tools/browser/actions.ts +189 -0
  66. package/src/tools/browser.ts +91 -1
  67. package/src/tools/image-gen.ts +42 -15
  68. package/src/tools/index.ts +7 -1
  69. package/src/tools/inspect-image.ts +10 -8
  70. package/src/tools/job.ts +12 -2
  71. package/src/tools/monitor.ts +98 -17
  72. package/src/utils/commit-message-generator.ts +6 -13
  73. package/src/utils/title-generator.ts +1 -1
  74. package/dist/types/harness-control-plane/frame-mapper.d.ts +0 -29
  75. package/src/harness-control-plane/frame-mapper.ts +0 -286
  76. package/src/priority.json +0 -37
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Structured browser action space.
3
+ *
4
+ * Adapts the SOTA computer-use / browser-use pattern: instead of authoring raw
5
+ * JavaScript for every interaction, the model emits a list of structured verbs
6
+ * (navigate / click / type / …) that reference elements by the numeric `id`
7
+ * returned from {@link Observation}. Each verb is compiled onto the existing
8
+ * in-tab `tab.*` helpers and executed through the same worker `run` path, so the
9
+ * worker protocol is unchanged and the raw-JS `run` escape hatch still works.
10
+ */
11
+ export type BrowserActionVerb = "navigate" | "click" | "type" | "fill" | "select" | "press" | "scroll" | "back" | "wait" | "observe" | "extract" | "screenshot";
12
+ export interface BrowserActionStep {
13
+ verb: BrowserActionVerb;
14
+ /** Element id from a prior `observe` (preferred for click/type). */
15
+ id?: number;
16
+ /** CSS / puppeteer selector when not addressing by `id`. */
17
+ selector?: string;
18
+ /** Text to type. */
19
+ text?: string;
20
+ /** Value for `fill`. */
21
+ value?: string;
22
+ /** Option value(s) for `select`. */
23
+ values?: string[];
24
+ /** URL for `navigate`. */
25
+ url?: string;
26
+ /** Key for `press` (e.g. "Enter"). */
27
+ key?: string;
28
+ /** Horizontal scroll delta. */
29
+ dx?: number;
30
+ /** Vertical scroll delta. */
31
+ dy?: number;
32
+ /** Sleep duration for `wait` when no selector is given. */
33
+ ms?: number;
34
+ /** Extract format. */
35
+ format?: "markdown" | "text" | "html";
36
+ /** Navigation wait condition for `navigate`. */
37
+ wait_until?: "load" | "domcontentloaded" | "networkidle0" | "networkidle2";
38
+ /** Only return interactive/viewport elements for `observe`. */
39
+ viewport_only?: boolean;
40
+ include_all?: boolean;
41
+ }
42
+ /**
43
+ * Validate a single step's required fields. Returns an error string, or
44
+ * `undefined` when the step is well-formed.
45
+ */
46
+ export declare function validateActionStep(step: BrowserActionStep, index: number): string | undefined;
47
+ /** Validate the full step list. Throws on the first invalid step. */
48
+ export declare function validateActionSteps(steps: readonly BrowserActionStep[]): void;
49
+ /**
50
+ * Compile structured steps into a JS program for the in-tab `run` worker. Steps
51
+ * are embedded as parsed JSON (no string interpolation, so values cannot inject
52
+ * code) and dispatched by a fixed interpreter against the `tab` / `page` helpers.
53
+ */
54
+ export declare function compileActionSteps(steps: readonly BrowserActionStep[]): string;
@@ -8,6 +8,7 @@ export { extractReadableFromHtml, type ReadableFormat, type ReadableResult } fro
8
8
  export type { Observation, ObservationEntry } from "./browser/tab-protocol";
9
9
  declare const browserSchema: z.ZodObject<{
10
10
  action: z.ZodEnum<{
11
+ act: "act";
11
12
  close: "close";
12
13
  open: "open";
13
14
  run: "run";
@@ -36,6 +37,45 @@ declare const browserSchema: z.ZodObject<{
36
37
  dismiss: "dismiss";
37
38
  }>>;
38
39
  code: z.ZodOptional<z.ZodString>;
40
+ actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
41
+ verb: z.ZodEnum<{
42
+ back: "back";
43
+ click: "click";
44
+ extract: "extract";
45
+ fill: "fill";
46
+ navigate: "navigate";
47
+ observe: "observe";
48
+ press: "press";
49
+ screenshot: "screenshot";
50
+ scroll: "scroll";
51
+ select: "select";
52
+ type: "type";
53
+ wait: "wait";
54
+ }>;
55
+ id: z.ZodOptional<z.ZodNumber>;
56
+ selector: z.ZodOptional<z.ZodString>;
57
+ text: z.ZodOptional<z.ZodString>;
58
+ value: z.ZodOptional<z.ZodString>;
59
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
60
+ url: z.ZodOptional<z.ZodString>;
61
+ key: z.ZodOptional<z.ZodString>;
62
+ dx: z.ZodOptional<z.ZodNumber>;
63
+ dy: z.ZodOptional<z.ZodNumber>;
64
+ ms: z.ZodOptional<z.ZodNumber>;
65
+ format: z.ZodOptional<z.ZodEnum<{
66
+ html: "html";
67
+ markdown: "markdown";
68
+ text: "text";
69
+ }>>;
70
+ wait_until: z.ZodOptional<z.ZodEnum<{
71
+ domcontentloaded: "domcontentloaded";
72
+ load: "load";
73
+ networkidle0: "networkidle0";
74
+ networkidle2: "networkidle2";
75
+ }>>;
76
+ viewport_only: z.ZodOptional<z.ZodBoolean>;
77
+ include_all: z.ZodOptional<z.ZodBoolean>;
78
+ }, z.core.$strip>>>;
39
79
  timeout: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
40
80
  all: z.ZodOptional<z.ZodBoolean>;
41
81
  kill: z.ZodOptional<z.ZodBoolean>;
@@ -73,6 +113,7 @@ export declare class BrowserTool implements AgentTool<typeof browserSchema, Brow
73
113
  readonly summary = "Control a headless browser to navigate and interact with web pages";
74
114
  readonly parameters: z.ZodObject<{
75
115
  action: z.ZodEnum<{
116
+ act: "act";
76
117
  close: "close";
77
118
  open: "open";
78
119
  run: "run";
@@ -101,6 +142,45 @@ export declare class BrowserTool implements AgentTool<typeof browserSchema, Brow
101
142
  dismiss: "dismiss";
102
143
  }>>;
103
144
  code: z.ZodOptional<z.ZodString>;
145
+ actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
146
+ verb: z.ZodEnum<{
147
+ back: "back";
148
+ click: "click";
149
+ extract: "extract";
150
+ fill: "fill";
151
+ navigate: "navigate";
152
+ observe: "observe";
153
+ press: "press";
154
+ screenshot: "screenshot";
155
+ scroll: "scroll";
156
+ select: "select";
157
+ type: "type";
158
+ wait: "wait";
159
+ }>;
160
+ id: z.ZodOptional<z.ZodNumber>;
161
+ selector: z.ZodOptional<z.ZodString>;
162
+ text: z.ZodOptional<z.ZodString>;
163
+ value: z.ZodOptional<z.ZodString>;
164
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
165
+ url: z.ZodOptional<z.ZodString>;
166
+ key: z.ZodOptional<z.ZodString>;
167
+ dx: z.ZodOptional<z.ZodNumber>;
168
+ dy: z.ZodOptional<z.ZodNumber>;
169
+ ms: z.ZodOptional<z.ZodNumber>;
170
+ format: z.ZodOptional<z.ZodEnum<{
171
+ html: "html";
172
+ markdown: "markdown";
173
+ text: "text";
174
+ }>>;
175
+ wait_until: z.ZodOptional<z.ZodEnum<{
176
+ domcontentloaded: "domcontentloaded";
177
+ load: "load";
178
+ networkidle0: "networkidle0";
179
+ networkidle2: "networkidle2";
180
+ }>>;
181
+ viewport_only: z.ZodOptional<z.ZodBoolean>;
182
+ include_all: z.ZodOptional<z.ZodBoolean>;
183
+ }, z.core.$strip>>>;
104
184
  timeout: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
105
185
  all: z.ZodOptional<z.ZodBoolean>;
106
186
  kill: z.ZodOptional<z.ZodBoolean>;
@@ -72,6 +72,7 @@ interface InlineImageData {
72
72
  }
73
73
  /** Set the preferred image provider from settings */
74
74
  export declare function setPreferredImageProvider(provider: ImageProvider | "auto"): void;
75
+ export declare function isOpenAIHostedImageModel(model: Model | undefined): model is Model;
75
76
  export declare const imageGenTool: CustomTool<typeof imageGenSchema, ImageGenToolDetails>;
76
77
  export declare function getImageGenTools(modelRegistry?: ModelRegistry, activeModel?: Model): Promise<Array<CustomTool<typeof imageGenSchema, ImageGenToolDetails>>>;
77
78
  export declare function getImageGenToolsWithRegistry(modelRegistry: ModelRegistry, activeModel?: Model): Promise<Array<CustomTool<typeof imageGenSchema, ImageGenToolDetails>>>;
@@ -8,7 +8,7 @@ import type { HindsightSessionState } from "../hindsight/state";
8
8
  import type { WorkflowGateEmitter } from "../modes/shared/agent-wire/unattended-session";
9
9
  import type { PlanModeState } from "../plan-mode/state";
10
10
  import type { AgentRegistry } from "../registry/agent-registry";
11
- import type { ForkContextSeed, ForkContextSeedOptions } from "../session/agent-session";
11
+ import type { ForkContextSeed, ForkContextSeedOptions, PurgeQueuedCustomMessagesResult } from "../session/agent-session";
12
12
  import type { ArtifactManager } from "../session/artifacts";
13
13
  import type { ClientBridge } from "../session/client-bridge";
14
14
  import type { CustomMessage } from "../session/messages";
@@ -117,6 +117,8 @@ export interface ToolSession {
117
117
  /** Agent identity used for IRC routing. Returns the registry id (e.g. "0-Main", "0-AuthLoader"). */
118
118
  getAgentId?: () => string | null;
119
119
  /** Look up a registered tool by name (used by the eval js backend's tool bridge). */
120
+ /** Purge undelivered queued custom messages matching the predicate. Returns counts. */
121
+ purgeQueuedCustomMessages?: (predicate: (message: CustomMessage) => boolean) => PurgeQueuedCustomMessagesResult;
120
122
  getToolByName?: (name: string) => AgentTool | undefined;
121
123
  /** Agent registry for IRC routing across live sessions. */
122
124
  agentRegistry?: AgentRegistry;
@@ -19,7 +19,7 @@ interface JobSnapshot {
19
19
  resultText?: string;
20
20
  errorText?: string;
21
21
  }
22
- type CancelStatus = "cancelled" | "not_found" | "already_completed";
22
+ type CancelStatus = "cancelled" | "not_found" | "already_completed" | "already_cancelled";
23
23
  export interface JobToolDetails {
24
24
  jobs: JobSnapshot[];
25
25
  cancelled?: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@gajae-code/coding-agent",
4
- "version": "0.4.2",
4
+ "version": "0.4.3",
5
5
  "description": "Gajae Code CLI with read, bash, edit, write tools and session management",
6
6
  "homepage": "https://gaebal-gajae.dev",
7
7
  "author": "Yeachan-Heo",
@@ -50,12 +50,12 @@
50
50
  "@agentclientprotocol/sdk": "0.21.0",
51
51
  "@babel/parser": "^7.29.3",
52
52
  "@mozilla/readability": "^0.6.0",
53
- "@gajae-code/stats": "0.4.2",
54
- "@gajae-code/agent-core": "0.4.2",
55
- "@gajae-code/ai": "0.4.2",
56
- "@gajae-code/natives": "0.4.2",
57
- "@gajae-code/tui": "0.4.2",
58
- "@gajae-code/utils": "0.4.2",
53
+ "@gajae-code/stats": "0.4.3",
54
+ "@gajae-code/agent-core": "0.4.3",
55
+ "@gajae-code/ai": "0.4.3",
56
+ "@gajae-code/natives": "0.4.3",
57
+ "@gajae-code/tui": "0.4.3",
58
+ "@gajae-code/utils": "0.4.3",
59
59
  "@puppeteer/browsers": "^2.13.0",
60
60
  "@types/turndown": "5.0.6",
61
61
  "@xterm/headless": "^6.0.0",
@@ -6,6 +6,7 @@ const DELIVERY_RETRY_MAX_MS = 30_000;
6
6
  const DELIVERY_RETRY_JITTER_MS = 200;
7
7
  const DEFAULT_RETENTION_MS = 5 * 60 * 1000;
8
8
  const DEFAULT_MAX_RUNNING_JOBS = 15;
9
+ const MONITOR_TOMBSTONE_TTL_MS = 5 * 60_000;
9
10
 
10
11
  export interface AsyncJob {
11
12
  id: string;
@@ -120,6 +121,27 @@ export interface AsyncJobDeliveryState {
120
121
  pendingJobIds: string[];
121
122
  }
122
123
 
124
+ export interface AsyncJobLifecycleCleanup {
125
+ onCancel?: (job: AsyncJob) => void;
126
+ onTerminal?: (job: AsyncJob) => void;
127
+ onEvict?: (job: AsyncJob) => void;
128
+ /**
129
+ * Idempotent residual cleanup invoked by a post-eviction tombstone purge
130
+ * (e.g. a late `job cancel` after the job left the registry). Kept distinct
131
+ * from the at-most-once lifecycle phases so a tombstone purge never has to
132
+ * re-invoke a phase hook. Must be safe to call repeatedly.
133
+ */
134
+ onTombstonePurge?: (job: AsyncJob) => void;
135
+ }
136
+
137
+ export interface MonitorTombstone {
138
+ jobId: string;
139
+ ownerId?: string;
140
+ status: AsyncJob["status"];
141
+ expiresAt: number;
142
+ purge: () => unknown;
143
+ }
144
+
123
145
  export interface AsyncJobRegisterOptions {
124
146
  id?: string;
125
147
  /** Registry id of the agent that owns this job; used to scope cancelAll. */
@@ -127,6 +149,7 @@ export interface AsyncJobRegisterOptions {
127
149
  /** Structured metadata for tool-specific control surfaces. */
128
150
  metadata?: AsyncJobMetadata;
129
151
  onProgress?: (text: string, details?: Record<string, unknown>) => void | Promise<void>;
152
+ lifecycle?: AsyncJobLifecycleCleanup;
130
153
  }
131
154
 
132
155
  /**
@@ -214,6 +237,9 @@ export class AsyncJobManager {
214
237
  readonly #evictionTimers = new Map<string, NodeJS.Timeout>();
215
238
  readonly #outputState = new Map<string, AsyncJobOutputState>();
216
239
  readonly #ownerCleanups = new Map<string, Set<() => void>>();
240
+ readonly #lifecycles = new Map<string, AsyncJobLifecycleCleanup>();
241
+ readonly #lifecyclePhases = new Map<string, Set<"cancel" | "terminal" | "evict">>();
242
+ readonly #monitorTombstones = new Map<string, MonitorTombstone>();
217
243
  readonly #outputRetentionBytes = DEFAULT_JOB_OUTPUT_RETENTION_BYTES;
218
244
  readonly #onJobComplete: AsyncJobManagerOptions["onJobComplete"];
219
245
  readonly #maxRunningJobs: number;
@@ -292,6 +318,7 @@ export class AsyncJobManager {
292
318
  );
293
319
  }
294
320
 
321
+ this.#expireMonitorTombstones();
295
322
  const id = this.#resolveJobId(options?.id);
296
323
  this.#suppressedDeliveries.delete(id);
297
324
  const abortController = new AbortController();
@@ -308,6 +335,7 @@ export class AsyncJobManager {
308
335
  ownerId: options?.ownerId,
309
336
  metadata: options?.metadata,
310
337
  };
338
+ if (options?.lifecycle) this.#lifecycles.set(id, options.lifecycle);
311
339
 
312
340
  const reportProgress = async (text: string, details?: Record<string, unknown>): Promise<void> => {
313
341
  if (!options?.onProgress) return;
@@ -325,8 +353,10 @@ export class AsyncJobManager {
325
353
  const result = await run({ jobId: id, signal: abortController.signal, reportProgress });
326
354
  const outcome: SubagentRunOutcome =
327
355
  typeof result === "string" ? { kind: "completed", text: result } : result;
356
+
328
357
  if (job.status === "cancelled") {
329
358
  job.resultText = outcome.kind === "completed" ? outcome.text : outcome.note;
359
+ this.#runLifecycle(id, "terminal");
330
360
  this.#scheduleEviction(id);
331
361
  this.#markRecordTerminal(id, "cancelled");
332
362
  this.#drainResumeQueue();
@@ -342,20 +372,24 @@ export class AsyncJobManager {
342
372
  this.#drainResumeQueue();
343
373
  return;
344
374
  }
375
+
345
376
  job.status = "completed";
346
377
  job.resultText = outcome.text;
347
378
  this.#enqueueDelivery(id, outcome.text);
379
+ this.#runLifecycle(id, "terminal");
348
380
  this.#scheduleEviction(id);
349
381
  this.#markRecordTerminal(id, "completed");
350
382
  this.#drainResumeQueue();
351
383
  } catch (error) {
352
384
  if (job.status === "cancelled") {
353
385
  job.errorText = error instanceof Error ? error.message : String(error);
386
+ this.#runLifecycle(id, "terminal");
354
387
  this.#scheduleEviction(id);
355
388
  this.#markRecordTerminal(id, "cancelled");
356
389
  this.#drainResumeQueue();
357
390
  return;
358
391
  }
392
+ this.#runLifecycle(id, "terminal");
359
393
  const errorText = error instanceof Error ? error.message : String(error);
360
394
  job.status = "failed";
361
395
  job.errorText = errorText;
@@ -381,6 +415,7 @@ export class AsyncJobManager {
381
415
  if (!job) return false;
382
416
  if (filter?.ownerId && job.ownerId !== filter.ownerId) return false;
383
417
  if (job.status === "paused") {
418
+ this.#runLifecycle(id, "cancel");
384
419
  // Paused jobs have no running promise to abort; transition directly.
385
420
  // The session file is kept, so the record stays resumable by id.
386
421
  job.status = "cancelled";
@@ -390,12 +425,76 @@ export class AsyncJobManager {
390
425
  return true;
391
426
  }
392
427
  if (job.status !== "running") return false;
428
+ this.#runLifecycle(id, "cancel");
393
429
  job.status = "cancelled";
394
430
  job.abortController.abort();
395
- this.#scheduleEviction(id);
396
431
  return true;
397
432
  }
398
433
 
434
+ #runLifecycle(jobId: string, phase: "cancel" | "terminal" | "evict"): void {
435
+ const fired = this.#lifecyclePhases.get(jobId) ?? new Set<"cancel" | "terminal" | "evict">();
436
+ if (fired.has(phase)) return;
437
+ fired.add(phase);
438
+ this.#lifecyclePhases.set(jobId, fired);
439
+ const lifecycle = this.#lifecycles.get(jobId);
440
+ const job = this.#jobs.get(jobId);
441
+ if (!lifecycle || !job) return;
442
+ try {
443
+ if (phase === "cancel") lifecycle.onCancel?.(job);
444
+ else if (phase === "terminal") lifecycle.onTerminal?.(job);
445
+ else lifecycle.onEvict?.(job);
446
+ } catch (error) {
447
+ logger.warn("Async job lifecycle cleanup failed", {
448
+ jobId,
449
+ phase,
450
+ error: error instanceof Error ? error.message : String(error),
451
+ });
452
+ }
453
+ }
454
+
455
+ #expireMonitorTombstones(): void {
456
+ const now = Date.now();
457
+ for (const [jobId, tombstone] of this.#monitorTombstones) {
458
+ if (tombstone.expiresAt <= now) this.#monitorTombstones.delete(jobId);
459
+ }
460
+ }
461
+
462
+ #recordMonitorTombstone(jobId: string): void {
463
+ const job = this.#jobs.get(jobId);
464
+ if (!job?.metadata?.monitor) return;
465
+ const lifecycle = this.#lifecycles.get(jobId);
466
+ this.#monitorTombstones.set(jobId, {
467
+ jobId,
468
+ ownerId: job.ownerId,
469
+ status: job.status,
470
+ expiresAt: Date.now() + MONITOR_TOMBSTONE_TTL_MS,
471
+ purge: () => (lifecycle?.onTombstonePurge ?? lifecycle?.onEvict)?.(job),
472
+ });
473
+ }
474
+
475
+ getMonitorTombstone(jobId: string, filter?: AsyncJobFilter): MonitorTombstone | undefined {
476
+ this.#expireMonitorTombstones();
477
+ const tombstone = this.#monitorTombstones.get(jobId);
478
+ if (!tombstone) return undefined;
479
+ if (filter?.ownerId && tombstone.ownerId !== filter.ownerId) return undefined;
480
+ return tombstone;
481
+ }
482
+
483
+ purgeMonitorTombstone(jobId: string, filter?: AsyncJobFilter): { found: boolean; status?: AsyncJob["status"] } {
484
+ const tombstone = this.getMonitorTombstone(jobId, filter);
485
+ if (!tombstone) return { found: false };
486
+ this.#monitorTombstones.delete(jobId);
487
+ try {
488
+ tombstone.purge();
489
+ } catch (error) {
490
+ logger.warn("Monitor tombstone purge failed", {
491
+ jobId,
492
+ error: error instanceof Error ? error.message : String(error),
493
+ });
494
+ }
495
+ return { found: true, status: tombstone.status };
496
+ }
497
+
399
498
  // ── Subagent control plane (pause / resume / steer support) ──────────
400
499
 
401
500
  /** Register or replace the canonical record for a subagent. */
@@ -836,6 +935,7 @@ export class AsyncJobManager {
836
935
  */
837
936
  cancelAll(filter?: AsyncJobFilter): void {
838
937
  for (const job of this.getRunningJobs(filter)) {
938
+ this.#runLifecycle(job.id, "cancel");
839
939
  job.status = "cancelled";
840
940
  job.abortController.abort();
841
941
  this.#scheduleEviction(job.id);
@@ -898,6 +998,17 @@ export class AsyncJobManager {
898
998
  // manager. Errors in cleanup callbacks are logged but never escalated.
899
999
  this.runOwnerCleanups();
900
1000
  this.cancelAll();
1001
+ for (const tombstone of this.#monitorTombstones.values()) {
1002
+ try {
1003
+ tombstone.purge();
1004
+ } catch (error) {
1005
+ logger.warn("Monitor tombstone purge failed during dispose", {
1006
+ jobId: tombstone.jobId,
1007
+ error: error instanceof Error ? error.message : String(error),
1008
+ });
1009
+ }
1010
+ }
1011
+ this.#monitorTombstones.clear();
901
1012
  await this.waitForAll();
902
1013
  const drained = await this.drainDeliveries({ timeoutMs: options?.timeoutMs ?? 3_000 });
903
1014
  this.#clearEvictionTimers();
@@ -945,7 +1056,11 @@ export class AsyncJobManager {
945
1056
  #scheduleEviction(jobId: string): void {
946
1057
  this.#notifyChange();
947
1058
  if (this.#retentionMs <= 0) {
1059
+ this.#recordMonitorTombstone(jobId);
1060
+ this.#runLifecycle(jobId, "evict");
948
1061
  this.#jobs.delete(jobId);
1062
+ this.#lifecycles.delete(jobId);
1063
+ this.#lifecyclePhases.delete(jobId);
949
1064
  this.#suppressedDeliveries.delete(jobId);
950
1065
  this.#watchedJobs.delete(jobId);
951
1066
  this.#outputState.delete(jobId);
@@ -957,7 +1072,11 @@ export class AsyncJobManager {
957
1072
  }
958
1073
  const timer = setTimeout(() => {
959
1074
  this.#evictionTimers.delete(jobId);
1075
+ this.#recordMonitorTombstone(jobId);
1076
+ this.#runLifecycle(jobId, "evict");
960
1077
  this.#jobs.delete(jobId);
1078
+ this.#lifecycles.delete(jobId);
1079
+ this.#lifecyclePhases.delete(jobId);
961
1080
  this.#suppressedDeliveries.delete(jobId);
962
1081
  this.#watchedJobs.delete(jobId);
963
1082
  this.#outputState.delete(jobId);
@@ -1,6 +1,7 @@
1
1
  import { Command } from "@gajae-code/utils/cli";
2
2
  import {
3
3
  GJC_SESSION_FILE_ENV,
4
+ GJC_SESSION_ID_ENV,
4
5
  isUltragoalCreateGoalsInvocation,
5
6
  readUltragoalGjcObjective,
6
7
  writeCurrentSessionGoalModeState,
@@ -28,6 +29,11 @@ export default class Ultragoal extends Command {
28
29
  sessionFile: process.env[GJC_SESSION_FILE_ENV],
29
30
  objective,
30
31
  });
31
- await writePendingGoalModeRequest({ cwd, objective, goalsPath });
32
+ await writePendingGoalModeRequest({
33
+ cwd,
34
+ objective,
35
+ goalsPath,
36
+ sessionId: process.env[GJC_SESSION_ID_ENV],
37
+ });
32
38
  }
33
39
  }
@@ -5,7 +5,7 @@ import { applyChangelogProposals } from "../../commit/changelog";
5
5
  import { detectChangelogBoundaries } from "../../commit/changelog/detect";
6
6
  import { parseUnreleasedSection } from "../../commit/changelog/parse";
7
7
  import { formatCommitMessage } from "../../commit/message";
8
- import { resolvePrimaryModel, resolveSmolModel } from "../../commit/model-selection";
8
+ import { resolvePrimaryModel, resolveSecondaryCommitModel } from "../../commit/model-selection";
9
9
  import type { CommitCommandArgs, ConventionalAnalysis } from "../../commit/types";
10
10
  import { ModelRegistry } from "../../config/model-registry";
11
11
  import { Settings } from "../../config/settings";
@@ -47,7 +47,7 @@ export async function runAgenticCommit(args: CommitCommandArgs): Promise<void> {
47
47
  const { model: primaryModel, apiKey: primaryApiKey } = primaryModelResult;
48
48
  process.stdout.write(` └─ ${primaryModel.name}\n`);
49
49
 
50
- const { model: agentModel, thinkingLevel: agentThinkingLevel } = await resolveSmolModel(
50
+ const { model: agentModel, thinkingLevel: agentThinkingLevel } = await resolveSecondaryCommitModel(
51
51
  settings,
52
52
  modelRegistry,
53
53
  primaryModel,
@@ -1,14 +1,7 @@
1
1
  import type { ThinkingLevel } from "@gajae-code/agent-core";
2
2
  import type { Api, Model } from "@gajae-code/ai";
3
- import { MODEL_ROLE_IDS } from "../config/model-registry";
4
- import {
5
- type ModelLookupRegistry,
6
- parseModelPattern,
7
- resolveModelRoleValue,
8
- resolveRoleSelection,
9
- } from "../config/model-resolver";
3
+ import { type ModelLookupRegistry, resolveModelRoleValue, resolveRoleSelection } from "../config/model-resolver";
10
4
  import type { Settings } from "../config/settings";
11
- import MODEL_PRIO from "../priority.json" with { type: "json" };
12
5
 
13
6
  export interface ResolvedCommitModel {
14
7
  model: Model<Api>;
@@ -29,7 +22,7 @@ export async function resolvePrimaryModel(
29
22
  const matchPreferences = { usageOrder: settings.getStorage()?.getModelUsageOrder() };
30
23
  const resolved = override
31
24
  ? resolveModelRoleValue(override, available, { settings, matchPreferences, modelRegistry })
32
- : resolveRoleSelection(["commit", "smol", ...MODEL_ROLE_IDS], settings, available, modelRegistry);
25
+ : resolveRoleSelection(["default"], settings, available, modelRegistry);
33
26
  const model = resolved?.model;
34
27
  if (!model) {
35
28
  throw new Error("No model available for commit generation");
@@ -41,25 +34,17 @@ export async function resolvePrimaryModel(
41
34
  return { model, apiKey, thinkingLevel: resolved?.thinkingLevel };
42
35
  }
43
36
 
44
- export async function resolveSmolModel(
37
+ export async function resolveSecondaryCommitModel(
45
38
  settings: Settings,
46
39
  modelRegistry: CommitModelRegistry,
47
40
  fallbackModel: Model<Api>,
48
41
  fallbackApiKey: string,
49
42
  ): Promise<ResolvedCommitModel> {
50
43
  const available = modelRegistry.getAvailable();
51
- const resolvedSmol = resolveRoleSelection(["smol"], settings, available, modelRegistry);
52
- if (resolvedSmol?.model) {
53
- const apiKey = await modelRegistry.getApiKey(resolvedSmol.model);
54
- if (apiKey) return { model: resolvedSmol.model, apiKey, thinkingLevel: resolvedSmol.thinkingLevel };
55
- }
56
-
57
- const matchPreferences = { usageOrder: settings.getStorage()?.getModelUsageOrder() };
58
- for (const pattern of MODEL_PRIO.smol) {
59
- const candidate = parseModelPattern(pattern, available, matchPreferences, { modelRegistry }).model;
60
- if (!candidate) continue;
61
- const apiKey = await modelRegistry.getApiKey(candidate);
62
- if (apiKey) return { model: candidate, apiKey };
44
+ const resolved = resolveRoleSelection(["default"], settings, available, modelRegistry);
45
+ if (resolved?.model) {
46
+ const apiKey = await modelRegistry.getApiKey(resolved.model);
47
+ if (apiKey) return { model: resolved.model, apiKey, thinkingLevel: resolved.thinkingLevel };
63
48
  }
64
49
 
65
50
  return { model: fallbackModel, apiKey: fallbackApiKey };
@@ -18,7 +18,7 @@ import {
18
18
  import { runChangelogFlow } from "./changelog";
19
19
  import { runMapReduceAnalysis, shouldUseMapReduce } from "./map-reduce";
20
20
  import { formatCommitMessage } from "./message";
21
- import { resolvePrimaryModel, resolveSmolModel } from "./model-selection";
21
+ import { resolvePrimaryModel, resolveSecondaryCommitModel } from "./model-selection";
22
22
  import summaryRetryPrompt from "./prompts/summary-retry.md" with { type: "text" };
23
23
  import typesDescriptionPrompt from "./prompts/types-description.md" with { type: "text" };
24
24
  import type { CommitCommandArgs, ConventionalAnalysis } from "./types";
@@ -56,7 +56,7 @@ async function runLegacyCommitCommand(args: CommitCommandArgs): Promise<void> {
56
56
  model: smolModel,
57
57
  apiKey: smolApiKey,
58
58
  thinkingLevel: smolThinkingLevel,
59
- } = await resolveSmolModel(settings, modelRegistry, primaryModel, primaryApiKey);
59
+ } = await resolveSecondaryCommitModel(settings, modelRegistry, primaryModel, primaryApiKey);
60
60
 
61
61
  let stagedFiles = await git.diff.changedFiles(cwd, { cached: true });
62
62
  if (stagedFiles.length === 0) {