@sorenllm/opencode-forge 0.6.0 → 0.7.0

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 (3) hide show
  1. package/README.md +21 -14
  2. package/dist/index.js +37 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -257,12 +257,12 @@ Subagents have it worse: the native task tool has no timeout at all.
257
257
  exit condition is bound to the actual exit event (structural immunity to
258
258
  the stdio-EOF bug):
259
259
 
260
- | condition | knob | on trigger |
261
- | --- | --- | --- |
262
- | process exit | — | final; exit code + output tail returned |
263
- | `success_pattern` regex matches new output | opt-in | completes as success; process kept alive by default (server semantics), `keep_alive: false` kills its tree |
264
- | `idle_ms` with no new output | default 60000 | early return `still-running` + `jobId`; process stays alive |
265
- | `max_wait_ms` hard cap | default 120000, max 600000 | early return `still-running`; never kills |
260
+ | condition | knob | on trigger | completion behavior |
261
+ | --- | --- | --- | --- |
262
+ | process exit | — | final; exit code + output tail returned | **terminal evidence** — output delivered in full; the job self-clears from the registry (no wake, no clear needed) |
263
+ | `success_pattern` regex matches new output | opt-in | completes as success; process kept alive by default (server semantics), `keep_alive: false` kills its tree | kept alive → later exit still wakes (the server dying is real news); killed inline → self-clears |
264
+ | `idle_ms` with no new output | default 60000 | early return `still-running` + `jobId`; process stays alive | later exit queues a wake; entry stays listed until cleared |
265
+ | `max_wait_ms` hard cap | default 120000, max 600000 | early return `still-running`; never kills | same as idle |
266
266
 
267
267
  `run_in_background: true` skips all waiting and returns
268
268
  `{jobId, logPath}` immediately. Every run pops one permission dialog
@@ -274,14 +274,21 @@ disagrees with that line, the line wins.
274
274
  **`forge_jobs`** manages the registry: `list` / `poll {jobId, waitMs≤30s}`
275
275
  (bounded wait for new output or exit, drains it) / `log {jobId, offset?,
276
276
  limit?}` (line paging over the on-disk log) / `kill` (whole process tree) /
