dsh-boost 0.1.0 → 0.1.2

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 (54) hide show
  1. package/README.en.md +184 -70
  2. package/README.md +148 -59
  3. package/dist/gate/decide.js +33 -2
  4. package/dist/gate/decide.js.map +1 -1
  5. package/dist/hooks/llm-stream.js +242 -89
  6. package/dist/hooks/llm-stream.js.map +1 -1
  7. package/dist/hooks/post-execute.js +282 -25
  8. package/dist/hooks/post-execute.js.map +1 -1
  9. package/dist/hooks/session-state.js +18 -8
  10. package/dist/hooks/session-state.js.map +1 -1
  11. package/dist/host/root.js +22 -1
  12. package/dist/host/root.js.map +1 -1
  13. package/dist/index.js +494 -72
  14. package/dist/index.js.map +1 -1
  15. package/dist/scope/doc.js.map +1 -1
  16. package/dist/scope/store.js +24 -9
  17. package/dist/scope/store.js.map +1 -1
  18. package/dist/tools/boost.js +37 -4
  19. package/dist/tools/boost.js.map +1 -1
  20. package/dist/types.d.ts +18 -1
  21. package/dist/types.js.map +1 -1
  22. package/package.json +10 -6
  23. package/dist/admission/fixed-cost.d.ts +0 -23
  24. package/dist/admission/ledger.d.ts +0 -113
  25. package/dist/admission/retrieval.d.ts +0 -65
  26. package/dist/admission/usage.d.ts +0 -75
  27. package/dist/config.d.ts +0 -43
  28. package/dist/gate/binding.d.ts +0 -113
  29. package/dist/gate/decide.d.ts +0 -82
  30. package/dist/gate/guard.d.ts +0 -69
  31. package/dist/gate/invalidate.d.ts +0 -112
  32. package/dist/gate/plan.d.ts +0 -86
  33. package/dist/hooks/clock.d.ts +0 -68
  34. package/dist/hooks/execute.d.ts +0 -79
  35. package/dist/hooks/llm-stream.d.ts +0 -276
  36. package/dist/hooks/pending.d.ts +0 -89
  37. package/dist/hooks/post-execute.d.ts +0 -247
  38. package/dist/hooks/session-state.d.ts +0 -158
  39. package/dist/hooks/synthesize.d.ts +0 -74
  40. package/dist/host/loader.d.ts +0 -23
  41. package/dist/host/platform.d.ts +0 -18
  42. package/dist/host/root.d.ts +0 -18
  43. package/dist/projection/apply.d.ts +0 -174
  44. package/dist/projection/canonicalise.d.ts +0 -43
  45. package/dist/projection/counters.d.ts +0 -65
  46. package/dist/projection/truncate.d.ts +0 -47
  47. package/dist/prompt/protocol.d.ts +0 -45
  48. package/dist/receipts/store.d.ts +0 -198
  49. package/dist/scope/doc.d.ts +0 -117
  50. package/dist/scope/resolve.d.ts +0 -91
  51. package/dist/scope/store.d.ts +0 -135
  52. package/dist/selector/jev.d.ts +0 -93
  53. package/dist/tools/boost.d.ts +0 -367
  54. package/dist/tools/family.d.ts +0 -26
@@ -1,3 +1,8 @@
1
+ // `sessionClock` is the single owner of the shared-instance loan rule. Importing
2
+ // it here keeps `clockTurnOf` from growing a second, disagreeing copy of that
3
+ // rule; the cycle is type/function-only (neither module calls the other at
4
+ // evaluation time).
5
+ import { sessionClock } from './llm-stream.js';
1
6
  /**
2
7
  * Receipt and dispatch memory for every session the plugin has seen.
3
8
  *
@@ -64,20 +69,25 @@ export class ReceiptSessionState {
64
69
  /**
65
70
  * The session's host turn, or `undefined` when no clock can answer a real turn.
66
71
  *
67
- * The per-session runtime wins over the shared fallback, exactly as in
68
- * `sessionClock`. A clock that throws, a missing clock and a non-finite or
69
- * non-positive turn all mean "no host turn": `TurnClock` reports 0 before the
70
- * first `agent/request`, and real host turns start at 1. Callers that need a
71
- * number for a receipt field write `?? 0`; callers that decide turn validity
72
- * keep the `undefined` distinction.
72
+ * The clock is resolved through `sessionClock`, never by reading `deps.clock`
73
+ * directly: that function owns the shared-instance loan rule. When no
74
+ * per-session runtime is wired, one shared clock may only be read by the
75
+ * session it was lent to; a second session gets `undefined` instead of another
76
+ * session's turn (review row 20). A clock that throws, a missing clock and a
77
+ * non-finite or non-positive turn all mean "no host turn": `TurnClock` reports
78
+ * 0 before the first `agent/request`, and real host turns start at 1. Callers
79
+ * that need a number for a receipt field write `?? 0`; callers that decide
80
+ * turn validity keep the `undefined` distinction.
73
81
  */
