@thready-web/dsh-bot-plugin 0.1.0-beta.5 → 0.1.0-beta.7

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.
@@ -3,7 +3,7 @@ import { sha256 } from "./fs-safe.js";
3
3
  import { toolError } from "./errors.js";
4
4
  import { createTicketBook } from "./work-tickets.js";
5
5
  import { decideAdmission, budgetTrip, estimateWorkerBudget, DEFAULT_WORK_BUDGET, effectiveWorkLimits, } from "./work-admit.js";
6
- import { messageIdOf, pushInput, pushNotice, reasonKindOf, reconcileInputs, reconcileNotices, renderNotice, } from "./work-ledger.js";
6
+ import { messageIdOf, pushInput, pushNotice, reasonKindOf, reconcileInputs, reconcileNotices, renderMainHistory, renderNotice, } from "./work-ledger.js";
7
7
  const KINDS = new Set(['progress', 'question', 'artifact', 'result', 'failure']);
8
8
  const LABEL = {
9
9
  accepted: 'accepted',
@@ -65,6 +65,7 @@ export function createWorkRuntime(store, engine, options = {}) {
65
65
  return options.push(sessionId, messageId, text);
66
66
  },
67
67
  noticeText: (nativeId) => noticeText(nativeId),
68
+ mainHistory: (ownerSessionId) => readMainHistory(ownerSessionId),
68
69
  };
69
70
  return {
70
71
  limits,
@@ -78,6 +79,7 @@ export function createWorkRuntime(store, engine, options = {}) {
78
79
  publish,
79
80
  reject,
80
81
  report,
82
+ mainHistory,
81
83
  holdNotices,
82
84
  releaseHold,
83
85
  tick,
@@ -101,6 +103,38 @@ export function createWorkRuntime(store, engine, options = {}) {
101
103
  function isWorkerSession(sessionId) {
102
104
  return book.attemptForChild(sessionId) != null;
103
105
  }
106
+ /**
107
+ * Direct read of the main session that owns this worker. No authorization prompt.
108
+ * @param {string} sessionId
109
+ * @param {{ maxChars?: number }} [limits]
110
+ */
111
+ async function mainHistory(sessionId, limits) {
112
+ const attempt = book.attemptForChild(sessionId);
113
+ if (!attempt)
114
+ return toolError('FORBIDDEN', 'Only the worker for a ticket can read the main session.');
115
+ const owner = book.ticket(attempt.ticket_id)?.owner_session_id;
116
+ if (typeof owner !== 'string' || owner === '')
117
+ return toolError('NOT_FOUND', 'This ticket has no main session.');
118
+ if (!options.snapshot)
119
+ return toolError('UNAVAILABLE', 'The host cannot read the main session log.');
120
+ const events = await options.snapshot(owner);
121
+ return {
122
+ ok: true,
123
+ direct: true,
124
+ ownerSessionId: owner,
125
+ text: renderMainHistory(events, limits),
126
+ };
127
+ }
128
+ /**
129
+ * Transcript excerpt attached to a briefing. A missing log is an empty excerpt.
130
+ * @param {string} ownerSessionId
131
+ */
132
+ async function readMainHistory(ownerSessionId) {
133
+ if (!options.snapshot)
134
+ return '';
135
+ const events = await options.snapshot(ownerSessionId);
136
+ return renderMainHistory(events);
137
+ }
104
138
  /**
105
139
  * A running slot is free when both the per-bot and global running caps have room.
106
140
  * needs_user does not occupy a running slot.
@@ -695,9 +729,9 @@ export function createWorkRuntime(store, engine, options = {}) {
695
729
  if (engine.isBot(owner))
696
730
  await admit(owner);
697
731
  }
698
- for (const child of book.childIds())
732
+ for (const child of book.childIdsForReconcile())
699
733
  await reconcileChild(child);
700
- for (const owner of book.ownerIds())
734
+ for (const owner of book.ownerIdsForReconcile())
701
735
  await reconcileOwner(owner);
702
736
  await promoteQueued();
703
737
  }
@@ -707,7 +741,7 @@ export function createWorkRuntime(store, engine, options = {}) {
707
741
  */
708
742
  async function renewLiveLeases() {
709
743
  const renewals = [];
710
- for (const child of book.childIds()) {
744
+ for (const child of book.childIdsForReconcile()) {
711
745
  const attempt = book.attemptForChild(child);
712
746
  if (!attempt || (attempt.status !== 'started' && attempt.status !== 'enqueued'))
713
747
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thready-web/dsh-bot-plugin",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.7",
4
4
  "type": "module",
5
5
  "description": "DSH bot plugin: session persona, memory, work, hash routing, and the workbench. Pinned to @deepseek-ai/dsh 0.2.2-rc.1.",
6
6
  "license": "MIT",