@gobing-ai/ts-ai-runner 0.8.3 → 0.8.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.
package/README.md CHANGED
@@ -333,7 +333,7 @@ const { args } = getAgentShim('omp').getPromptCommand({
333
333
  // args: ['-p', '', '--session-dir', '.spur/run/r1/...', '-r', 'abc123', '--mode', 'text']
334
334
  ```
335
335
 
336
- **Shim / capability matrix** (probed 2026-09-18; `verifiedAgainst` per row in `getAgentSessionCapability`):
336
+ **Shim / capability matrix** (probed 2026-09-18; `deepseek` re-probed 2026-11-26 on dsh 0.2.2-rc.1; `verifiedAgainst` per row in `getAgentSessionCapability`):
337
337
 
338
338
  | Agent | resumeById | sessionDir | sessionId resume flag | persistentStdin | structuredOutput |
339
339
  | ----- | ---------- | ---------- | --------------------- | --------------- | ---------------- |
@@ -347,7 +347,7 @@ const { args } = getAgentShim('omp').getPromptCommand({
347
347
  | opencode | ✗ (CLI `-s <id>` unwired) | ✗ | degrade → fresh `run` | ✗ | ✓ (`--format json`) |
348
348
  | openclaw | ✗ (CLI `--session-id` unwired) | ✗ | degrade → fresh `agent` | ✗ | ✓ (CLI `--json`; unwired) |
349
349
  | hermes | ✗ (unverified) | ✗ | degrade → fresh `chat` | ✗ | ✗ (unverified) |
350
- | deepseek | ✗ | ✗ | degrade → fresh headless one-shot | ✗ | ✗ |
350
+ | deepseek | ✓ (0.2.2-rc.1) | ✗ (ignored; the store is `$DSH_HOME`) | `--session-id <id>` | ✗ | ✓ (`--json`) |
351
351
  | fm | ✓ | ✓ | `--resume <file>` + `--save-transcript <file>` (file = `<sessionDir>/<sessionId>.json`) | ✗ (`fm chat` is interactive only) | ✗ (`--schema` needs a file; ts-decision-fm surface) |
352
352
 
353
353
  **Claude session discovery:** claude has no session-dir flag and does not accept a caller-chosen
@@ -506,7 +506,7 @@ Agent-specific behavior:
506
506
  | `openclaw` | `openclaw` | 2 | `openclaw health` | `agent --local -m` |
507
507
  | `hermes` | `hermes` | 1 | `hermes doctor` | `chat -q`, `--continue`, `-m` |
508
508
  | `grok` | `grok` | 1 | env/file (`XAI_API_KEY` or `~/.grok/auth.json`) | `-p`, `-c` (resume), `-m`, `--output-format plain\|json` (maps ai-runner `text` → `plain`) |
509
- | `deepseek` | `dsh` | 1 | env-only / `~/.dsh` (no status verb) | `--profile headless <task>`; session/model options degrade to a fresh one-shot (no flags at 0.1.5-rc.1) |
509
+ | `deepseek` | `dsh` | 1 | env-only / `~/.dsh` (no status verb) | `--profile headless`, `--json`, `--session-id <id>`, `--permission-mode workspace-write`, `--approval-policy never`, `--` then the task (0.2.2-rc.1); `continue`/`sessionDir`/`model` degrade to a fresh one-shot |
510
510
  | `fm` | `fm` | 1 | `fm available --model system` | `respond --no-stream`, `-m`, transcript session flags; **text-only** (no file/shell tools — excluded from `TIER1_PRIORITY` auto-selection) |
511
511
 
512
512
  This is the right layer for UI previews, audit logging, and custom launchers.
@@ -1 +1 @@
1
- {"version":3,"file":"shims.d.ts","sourceRoot":"","sources":["../../src/agents/shims.ts"],"names":[],"mappings":"AAIA,gEAAgE;AAChE,MAAM,MAAM,SAAS,GACf,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,IAAI,GACJ,UAAU,GACV,iBAAiB,GACjB,UAAU,GACV,QAAQ,GACR,KAAK,GACL,MAAM,GACN,UAAU,GACV,IAAI,CAAC;AAEX,0CAA0C;AAC1C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,mEAAmE;AACnE,MAAM,WAAW,WAAW;IACxB,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,4CAA4C;AAC5C,MAAM,WAAW,aAAa;IAC1B,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IAC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AAC;AAU1E;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAQrE;AAED;mEACmE;AACnE,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAMxD"}
@@ -310,10 +310,12 @@ const grokShim = {
310
310
  /**
311
311
  * DeepSeek coding agent (`dsh`, @deepseek-ai/dsh) — tier-1. Boot model is
312
312
  * `dsh --profile <name>`; the headless one-shot surface is the `headless`
313
- * profile: `dsh --profile headless "<task>"` streams reasoning to stderr and
314
- * prints the final assistant message to stdout. At 0.1.5-rc.1 the headless
315
- * app accepts only the positional task and `-h` — no resume/model/mode flags.
316
- * No auth subcommand; credentials resolve via env references / `~/.dsh`.
313
+ * profile. At 0.2.x headless the app accepts `--json` (NDJSON run events),
314
+ * `--session-id` resume, `--permission-mode`, `--approval-policy` and
315
+ * `--add-dir` (`dsh --profile headless --help`, verified on 0.2.2-rc.1).
316
+ * A run exits 0 only when it ends with a completed final `turn/end`, so the
317
+ * exit status alone carries the outcome and the shim parses no events.
318
+ * No auth subcommand; credentials resolve via env references / `$DSH_HOME`.
317
319
  */
318
320
  const dshShim = {
319
321
  name: 'deepseek',
@@ -322,11 +324,22 @@ const dshShim = {
322
324
  getHelpCommand: () => ({ command: 'dsh', args: ['--help'] }),
323
325
  getVersionCommand: () => ({ command: 'dsh', args: ['--version'] }),
324
326
  getPromptCommand: (options) => {
325
- // Always a fresh one-shot headless dispatch: sessionId/sessionDir/
326
- // continue/model degrade silently — the HEADLESS app takes only the
327
- // task + `-h`; no resume/model flags exist at dsh 0.1.5-rc.1.
328
- // mode/workspace/timeoutMs have no dsh flag — best-effort ignored.
329
- return { command: 'dsh', args: ['--profile', 'headless', options.input ?? ''] };
327
+ const args = ['--profile', 'headless'];
328
+ if ((options.mode ?? 'text') === 'json')
329
+ args.push('--json');
330
+ // ADR-047 R5: sessionId is the only session input that emits a flag. `continue`
331
+ // is never mapped — dsh has no last-session flag and guessing an id would break
332
+ // pinned-session precedence; `sessionDir` is ignored (the store is `$DSH_HOME`,
333
+ // an env var an argv-only shim cannot carry).
334
+ if (options.sessionId !== undefined)
335
+ args.push('--session-id', options.sessionId);
336
+ // Non-interactive fixed grant: dsh requires the permission preset (and the
337
+ // approval policy) on every dispatch, resume included. model/workspace/
338
+ // timeoutMs have no dsh flag — best-effort ignored.
339
+ args.push('--permission-mode', 'workspace-write', '--approval-policy', 'never');
340
+ // `--` pins the task as the positional, so a dash-leading prompt is never a flag.
341
+ args.push('--', options.input ?? '');
342
+ return { command: 'dsh', args };
330
343
  },
331
344
  getAuthCommand: () => null,
332
345
  };
@@ -507,14 +520,16 @@ const AGENT_SESSION_CAPABILITY = {
507
520
  verifiedAgainst: 'unverified (CLI not installed)',
508
521
  note: 'CLI absent at verification (2026-09-18) — conservative defaults; `chat --continue` resumes the last session only, no session-dir/stdin/structured-output flags documented',
509
522
  },
510
- // dsh headless has no resume/session flags — fresh-dispatch degrade.
523
+ // dsh 0.2.x headless: `--json` NDJSON events and `--session-id` resume exist; the
524
+ // session store is `$DSH_HOME` (no directory flag) and each run is one task per
525
+ // process (no persistent stdin). Resume needs the same cwd + repeated permission flags.
511
526
  deepseek: {
512
- supportsResumeById: false,
527
+ supportsResumeById: true,
513
528
  supportsSessionDir: false,
514
529
  supportsPersistentStdin: false,
515
- supportsStructuredOutput: false,
516
- verifiedAgainst: '0.1.5-rc.1',
517
- note: 'headless app takes only the task positional and -h at 0.1.5-rc.1 — no resume/session/mode flags; fresh-dispatch degrade',
530
+ supportsStructuredOutput: true,
531
+ verifiedAgainst: '0.2.2-rc.1',
532
+ note: 'sessionDir false: the session store is $DSH_HOME, an env var an argv-only shim cannot set; persistent stdin false: headless runs one task per process; resume requires the same cwd and repeats the permission flags',
518
533
  },
519
534
  fm: {
520
535
  supportsResumeById: true,
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CAAC,OAAO,EAAE;IACrD,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACtC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC/B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA0EjC"}
@@ -221,6 +221,11 @@ class TurnSessionImpl {
221
221
  lines;
222
222
  /** Resolves when the stdout pump has routed every line (never rejects — it settles the turn). */
223
223
  pumped;
224
+ /**
225
+ * First frame the pump could not decode. Proof the protocol broke outranks every
226
+ * process-gone classification (exit, dead stdin) and outlives the turn it happened outside of.
227
+ */
228
+ protocolViolation;
224
229
  active;
225
230
  /** Most recent turn — kept so frames arriving after settlement surface as diagnostics. */
226
231
  lastTurn;
@@ -250,6 +255,11 @@ class TurnSessionImpl {
250
255
  turn.cancelHook = (reason, graceMs) => this.cancelTurn(turn, reason, graceMs);
251
256
  this.active = turn;
252
257
  this.state = 'busy';
258
+ if (this.protocolViolation !== undefined) {
259
+ // The stream already broke before this turn existed; writing a prompt to it is pointless.
260
+ turn.settle({ kind: 'contract-violation', reason: this.protocolViolation });
261
+ return turn;
262
+ }
253
263
  try {
254
264
  this.process.writeStdin(this.driver.encodeTurn({
255
265
  turnId,
@@ -259,8 +269,9 @@ class TurnSessionImpl {
259
269
  }));
260
270
  }
261
271
  catch (error) {
262
- // A dead stdin means the process is gone: the turn never started.
263
- turn.settle({ kind: 'not-started', reason: error instanceof Error ? error.message : String(error) });
272
+ // A dead stdin means the process is gone — but it may have died of a malformed frame it
273
+ // already wrote, so settle behind the drain instead of claiming the turn never arrived.
274
+ void this.settleGone(turn, error instanceof Error ? error.message : String(error));
264
275
  }
265
276
  return turn;
266
277
  }
@@ -399,11 +410,19 @@ class TurnSessionImpl {
399
410
  }
400
411
  }
401
412
  catch (error) {
402
- this.active?.settle({
403
- kind: 'contract-violation',
404
- reason: error instanceof Error ? error.message : String(error),
405
- });
413
+ const reason = error instanceof Error ? error.message : String(error);
414
+ this.protocolViolation ??= reason;
415
+ this.active?.settle({ kind: 'contract-violation', reason });
416
+ }
417
+ }
418
+ /** Let the stdout pump finish (bounded), then settle a turn whose process is gone. */
419
+ async settleGone(turn, reason) {
420
+ await Promise.race([this.pumped, delay(TURN_EXIT_DRAIN_MS)]);
421
+ if (this.protocolViolation !== undefined) {
422
+ turn.settle({ kind: 'contract-violation', reason: this.protocolViolation });
423
+ return;
406
424
  }
425
+ turn.settle({ kind: 'not-started', reason });
407
426
  }
408
427
  /** Deterministic settlement when the process dies: before acceptance → not-started, after → unknown. */
409
428
  async onExit() {
@@ -415,7 +434,9 @@ class TurnSessionImpl {
415
434
  if (turn === undefined)
416
435
  return;
417
436
  if (!turn.outcomeResolved) {
418
- if (turn.acceptedAt === undefined)
437
+ if (this.protocolViolation !== undefined)
438
+ turn.settle({ kind: 'contract-violation', reason: this.protocolViolation });
439
+ else if (turn.acceptedAt === undefined)
419
440
  turn.settle({ kind: 'not-started', reason: 'process exited before acceptance' });
420
441
  else
421
442
  turn.settle({ kind: 'outcome-unknown', reason: 'process exited without a native terminal' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobing-ai/ts-ai-runner",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "@gobing-ai/ts-ai-runner — Coding-agent shims, detection, doctor checks, and prompt execution.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -51,12 +51,12 @@
51
51
  "release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-ai-runner-v<version> && git push --tags' && exit 1"
52
52
  },
53
53
  "dependencies": {
54
- "@gobing-ai/ts-infra": "^0.8.3",
55
- "@gobing-ai/ts-runtime": "^0.8.3"
54
+ "@gobing-ai/ts-infra": "^0.8.5",
55
+ "@gobing-ai/ts-runtime": "^0.8.5"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/bun": "1.4.3",
59
- "@gobing-ai/ts-db": "^0.8.3"
59
+ "@gobing-ai/ts-db": "^0.8.5"
60
60
  },
61
61
  "publishConfig": {
62
62
  "access": "public"
@@ -416,10 +416,12 @@ const grokShim: AgentShim = {
416
416
  /**
417
417
  * DeepSeek coding agent (`dsh`, @deepseek-ai/dsh) — tier-1. Boot model is
418
418
  * `dsh --profile <name>`; the headless one-shot surface is the `headless`
419
- * profile: `dsh --profile headless "<task>"` streams reasoning to stderr and
420
- * prints the final assistant message to stdout. At 0.1.5-rc.1 the headless
421
- * app accepts only the positional task and `-h` — no resume/model/mode flags.
422
- * No auth subcommand; credentials resolve via env references / `~/.dsh`.
419
+ * profile. At 0.2.x headless the app accepts `--json` (NDJSON run events),
420
+ * `--session-id` resume, `--permission-mode`, `--approval-policy` and
421
+ * `--add-dir` (`dsh --profile headless --help`, verified on 0.2.2-rc.1).
422
+ * A run exits 0 only when it ends with a completed final `turn/end`, so the
423
+ * exit status alone carries the outcome and the shim parses no events.
424
+ * No auth subcommand; credentials resolve via env references / `$DSH_HOME`.
423
425
  */
424
426
  const dshShim: AgentShim = {
425
427
  name: 'deepseek',
@@ -428,11 +430,20 @@ const dshShim: AgentShim = {
428
430
  getHelpCommand: () => ({ command: 'dsh', args: ['--help'] }),
429
431
  getVersionCommand: () => ({ command: 'dsh', args: ['--version'] }),
430
432
  getPromptCommand: (options) => {
431
- // Always a fresh one-shot headless dispatch: sessionId/sessionDir/
432
- // continue/model degrade silently — the HEADLESS app takes only the
433
- // task + `-h`; no resume/model flags exist at dsh 0.1.5-rc.1.
434
- // mode/workspace/timeoutMs have no dsh flag — best-effort ignored.
435
- return { command: 'dsh', args: ['--profile', 'headless', options.input ?? ''] };
433
+ const args = ['--profile', 'headless'];
434
+ if ((options.mode ?? 'text') === 'json') args.push('--json');
435
+ // ADR-047 R5: sessionId is the only session input that emits a flag. `continue`
436
+ // is never mapped — dsh has no last-session flag and guessing an id would break
437
+ // pinned-session precedence; `sessionDir` is ignored (the store is `$DSH_HOME`,
438
+ // an env var an argv-only shim cannot carry).
439
+ if (options.sessionId !== undefined) args.push('--session-id', options.sessionId);
440
+ // Non-interactive fixed grant: dsh requires the permission preset (and the
441
+ // approval policy) on every dispatch, resume included. model/workspace/
442
+ // timeoutMs have no dsh flag — best-effort ignored.
443
+ args.push('--permission-mode', 'workspace-write', '--approval-policy', 'never');
444
+ // `--` pins the task as the positional, so a dash-leading prompt is never a flag.
445
+ args.push('--', options.input ?? '');
446
+ return { command: 'dsh', args };
436
447
  },
437
448
  getAuthCommand: () => null,
438
449
  };
@@ -630,14 +641,16 @@ const AGENT_SESSION_CAPABILITY: Readonly<Record<AgentName, AgentSessionCapabilit
630
641
  verifiedAgainst: 'unverified (CLI not installed)',
631
642
  note: 'CLI absent at verification (2026-09-18) — conservative defaults; `chat --continue` resumes the last session only, no session-dir/stdin/structured-output flags documented',
632
643
  },
633
- // dsh headless has no resume/session flags — fresh-dispatch degrade.
644
+ // dsh 0.2.x headless: `--json` NDJSON events and `--session-id` resume exist; the
645
+ // session store is `$DSH_HOME` (no directory flag) and each run is one task per
646
+ // process (no persistent stdin). Resume needs the same cwd + repeated permission flags.
634
647
  deepseek: {
635
- supportsResumeById: false,
648
+ supportsResumeById: true,
636
649
  supportsSessionDir: false,
637
650
  supportsPersistentStdin: false,
638
- supportsStructuredOutput: false,
639
- verifiedAgainst: '0.1.5-rc.1',
640
- note: 'headless app takes only the task positional and -h at 0.1.5-rc.1 — no resume/session/mode flags; fresh-dispatch degrade',
651
+ supportsStructuredOutput: true,
652
+ verifiedAgainst: '0.2.2-rc.1',
653
+ note: 'sessionDir false: the session store is $DSH_HOME, an env var an argv-only shim cannot set; persistent stdin false: headless runs one task per process; resume requires the same cwd and repeats the permission flags',
641
654
  },
642
655
  fm: {
643
656
  supportsResumeById: true,
@@ -439,6 +439,11 @@ class TurnSessionImpl implements TurnSession {
439
439
  private readonly lines: AsyncIterable<string>;
440
440
  /** Resolves when the stdout pump has routed every line (never rejects — it settles the turn). */
441
441
  private readonly pumped: Promise<void>;
442
+ /**
443
+ * First frame the pump could not decode. Proof the protocol broke outranks every
444
+ * process-gone classification (exit, dead stdin) and outlives the turn it happened outside of.
445
+ */
446
+ private protocolViolation: string | undefined;
442
447
  private active: ActiveTurn | undefined;
443
448
  /** Most recent turn — kept so frames arriving after settlement surface as diagnostics. */
444
449
  private lastTurn: ActiveTurn | undefined;
@@ -475,6 +480,11 @@ class TurnSessionImpl implements TurnSession {
475
480
  turn.cancelHook = (reason, graceMs) => this.cancelTurn(turn, reason, graceMs);
476
481
  this.active = turn;
477
482
  this.state = 'busy';
483
+ if (this.protocolViolation !== undefined) {
484
+ // The stream already broke before this turn existed; writing a prompt to it is pointless.
485
+ turn.settle({ kind: 'contract-violation', reason: this.protocolViolation });
486
+ return turn;
487
+ }
478
488
  try {
479
489
  this.process.writeStdin(
480
490
  this.driver.encodeTurn({
@@ -485,8 +495,9 @@ class TurnSessionImpl implements TurnSession {
485
495
  }),
486
496
  );
487
497
  } catch (error) {
488
- // A dead stdin means the process is gone: the turn never started.
489
- turn.settle({ kind: 'not-started', reason: error instanceof Error ? error.message : String(error) });
498
+ // A dead stdin means the process is gone — but it may have died of a malformed frame it
499
+ // already wrote, so settle behind the drain instead of claiming the turn never arrived.
500
+ void this.settleGone(turn, error instanceof Error ? error.message : String(error));
490
501
  }
491
502
  return turn;
492
503
  }
@@ -624,11 +635,20 @@ class TurnSessionImpl implements TurnSession {
624
635
  for (const wire of wires) this.route(wire);
625
636
  }
626
637
  } catch (error) {
627
- this.active?.settle({
628
- kind: 'contract-violation',
629
- reason: error instanceof Error ? error.message : String(error),
630
- });
638
+ const reason = error instanceof Error ? error.message : String(error);
639
+ this.protocolViolation ??= reason;
640
+ this.active?.settle({ kind: 'contract-violation', reason });
641
+ }
642
+ }
643
+
644
+ /** Let the stdout pump finish (bounded), then settle a turn whose process is gone. */
645
+ private async settleGone(turn: ActiveTurn, reason: string): Promise<void> {
646
+ await Promise.race([this.pumped, delay(TURN_EXIT_DRAIN_MS)]);
647
+ if (this.protocolViolation !== undefined) {
648
+ turn.settle({ kind: 'contract-violation', reason: this.protocolViolation });
649
+ return;
631
650
  }
651
+ turn.settle({ kind: 'not-started', reason });
632
652
  }
633
653
 
634
654
  /** Deterministic settlement when the process dies: before acceptance → not-started, after → unknown. */
@@ -640,7 +660,9 @@ class TurnSessionImpl implements TurnSession {
640
660
  this.state = 'closed';
641
661
  if (turn === undefined) return;
642
662
  if (!turn.outcomeResolved) {
643
- if (turn.acceptedAt === undefined)
663
+ if (this.protocolViolation !== undefined)
664
+ turn.settle({ kind: 'contract-violation', reason: this.protocolViolation });
665
+ else if (turn.acceptedAt === undefined)
644
666
  turn.settle({ kind: 'not-started', reason: 'process exited before acceptance' });
645
667
  else turn.settle({ kind: 'outcome-unknown', reason: 'process exited without a native terminal' });
646
668
  }