277
- `clear` (drop a finished entry) / `handoff` (rebind ownership to the root
278
- session so a subagent's job survives the subagent). Delegated agents are
279
- instructed to poll their jobs before yielding a conclusion.
280
-
281
- **Exit wakes.** A job that exits after its `forge_shell` call already
282
- returned queues a single `[forge:job-complete]` message, delivered into the
283
- owning session via `promptAsync` the next time it goes idle (exactly once;
284
- `notify: false` opts out per job).
277
+ `clear` (drop a finished entry — only early-returned/background jobs need
278
+ this; synchronously consumed jobs self-clear at completion) / `handoff`
279
+ (rebind ownership to the root session so a subagent's job survives the
280
+ subagent). Delegated agents are instructed to poll their jobs before
281
+ yielding a conclusion.
282
+
283
+ **Exit wakes.** A job whose caller last saw it before completion —
284
+ `run_in_background` starts and `still-running`/kept-alive `success` early
285
+ returns — queues a single `[forge:job-complete]` message when it finishes,
286
+ delivered into the owning session via `promptAsync` the next time it goes
287
+ idle (exactly once; `notify: false` opts out per job). A foreground call
288
+ resolved on the exit event is terminal evidence: the caller already holds
289
+ the complete output, so no wake fires and the registry entry self-clears —
290
+ a stale `poll`/`kill`/`clear` on such an id answers "already consumed"
291
+ instead of "unknown job".
285
292
 
286
293
  **Ownership.** Jobs belong to the session that created them. Session
287
294
  deleted → its live session-scoped jobs are killed and the event is recorded
package/dist/index.js CHANGED
@@ -13416,12 +13416,30 @@ function createJobManager(opts = {}) {
13416
13416
  job.state = state;
13417
13417
  job.exitCode = exitCode;
13418
13418
  job.endedAt = now();
13419
- if (job.notify && job.wakeState === "none") {
13419
+ if (job.notify && job.wakeState === "none" && !job.terminalEvidence) {
13420
13420
  job.wakeState = "queued";
13421
13421
  job.wakeQueuedAt = now();
13422
13422
  }
13423
+ if (job.terminalEvidence) {
13424
+ jobs.delete(job.id);
13425
+ rememberConsumed(job.id);
13426
+ }
13423
13427
  enforceCaps();
13424
13428
  }
13429
+ const consumedIds = new Set;
13430
+ function rememberConsumed(id) {
13431
+ if (consumedIds.has(id))
13432
+ return;
13433
+ consumedIds.add(id);
13434
+ if (consumedIds.size > maxFinishedJobs) {
13435
+ const oldest = consumedIds.values().next().value;
13436
+ if (oldest !== undefined)
13437
+ consumedIds.delete(oldest);
13438
+ }
13439
+ }
13440
+ function consumed(id) {
13441
+ return consumedIds.has(id);
13442
+ }
13425
13443
  function kill(job) {
13426
13444
  if (isTerminal2(job))
13427
13445
  return;
@@ -13533,6 +13551,7 @@ function createJobManager(opts = {}) {
13533
13551
  deliverWakesFor,
13534
13552
  abandonStaleWakes,
13535
13553
  ledgerEntries,
13554
+ consumed,
13536
13555
  size: () => jobs.size
13537
13556
  };
13538
13557
  }
@@ -13640,6 +13659,11 @@ function startJob(manager, opts) {
13640
13659
  clearTimeout(maxWaitTimer);
13641
13660
  };
13642
13661
  const firstOutputHooks = [];
13662
+ const foregroundWatch = !opts.runInBackground;
13663
+ const stampTerminalEvidence = () => {
13664
+ if (foregroundWatch && !settled)
13665
+ job.terminalEvidence = true;
13666
+ };
13643
13667
  function resolveStillRunning() {
13644
13668
  if (settled)
13645
13669
  return;
@@ -13675,6 +13699,7 @@ function startJob(manager, opts) {
13675
13699
  closeSync(wfd);
13676
13700
  } catch {}
13677
13701
  }
13702
+ stampTerminalEvidence();
13678
13703
  manager.markTerminal(job, "killed", null);
13679
13704
  maxWaitTimer && clearTimeout(maxWaitTimer);
13680
13705
  resolveSettle({ status: "exited", exitCode: null, outputTail: "", spawnError: String(err) });
@@ -13726,6 +13751,8 @@ function startJob(manager, opts) {
13726
13751
  killTree(child);
13727
13752
  if (opts.survive)
13728
13753
  opts.registry?.remove(id);
13754
+ if (foregroundWatch)
13755
+ job.terminalEvidence = true;
13729
13756
  manager.markTerminal(job, "succeeded", null);
13730
13757
  }
13731
13758
  resolveSettle({ status: "succeeded", matched: m[0], outputTail: job.tail, keptAlive });
@@ -13747,6 +13774,7 @@ function startJob(manager, opts) {
13747
13774
  tail.flush();
13748
13775
  tail.stop();
13749
13776
  liveTails.delete(id);
13777
+ stampTerminalEvidence();
13750
13778
  manager.markTerminal(job, "exited", code);
13751
13779
  if (opts.survive)
13752
13780
  opts.registry?.remove(id);
@@ -13765,6 +13793,7 @@ function startJob(manager, opts) {
13765
13793
  if (opts.survive)
13766
13794
  opts.registry?.remove(id);
13767
13795
  if (!settled) {
13796
+ stampTerminalEvidence();
13768
13797
  settled = true;
13769
13798
  stopTimers();
13770
13799
  manager.markTerminal(job, "killed", null);
@@ -16169,6 +16198,8 @@ var forgeShellTool = tool({
16169
16198
  output: [
16170
16199
  `[forge:job] Command finished (exit=${r.exitCode ?? "none"}).`,
16171
16200
  `cwd: ${cwd}`,
16201
+ `jobId: ${started.job.id}`,
16202
+ `Output was delivered in full above — terminal evidence: the job self-cleared from the registry (no wake fires, no forge_jobs clear needed).`,
16172
16203
  ...r.spawnError ? [`spawn error: ${r.spawnError}`] : [],
16173
16204
  `output:
16174
16205
  ${r.outputTail || "(none)"}`
@@ -16182,7 +16213,7 @@ ${r.outputTail || "(none)"}`
16182
16213
  output: [
16183
16214
  `[forge:job] Success pattern matched: "${r.matched}".`,
16184
16215
  `cwd: ${cwd}`,
16185
- r.keptAlive ? `The process was kept alive as job ${started.job.id} (stop it with forge_jobs kill when done).` : "The process tree was terminated (keep_alive=false).",
16216
+ r.keptAlive ? `The process was kept alive as job ${started.job.id} (stop it with forge_jobs kill when done).` : `The process tree was terminated (keep_alive=false) — terminal evidence: job ${started.job.id} self-cleared from the registry (no wake, no clear needed).`,
16186
16217
  `output:
16187
16218
  ${r.outputTail}`
16188
16219
  ].join(`
@@ -16205,7 +16236,7 @@ ${r.outputTail || "(none yet)"}`,
16205
16236
  });
16206
16237
  var FORGE_JOBS_ACTIONS = ["list", "poll", "log", "kill", "clear", "handoff"];
16207
16238
  var forgeJobsTool = tool({
16208
- description: "Manage forge_shell jobs. Actions: list (all jobs, newest first); poll {jobId, waitMs<=30000} — bounded wait for NEW output or exit, drains it; log {jobId, offset?, limit?} — line paging over the on-disk log (omitted offset = tail window, default 200 lines); kill {jobId} — terminate the job's whole process tree; clear {jobId} — drop a finished job from the registry; handoff {jobId} — rebind ownership to the root session so the job survives this (sub)session's end. A delegated agent MUST poll its jobs before yielding its conclusion.",
16239
+ description: "Manage forge_shell jobs. Actions: list (all jobs, newest first); poll {jobId, waitMs<=30000} — bounded wait for NEW output or exit, drains it; log {jobId, offset?, limit?} — line paging over the on-disk log (omitted offset = tail window, default 200 lines); kill {jobId} — terminate the job's whole process tree; clear {jobId} — drop a finished job from the registry (only early-returned/background jobs need this — synchronously consumed jobs self-clear at completion); handoff {jobId} — rebind ownership to the root session so the job survives this (sub)session's end. A delegated agent MUST poll its jobs before yielding its conclusion.",
16209
16240
  args: {
16210
16241
  action: tool.schema.string().describe(`One of: ${FORGE_JOBS_ACTIONS.join(", ")}`),
16211
16242
  jobId: tool.schema.string().optional().describe("Job id from forge_shell (required for every action except list)"),
@@ -16230,8 +16261,9 @@ var forgeJobsTool = tool({
16230
16261
  if (!args.jobId)
16231
16262
  throw new Error(`Action "${action}" requires jobId.`);
16232
16263
  const job = jobManager.get(args.jobId);
16233
- if (!job)
16234
- throw new Error(`No job ${args.jobId} in the registry (finished jobs age out; the on-disk log may still exist).`);
16264
+ if (!job) {
16265
+ throw new Error(jobManager.consumed(args.jobId) ? `Job ${args.jobId} was already consumed: a terminal-evidence foreground return delivered its complete output inline, so it self-cleared from the registry — no wake fires and no clear is needed.` : `No job ${args.jobId} in the registry (finished jobs age out; the on-disk log may still exist).`);
16266
+ }
16235
16267
  if (action === "poll") {
16236
16268
  const p = await pollJob(jobManager, args.jobId, args.waitMs ?? 0);
16237
16269
  if (!p)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sorenllm/opencode-forge",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Single general-purpose forge agent for opencode: static worker subagents defined in forge.json (pinned model + thoughtLevel pair, or an Auto worker inheriting the parent model; dispatched through the native task tool — TUI-visible), a plan harness (file-backed plans with approve/close confirmation gates and a hard draft write-ban), a goal harness (autonomous, host-verified objectives), a /crew orchestration command (declared-plan waves with an evidence-checked close gate), a job supervisor (forge_shell with exit-bound completion, idle/success early return, background jobs with poll/log/kill/handoff), and a builtin-shell hang watchdog.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",