74
82
  export function clockTurnOf(deps, sessionId) {
75
83
  let clock;
76
84
  try {
77
- clock = deps.sessions?.clockFor(sessionId) ?? deps.clock;
85
+ // `SessionPlumbing` is the structural subset `sessionClock` reads; the
86
+ // cast only widens it to the full `HookDeps` the hook modules pass.
87
+ clock = sessionClock(deps, sessionId);
78
88
  }
79
89
  catch {
80
- clock = deps.clock;
90
+ clock = undefined;
81
91
  }
82
92
  try {
83
93
  const turn = clock?.turn();
@@ -1 +1 @@
1
- {"version":3,"file":"session-state.js","sourceRoot":"","sources":["../../src/hooks/session-state.ts"],"names":[],"mappings":"AA8DA;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAmB;IACb,SAAS,GAAG,IAAI,GAAG,EAAwB,CAAA;IAE5D;;;;;;;OAOG;IACH,KAAK,CAAC,SAAiB,EAAE,IAAY;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAC9C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA;QAC/C,CAAC;QACD,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,GAAG,EAAE,EAAE,CAAA;QAChF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QACpC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,KAAK,SAAS,EAAE,CAAA;IACtD,CAAC;IAED,qFAAqF;IACrF,UAAU,CAAC,SAAiB,EAAE,IAAY,EAAE,OAAyB;QACnE,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC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,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["/**\n * Per-session bookkeeping for the post-execute decision path.\n *\n * The receipt/dispatch maps below are the class's own state. The module also\n * owns the small plumbing both hook modules share — queue/anchor/plan access,\n * receipt appends, the clock-turn read and receipt previews — so the two\n * former copies cannot drift (in particular, their `clockTurnOf` fallbacks\n * disagreed on `0` vs `undefined`).\n *\n * Both maps are keyed by session id and scoped to one host turn\n * (design §5.2-7: the anchor cache expires at turn end):\n *\n * - **Receipts.** `decide` evaluates guards and `$public` templates against the\n * receipt that just arrived (filed under `'root'`) *and* the receipts of the\n * calls this plugin substituted earlier in the turn (filed under the plan\n * candidate id). Without the second half a later step's\n * `{ \"$public\": { \"after\": \"A\" … } }` can never bind, so the plan could only\n * ever commit its first step.\n * - **In-flight dispatches.** `tools/execute` clears the pending entry once the\n * arriving call's id matches it (on accept or reject); a call with a different\n * id passes through untouched. `tools/post-execute` still needs to know which\n * candidate the arriving call belonged to. The execute hook records `callId -> candidateId` here\n * before clearing, and the post-execute hook consumes it once.\n *\n * A new host turn drops both maps. Turn detection is lazy: the hooks see no\n * turn-end event, so the first call of a new turn is what folds the old turn\n * away. Nothing here throws on its own, but every method is still called from\n * inside the hooks' `try` blocks, because the callers own the no-throw\n * contract with the host.\n *\n * **Lifetime.** One entry per session, scoped to the host turn. A session's\n * entry is replaced on the first call of its next turn, so the steady-state\n * retention is one turn's receipts (at most 27: `'root'` plus the plan's\n * `A`–`Z`) and any in-flight dispatches. `session/disposed` is wired in\n * `src/index.ts`, which calls `clearSession(deps, sessionId)`; that drops this\n * state along with the queue, anchors, plan and per-session runtime, so a\n * disposed session leaves nothing behind.\n *\n * The class's internals stay private (`HookDeps` exposes only the optional\n * instance), and only the plumbing helpers are exported. It lives apart from\n * `post-execute.ts` because that file already carries the four mount bodies and\n * the eleven obligations; mixing a mutable session map into it would make the\n * hook harder to audit.\n *\n * @module dsh-boost/hooks/session-state\n */\nimport type { ReceiptAnchors } from '../gate/invalidate.js'\nimport type { ReceiptStore } from '../receipts/store.js'\nimport type { CanonicalReceipt } from '../projection/canonicalise.js'\nimport type { TurnClock } from './clock.js'\nimport type { PendingEntry, PendingQueue } from './pending.js'\n\n/** One session's receipts and in-flight dispatches for the current turn. */\ninterface SessionEntry {\n /** The host turn the entry belongs to; a different turn resets it. */\n turn: number\n /** Receipts keyed by `'root'` or a plan candidate id. */\n receipts: Map<string, CanonicalReceipt>\n /** `callId -> candidateId` for substitutions the execute hook accepted. */\n dispatches: Map<string, string>\n}\n\n/**\n * Receipt and dispatch memory for every session the plugin has seen.\n *\n * `begin` is the only reader that can fold a turn away; callers use it once per\n * hook invocation and then use the rest of the API. There is no eviction within\n * a turn: a session's candidate receipts are exactly the steps of the current\n * plan, and plan parsing caps a plan at 26 steps (`A`–`Z`).\n */\nexport class ReceiptSessionState {\n private readonly bySession = new Map<string, SessionEntry>()\n\n /**\n * Return the state for `sessionId` at `turn`, discarding a previous turn's\n * receipts and dispatches.\n *\n * `rolledOver` tells the caller that the previous turn's anchors (which live\n * in `AnchorStore`, not here) are stale too and must be dropped. A brand-new\n * session has nothing to roll over, so it reports `false`.\n */\n begin(sessionId: string, turn: number): { entry: SessionEntry; rolledOver: boolean } {\n const existing = this.bySession.get(sessionId)\n if (existing !== undefined && existing.turn === turn) {\n return { entry: existing, rolledOver: false }\n }\n const entry: SessionEntry = { turn, receipts: new Map(), dispatches: new Map() }\n this.bySession.set(sessionId, entry)\n return { entry, rolledOver: existing !== undefined }\n }\n\n /** File the receipt that just arrived under `'root'`, keeping candidate receipts. */\n recordRoot(sessionId: string, turn: number, receipt: CanonicalReceipt): void {\n this.begin(sessionId, turn).entry.receipts.set('root', receipt)\n }\n\n /** File an executed candidate's receipt under its plan candidate id. */\n recordCandidate(sessionId: string, turn: number, candidateId: string, receipt: CanonicalReceipt): void {\n this.begin(sessionId, turn).entry.receipts.set(candidateId, receipt)\n }\n\n /** The receipt map `decide` reads; contains `'root'` after `recordRoot`. */\n receiptsFor(sessionId: string, turn: number): ReadonlyMap<string, CanonicalReceipt> {\n return this.begin(sessionId, turn).entry.receipts\n }\n\n /** Remember which candidate a dispatched call id belongs to. */\n recordDispatch(sessionId: string, turn: number, callId: string, candidateId: string): void {\n this.begin(sessionId, turn).entry.dispatches.set(callId, candidateId)\n }\n\n /** Consume the candidate id for `callId`, or `undefined` when the call is not one of ours. */\n takeDispatch(sessionId: string, turn: number, callId: string): string | undefined {\n const { entry } = this.begin(sessionId, turn)\n const candidateId = entry.dispatches.get(callId)\n if (candidateId === undefined) return undefined\n entry.dispatches.delete(callId)\n return candidateId\n }\n\n /**\n * Drop everything for one session: both maps and the stored turn.\n *\n * `src/index.ts` calls this from its `session/disposed` listener through\n * `clearSession`; the hooks themselves only replace an entry lazily when the\n * next turn's first call arrives.\n */\n clear(sessionId: string): void {\n this.bySession.delete(sessionId)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared session plumbing\n// ---------------------------------------------------------------------------\n//\n// `post-execute.ts` and `llm-stream.ts` both read the queue, anchors, plans and\n// receipt store. These helpers live here so the two copies that used to exist\n// cannot drift: in particular the old `clockTurnOf` returned `0` in one file and\n// `undefined` in the other, which stamped different `turn` values on receipts\n// for the same state. `receipts` and `anchors` are typed structurally so the\n// module stays usable from a test double as well as from `HookDeps`.\n\n/** The store's append input, shared by both hook modules. */\nexport type ReceiptInput = Parameters<ReceiptStore['append']>[0]\n\n/** The dependencies these helpers read; `HookDeps` is structurally assignable. */\nexport interface SessionPlumbing {\n /** Shared fallback clock when no per-session runtime is wired. */\n clock?: TurnClock\n /** Per-session runtime; its clock is authoritative when present. */\n sessions?: { clockFor(sessionId: string): TurnClock }\n /** At most one pending substitution per session. */\n queue?: PendingQueue\n /** Per-session receipt anchors. */\n anchors?: {\n get(sessionId: string): ReceiptAnchors | undefined\n clear(sessionId: string): void\n }\n /** Append-only receipt store. */\n receipts?: ReceiptStore\n /** Parsed plans, keyed by session. */\n plans?: { delete(sessionId: string): boolean }\n}\n\n/**\n * The session's host turn, or `undefined` when no clock can answer a real turn.\n *\n * The per-session runtime wins over the shared fallback, exactly as in\n * `sessionClock`. A clock that throws, a missing clock and a non-finite or\n * non-positive turn all mean \"no host turn\": `TurnClock` reports 0 before the\n * first `agent/request`, and real host turns start at 1. Callers that need a\n * number for a receipt field write `?? 0`; callers that decide turn validity\n * keep the `undefined` distinction.\n */\nexport function clockTurnOf(\n deps: SessionPlumbing,\n sessionId: string,\n): number | undefined {\n let clock: TurnClock | undefined\n try {\n clock = deps.sessions?.clockFor(sessionId) ?? deps.clock\n } catch {\n clock = deps.clock\n }\n try {\n const turn = clock?.turn()\n return typeof turn === 'number' && Number.isFinite(turn) && turn > 0 ? turn : undefined\n } catch {\n return undefined\n }\n}\n\n/** The pending entry for a session, never removing it and never throwing. */\nexport function peekPending(\n deps: SessionPlumbing,\n sessionId: string,\n): PendingEntry | undefined {\n try {\n const queue = deps.queue\n if (queue == null || typeof queue.peek !== 'function') return undefined\n return queue.peek(sessionId)\n } catch {\n return undefined\n }\n}\n\n/** Drop the session's pending entry; a foreign queue must not break the call. */\nexport function clearPending(deps: SessionPlumbing, sessionId: string): void {\n try {\n const queue = deps.queue\n if (queue == null || typeof queue.clear !== 'function') return\n queue.clear(sessionId)\n } catch {\n // Containment only: a stale entry costs a false reject later, not this call.\n }\n}\n\n/** Drop the session's anchors; a foreign store must not break the call. */\nexport function clearAnchors(deps: SessionPlumbing, sessionId: string): void {\n try {\n deps.anchors?.clear(sessionId)\n } catch {\n // Containment only: the store is evidence, not a precondition.\n }\n}\n\n/** Drop the session's parsed plan; a foreign map must not break the call. */\nexport function clearPlan(deps: SessionPlumbing, sessionId: string): void {\n try {\n deps.plans?.delete(sessionId)\n } catch {\n // A foreign map can only cost a later decision.\n }\n}\n\n/** Append one receipt; a receipt is evidence, never a precondition. */\nexport async function appendReceipt(\n deps: SessionPlumbing,\n receipt: ReceiptInput,\n): Promise<void> {\n const store = deps.receipts\n if (store == null || typeof store.append !== 'function') return\n try {\n await store.append(receipt)\n } catch {\n // A receipt is evidence, not a precondition: never break the call for it.\n }\n}\n\n/** The design's preview bound: 256 code points, never split a surrogate pair. */\nconst PREVIEW_CODE_POINTS = 256\n\n/** The first 256 code points of a canonical receipt, or of a synthesized call. */\nexport function previewOf(text: string | undefined): string {\n return Array.from(text ?? '').slice(0, PREVIEW_CODE_POINTS).join('')\n}\n\n/**\n * The evidence line for a receipt that predates its tool result.\n *\n * A substitute or a refused dispatch has no canonical tool result yet, so its\n * preview names the call that is being made (or was refused): the operator's\n * question is \"why did this call run?\", and the name plus bound args is the\n * answer available at that point.\n */\nexport function callPreview(name: string, args: unknown): string {\n let encoded = ''\n try {\n encoded = JSON.stringify(args) ?? ''\n } catch {\n // A non-serialisable tree still leaves the tool name as evidence.\n }\n return previewOf(`${name} ${encoded}`.trim())\n}\n"]}
1
+ {"version":3,"file":"session-state.js","sourceRoot":"","sources":["../../src/hooks/session-state.ts"],"names":[],"mappings":"AAkDA,iFAAiF;AACjF,8EAA8E;AAC9E,2EAA2E;AAC3E,oBAAoB;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAa9C;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAmB;IACb,SAAS,GAAG,IAAI,GAAG,EAAwB,CAAA;IAE5D;;;;;;;OAOG;IACH,KAAK,CAAC,SAAiB,EAAE,IAAY;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAC9C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA;QAC/C,CAAC;QACD,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,GAAG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C,CAAC,EAAE,mBAAmB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACtE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAa;IACrD,IAAI,OAAO,GAAG,EAAE,CAAA;IAChB,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,kEAAkE;IACpE,CAAC;IACD,OAAO,SAAS,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["/**\n * Per-session bookkeeping for the post-execute decision path.\n *\n * The receipt/dispatch maps below are the class's own state. The module also\n * owns the small plumbing both hook modules share — queue/anchor/plan access,\n * receipt appends, the clock-turn read and receipt previews — so the two\n * former copies cannot drift (in particular, their `clockTurnOf` fallbacks\n * disagreed on `0` vs `undefined`).\n *\n * Both maps are keyed by session id and scoped to one host turn\n * (design §5.2-7: the anchor cache expires at turn end):\n *\n * - **Receipts.** `decide` evaluates guards and `$public` templates against the\n * receipt that just arrived (filed under `'root'`) *and* the receipts of the\n * calls this plugin substituted earlier in the turn (filed under the plan\n * candidate id). Without the second half a later step's\n * `{ \"$public\": { \"after\": \"A\" … } }` can never bind, so the plan could only\n * ever commit its first step.\n * - **In-flight dispatches.** `tools/execute` clears the pending entry once the\n * arriving call's id matches it (on accept or reject); a call with a different\n * id passes through untouched. `tools/post-execute` still needs to know which\n * candidate the arriving call belonged to. The execute hook records `callId -> candidateId` here\n * before clearing, and the post-execute hook consumes it once.\n *\n * A new host turn drops both maps. Turn detection is lazy: the hooks see no\n * turn-end event, so the first call of a new turn is what folds the old turn\n * away. Nothing here throws on its own, but every method is still called from\n * inside the hooks' `try` blocks, because the callers own the no-throw\n * contract with the host.\n *\n * **Lifetime.** One entry per session, scoped to the host turn. A session's\n * entry is replaced on the first call of its next turn, so the steady-state\n * retention is one turn's receipts (at most 27: `'root'` plus the plan's\n * `A`–`Z`) and any in-flight dispatches. `session/disposed` is wired in\n * `src/index.ts`, which calls `clearSession(deps, sessionId)`; that drops this\n * state along with the queue, anchors, plan and per-session runtime, so a\n * disposed session leaves nothing behind.\n *\n * The class's internals stay private (`HookDeps` exposes only the optional\n * instance), and only the plumbing helpers are exported. It lives apart from\n * `post-execute.ts` because that file already carries the four mount bodies and\n * the eleven obligations; mixing a mutable session map into it would make the\n * hook harder to audit.\n *\n * @module dsh-boost/hooks/session-state\n */\nimport type { ReceiptAnchors } from '../gate/invalidate.js'\nimport type { ReceiptStore } from '../receipts/store.js'\nimport type { CanonicalReceipt } from '../projection/canonicalise.js'\nimport type { TurnClock } from './clock.js'\n// `sessionClock` is the single owner of the shared-instance loan rule. Importing\n// it here keeps `clockTurnOf` from growing a second, disagreeing copy of that\n// rule; the cycle is type/function-only (neither module calls the other at\n// evaluation time).\nimport { sessionClock } from './llm-stream.js'\nimport type { PendingEntry, PendingQueue } from './pending.js'\n\n/** One session's receipts and in-flight dispatches for the current turn. */\ninterface SessionEntry {\n /** The host turn the entry belongs to; a different turn resets it. */\n turn: number\n /** Receipts keyed by `'root'` or a plan candidate id. */\n receipts: Map<string, CanonicalReceipt>\n /** `callId -> candidateId` for substitutions the execute hook accepted. */\n dispatches: Map<string, string>\n}\n\n/**\n * Receipt and dispatch memory for every session the plugin has seen.\n *\n * `begin` is the only reader that can fold a turn away; callers use it once per\n * hook invocation and then use the rest of the API. There is no eviction within\n * a turn: a session's candidate receipts are exactly the steps of the current\n * plan, and plan parsing caps a plan at 26 steps (`A`–`Z`).\n */\nexport class ReceiptSessionState {\n private readonly bySession = new Map<string, SessionEntry>()\n\n /**\n * Return the state for `sessionId` at `turn`, discarding a previous turn's\n * receipts and dispatches.\n *\n * `rolledOver` tells the caller that the previous turn's anchors (which live\n * in `AnchorStore`, not here) are stale too and must be dropped. A brand-new\n * session has nothing to roll over, so it reports `false`.\n */\n begin(sessionId: string, turn: number): { entry: SessionEntry; rolledOver: boolean } {\n const existing = this.bySession.get(sessionId)\n if (existing !== undefined && existing.turn === turn) {\n return { entry: existing, rolledOver: false }\n }\n const entry: SessionEntry = { turn, receipts: new Map(), dispatches: new Map() }\n this.bySession.set(sessionId, entry)\n return { entry, rolledOver: existing !== undefined }\n }\n\n /** File the receipt that just arrived under `'root'`, keeping candidate receipts. */\n recordRoot(sessionId: string, turn: number, receipt: CanonicalReceipt): void {\n this.begin(sessionId, turn).entry.receipts.set('root', receipt)\n }\n\n /** File an executed candidate's receipt under its plan candidate id. */\n recordCandidate(sessionId: string, turn: number, candidateId: string, receipt: CanonicalReceipt): void {\n this.begin(sessionId, turn).entry.receipts.set(candidateId, receipt)\n }\n\n /** The receipt map `decide` reads; contains `'root'` after `recordRoot`. */\n receiptsFor(sessionId: string, turn: number): ReadonlyMap<string, CanonicalReceipt> {\n return this.begin(sessionId, turn).entry.receipts\n }\n\n /** Remember which candidate a dispatched call id belongs to. */\n recordDispatch(sessionId: string, turn: number, callId: string, candidateId: string): void {\n this.begin(sessionId, turn).entry.dispatches.set(callId, candidateId)\n }\n\n /** Consume the candidate id for `callId`, or `undefined` when the call is not one of ours. */\n takeDispatch(sessionId: string, turn: number, callId: string): string | undefined {\n const { entry } = this.begin(sessionId, turn)\n const candidateId = entry.dispatches.get(callId)\n if (candidateId === undefined) return undefined\n entry.dispatches.delete(callId)\n return candidateId\n }\n\n /**\n * Drop everything for one session: both maps and the stored turn.\n *\n * `src/index.ts` calls this from its `session/disposed` listener through\n * `clearSession`; the hooks themselves only replace an entry lazily when the\n * next turn's first call arrives.\n */\n clear(sessionId: string): void {\n this.bySession.delete(sessionId)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared session plumbing\n// ---------------------------------------------------------------------------\n//\n// `post-execute.ts` and `llm-stream.ts` both read the queue, anchors, plans and\n// receipt store. These helpers live here so the two copies that used to exist\n// cannot drift: in particular the old `clockTurnOf` returned `0` in one file and\n// `undefined` in the other, which stamped different `turn` values on receipts\n// for the same state. `receipts` and `anchors` are typed structurally so the\n// module stays usable from a test double as well as from `HookDeps`.\n\n/** The store's append input, shared by both hook modules. */\nexport type ReceiptInput = Parameters<ReceiptStore['append']>[0]\n\n/** The dependencies these helpers read; `HookDeps` is structurally assignable. */\nexport interface SessionPlumbing {\n /** Shared fallback clock when no per-session runtime is wired. */\n clock?: TurnClock\n /** Per-session runtime; its clock is authoritative when present. */\n sessions?: { clockFor(sessionId: string): TurnClock }\n /** At most one pending substitution per session. */\n queue?: PendingQueue\n /** Per-session receipt anchors. */\n anchors?: {\n get(sessionId: string): ReceiptAnchors | undefined\n clear(sessionId: string): void\n }\n /** Append-only receipt store. */\n receipts?: ReceiptStore\n /** Parsed plans, keyed by session. */\n plans?: { delete(sessionId: string): boolean }\n}\n\n/**\n * The session's host turn, or `undefined` when no clock can answer a real turn.\n *\n * The clock is resolved through `sessionClock`, never by reading `deps.clock`\n * directly: that function owns the shared-instance loan rule. When no\n * per-session runtime is wired, one shared clock may only be read by the\n * session it was lent to; a second session gets `undefined` instead of another\n * session's turn (review row 20). A clock that throws, a missing clock and a\n * non-finite or non-positive turn all mean \"no host turn\": `TurnClock` reports\n * 0 before the first `agent/request`, and real host turns start at 1. Callers\n * that need a number for a receipt field write `?? 0`; callers that decide\n * turn validity keep the `undefined` distinction.\n */\nexport function clockTurnOf(\n deps: SessionPlumbing,\n sessionId: string,\n): number | undefined {\n let clock: TurnClock | undefined\n try {\n // `SessionPlumbing` is the structural subset `sessionClock` reads; the\n // cast only widens it to the full `HookDeps` the hook modules pass.\n clock = sessionClock(deps as unknown as Parameters<typeof sessionClock>[0], sessionId)\n } catch {\n clock = undefined\n }\n try {\n const turn = clock?.turn()\n return typeof turn === 'number' && Number.isFinite(turn) && turn > 0 ? turn : undefined\n } catch {\n return undefined\n }\n}\n\n/** The pending entry for a session, never removing it and never throwing. */\nexport function peekPending(\n deps: SessionPlumbing,\n sessionId: string,\n): PendingEntry | undefined {\n try {\n const queue = deps.queue\n if (queue == null || typeof queue.peek !== 'function') return undefined\n return queue.peek(sessionId)\n } catch {\n return undefined\n }\n}\n\n/** Drop the session's pending entry; a foreign queue must not break the call. */\nexport function clearPending(deps: SessionPlumbing, sessionId: string): void {\n try {\n const queue = deps.queue\n if (queue == null || typeof queue.clear !== 'function') return\n queue.clear(sessionId)\n } catch {\n // Containment only: a stale entry costs a false reject later, not this call.\n }\n}\n\n/** Drop the session's anchors; a foreign store must not break the call. */\nexport function clearAnchors(deps: SessionPlumbing, sessionId: string): void {\n try {\n deps.anchors?.clear(sessionId)\n } catch {\n // Containment only: the store is evidence, not a precondition.\n }\n}\n\n/** Drop the session's parsed plan; a foreign map must not break the call. */\nexport function clearPlan(deps: SessionPlumbing, sessionId: string): void {\n try {\n deps.plans?.delete(sessionId)\n } catch {\n // A foreign map can only cost a later decision.\n }\n}\n\n/** Append one receipt; a receipt is evidence, never a precondition. */\nexport async function appendReceipt(\n deps: SessionPlumbing,\n receipt: ReceiptInput,\n): Promise<void> {\n const store = deps.receipts\n if (store == null || typeof store.append !== 'function') return\n try {\n await store.append(receipt)\n } catch {\n // A receipt is evidence, not a precondition: never break the call for it.\n }\n}\n\n/** The design's preview bound: 256 code points, never split a surrogate pair. */\nconst PREVIEW_CODE_POINTS = 256\n\n/** The first 256 code points of a canonical receipt, or of a synthesized call. */\nexport function previewOf(text: string | undefined): string {\n return Array.from(text ?? '').slice(0, PREVIEW_CODE_POINTS).join('')\n}\n\n/**\n * The evidence line for a receipt that predates its tool result.\n *\n * A substitute or a refused dispatch has no canonical tool result yet, so its\n * preview names the call that is being made (or was refused): the operator's\n * question is \"why did this call run?\", and the name plus bound args is the\n * answer available at that point.\n */\nexport function callPreview(name: string, args: unknown): string {\n let encoded = ''\n try {\n encoded = JSON.stringify(args) ?? ''\n } catch {\n // A non-serialisable tree still leaves the tool name as evidence.\n }\n return previewOf(`${name} ${encoded}`.trim())\n}\n"]}
package/dist/host/root.js CHANGED
@@ -31,13 +31,34 @@ import { join, resolve } from 'node:path';
31
31
  * Passing it through would leave the stores resolving it again on every read,
32
32
  * so a later `chdir` would silently move the state root mid-session (review
33
33
  * minor).
34
+ *
35
+ * A leading `~` is expanded exactly as the host's `expandHomePath`
36
+ * (`@deepseek-ai/dsh-home-paths`) does: `~` is the home directory and `~/` or
37
+ * `~\` are joined under it. The host applies that rule to `$DSH_HOME` and to a
38
+ * configured `dshHome` before resolving; without it `DSH_HOME='~/x'` would
39
+ * create a literal `~` directory under the cwd while the host's own home is
40
+ * `$HOME/x`, and `boost status` would read an empty ledger (review row 30).
34
41
  */
35
42
  export function resolveBoostRoot(config) {
36
43
  const override = config?.dshHome;
37
44
  const configured = typeof override === 'string' && override.trim() !== ''
38
45
  ? override.trim()
39
46
  : process.env.DSH_HOME?.trim();
40
- const home = configured ? resolve(configured) : join(homedir(), '.dsh');
47
+ const home = configured ? resolve(expandHomePath(configured)) : join(homedir(), '.dsh');
41
48
  return join(home, 'boost');
42
49
  }
50
+ /**
51
+ * Expand the host-supported tilde prefixes against the OS home.
52
+ *
53
+ * Mirrors `expandHomePath` in `@deepseek-ai/dsh-home-paths` (the host's one
54
+ * home-path rule): only a bare `~`, `~/…` and `~\…` are special. `~user` and a
55
+ * `~` in the middle of a path are left alone, exactly like the host.
56
+ */
57
+ function expandHomePath(value) {
58
+ if (value === '~')
59
+ return homedir();
60
+ if (value.startsWith('~/') || value.startsWith('~\\'))
61
+ return join(homedir(), value.slice(2));
62
+ return value;
63
+ }
43
64
  //# sourceMappingURL=root.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"root.js","sourceRoot":"","sources":["../../src/host/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEzC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAgB;IAC/C,MAAM,QAAQ,GAAI,MAAmD,EAAE,OAAO,CAAA;IAC9E,MAAM,UAAU,GACd,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE;QACpD,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE;QACjB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAA;IAClC,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAA;IACvE,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC5B,CAAC","sourcesContent":["/**\n * The plugin's one data-root rule.\n *\n * All three state files live under it (design §10): `scope.json`, `scope.lock`\n * and `receipts/<encoded-session>.jsonl`. `$DSH_HOME` is the host variable;\n * there is no `ctx` accessor for it (`ctx.get('dshHomePath')` does not exist —\n * an earlier task deleted that dead branch). When it is unset or blank the\n * fallback is `~/.dsh`, and the plugin appends `/boost` in both cases.\n *\n * The receipts store and the scope store receive this root; they never resolve\n * the environment themselves, so a test can point every store at one temporary\n * directory by setting `$DSH_HOME` before `apply`.\n *\n * @module dsh-boost/host/root\n */\nimport { homedir } from 'node:os'\nimport { join, resolve } from 'node:path'\n\n/**\n * `<DSH_HOME>/boost`, falling back to `<homedir>/.dsh/boost`.\n *\n * A `config.dshHome` override wins over the environment, matching the other\n * host plugins (`dsh-mcp-btwy` resolves `config.dshHome` before `$DSH_HOME`):\n * an operator who patches the plugin row should not have to change the\n * process environment for all plugins. A non-string or blank override is\n * ignored and the environment rule applies.\n *\n * A blank value is treated as unset: `join('', 'boost')` would otherwise put\n * state in the process's working directory, which is not a home directory.\n *\n * A relative home is resolved against the current cwd **once**, here.\n * Passing it through would leave the stores resolving it again on every read,\n * so a later `chdir` would silently move the state root mid-session (review\n * minor).\n */\nexport function resolveBoostRoot(config?: unknown): string {\n const override = (config as { dshHome?: unknown } | null | undefined)?.dshHome\n const configured =\n typeof override === 'string' && override.trim() !== ''\n ? override.trim()\n : process.env.DSH_HOME?.trim()\n const home = configured ? resolve(configured) : join(homedir(), '.dsh')\n return join(home, 'boost')\n}\n"]}
1
+ {"version":3,"file":"root.js","sourceRoot":"","sources":["../../src/host/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAgB;IAC/C,MAAM,QAAQ,GAAI,MAAmD,EAAE,OAAO,CAAA;IAC9E,MAAM,UAAU,GACd,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE;QACpD,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE;QACjB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAA;IAClC,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAA;IACvF,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,KAAa;IACnC,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,OAAO,EAAE,CAAA;IACnC,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7F,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["/**\n * The plugin's one data-root rule.\n *\n * All three state files live under it (design §10): `scope.json`, `scope.lock`\n * and `receipts/<encoded-session>.jsonl`. `$DSH_HOME` is the host variable;\n * there is no `ctx` accessor for it (`ctx.get('dshHomePath')` does not exist —\n * an earlier task deleted that dead branch). When it is unset or blank the\n * fallback is `~/.dsh`, and the plugin appends `/boost` in both cases.\n *\n * The receipts store and the scope store receive this root; they never resolve\n * the environment themselves, so a test can point every store at one temporary\n * directory by setting `$DSH_HOME` before `apply`.\n *\n * @module dsh-boost/host/root\n */\nimport { homedir } from 'node:os'\nimport { join, resolve } from 'node:path'\n\n/**\n * `<DSH_HOME>/boost`, falling back to `<homedir>/.dsh/boost`.\n *\n * A `config.dshHome` override wins over the environment, matching the other\n * host plugins (`dsh-mcp-btwy` resolves `config.dshHome` before `$DSH_HOME`):\n * an operator who patches the plugin row should not have to change the\n * process environment for all plugins. A non-string or blank override is\n * ignored and the environment rule applies.\n *\n * A blank value is treated as unset: `join('', 'boost')` would otherwise put\n * state in the process's working directory, which is not a home directory.\n *\n * A relative home is resolved against the current cwd **once**, here.\n * Passing it through would leave the stores resolving it again on every read,\n * so a later `chdir` would silently move the state root mid-session (review\n * minor).\n *\n * A leading `~` is expanded exactly as the host's `expandHomePath`\n * (`@deepseek-ai/dsh-home-paths`) does: `~` is the home directory and `~/` or\n * `~\\` are joined under it. The host applies that rule to `$DSH_HOME` and to a\n * configured `dshHome` before resolving; without it `DSH_HOME='~/x'` would\n * create a literal `~` directory under the cwd while the host's own home is\n * `$HOME/x`, and `boost status` would read an empty ledger (review row 30).\n */\nexport function resolveBoostRoot(config?: unknown): string {\n const override = (config as { dshHome?: unknown } | null | undefined)?.dshHome\n const configured =\n typeof override === 'string' && override.trim() !== ''\n ? override.trim()\n : process.env.DSH_HOME?.trim()\n const home = configured ? resolve(expandHomePath(configured)) : join(homedir(), '.dsh')\n return join(home, 'boost')\n}\n\n/**\n * Expand the host-supported tilde prefixes against the OS home.\n *\n * Mirrors `expandHomePath` in `@deepseek-ai/dsh-home-paths` (the host's one\n * home-path rule): only a bare `~`, `~/…` and `~\\…` are special. `~user` and a\n * `~` in the middle of a path are left alone, exactly like the host.\n */\nfunction expandHomePath(value: string): string {\n if (value === '~') return homedir()\n if (value.startsWith('~/') || value.startsWith('~\\\\')) return join(homedir(), value.slice(2))\n return value\n}\n"]}