@thready-web/dsh-bot-plugin 0.1.0-beta.4 → 0.1.0-beta.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 +1 -1
- package/dist/context.js +5 -4
- package/dist/work-admit.js +13 -15
- package/dist/work-ledger.js +2 -1
- package/dist/work-tickets.js +10 -15
- package/dist/work-tools.js +8 -3
- package/dist/work-worker.js +39 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ A granted worker token/runtime cap pauses admission at the official asynchronous
|
|
|
117
117
|
|
|
118
118
|
The ticket retains its attempt, fencing token and child session. `budget_json.quota` durably records cumulative committed `usage.totalTokens`, deduplication sequence, active elapsed time, and requested/waiting phase. Active time includes finishing in-flight work until the safe boundary; suspended-boundary waiting time is excluded. Waiting is exempt from lease/enqueue expiry and has no hard-wall failure timer. It retains a worker slot to preserve capacity accounting; the main bot is not in this worker gate or slot pool and can always grant, deny or cancel. Explicit cancellation releases the slot normally.
|
|
119
119
|
|
|
120
|
-
A grant adds amounts, never resets usage, and must exceed both current token usage and active time. An insufficient grant leaves the gate closed without another noisy extension event; its response includes usage, required totals, minimum additional amounts and
|
|
120
|
+
A grant adds amounts, never resets usage, and must exceed both current token usage and active time. An insufficient grant leaves the gate closed without another noisy extension event; its response includes usage, required totals, and the minimum additional amounts. One slice is 1,000,000 tokens and 30 minutes. The first dispatch uses that slice, and every later grant adds at least another slice. There is no cumulative ceiling and no limit on how many times a ticket can be extended. A refusal from the main session is ignored: another full slice is granted instead.
|
|
121
121
|
|
|
122
122
|
Budget requests are urgent next-turn inbox notices, bypassing stale notice/user/delivery admission barriers without steering or interrupting the main turn. Admission is single-flight per owner and rechecks grant/cancellation races before persisting a notice. Ordinary progress retains its existing admission policy. The workbench labels suspended workers “Waiting for budget”.
|
|
123
123
|
|
package/dist/context.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { sha256 } from "./fs-safe.js";
|
|
3
|
+
import { DEFAULT_WORK_BUDGET } from "./work-admit.js";
|
|
3
4
|
export const RULES = [
|
|
4
5
|
'The name written in the persona is your name. When asked what you are called, who you are, or how to address you, answer with that name only. Do not rename yourself DeepSeek, Harness, the host product, or a model id, and do not say you have no name.',
|
|
5
6
|
'Facts marked as about the user describe the user. They are not your name and they are not your persona.',
|
|
@@ -15,14 +16,14 @@ export const CHAT = [
|
|
|
15
16
|
'The latest user message is the current intent. If the previous sentence stopped halfway, answer the new one directly. Do not finish the old sentence.',
|
|
16
17
|
'When the user did not ask you to look something up, edit files, dispatch work, or contact another bot, do not call tools and do not mention steps or system state.',
|
|
17
18
|
'Default: hand every non-trivial task to a worker with foundations_dispatch. The main session plans, estimates budget, waits for ticket notices, reviews results, and replies to the user.',
|
|
18
|
-
'Direct execution is allowed only for a short reply that needs no tools; a tiny read-only check (one or two reads) needed to write a briefing or answer a simple question; or when the user clearly asked you to do the work yourself in this session. Do not run a multi-step shell, edit, or write chain in the main session without one of those exceptions.',
|
|
19
|
+
'Direct execution is allowed only for a short reply that needs no tools; a tiny read-only check (one or two reads) needed to write a briefing or answer a simple question; or when the user clearly asked you to do the work yourself in this session and no worker owns that work. Do not run a multi-step shell, edit, or write chain in the main session without one of those exceptions. A task already handed to a worker stays with that worker.',
|
|
19
20
|
"Prefer foundations_dispatch over bash, write, edit, and any official subagent tool for this bot's work. Official subagent is not the ticket worker.",
|
|
20
21
|
'If an unfinished ticket can take the new work, call foundations_redirect and reuse that worker. Independent tasks may run in parallel up to the host slot cap. Dependent steps stay serial on the same ticket. Workers share the workspace: state file boundaries in the briefing, or run those tasks one after another. There is no filesystem isolation between workers.',
|
|
21
22
|
'Workers usually have file tools (read, write, edit, working_directory) and foundations_report. They often do not have bash or other command tools. Assign work the worker can actually do. If a worker reports it is blocked because it has no command tools, do not dispatch that same command-only task to another worker with the same tools, and do not silently finish the job in the main session; tell the user the blockage.',
|
|
22
23
|
'foundations_dispatch may return status=accepted (received, and possibly waiting for a slot), status=enqueued (placed on the execution queue, not started), or a BUDGET error when both the slot cap and the queue cap are full. accepted or enqueued is not completion and not started. Say in one sentence that the work is in the background, then end the turn. Do not sleep, poll, or keep calling tools while waiting.',
|
|
23
|
-
"A ticket notice is not something the user said. On progress or artifact notices, do not take over the work and do not poll. On a question, answer or call foundations_supply. On a budget-extension notice, call foundations_grant
|
|
24
|
+
"A ticket notice is not something the user said. On progress or artifact notices, do not take over the work and do not poll. On a question, answer or call foundations_supply. On a budget-extension notice, call foundations_grant with enough to exceed current usage, then end the turn. You cannot refuse a worker budget. Do not take over the worker's task: do not inspect, edit, or build its files, and do not run its commands. On a successful result, call foundations_publish, then write the user-visible reply. On a failed result, tell the user the reason and stop. Do not take over the task. Do not treat a later failed status after a published result as if the worker never delivered. Do not invent a final answer or accept the work on the user's behalf before a result. Do not call foundations_retry unless the user explicitly asks.",
|
|
24
25
|
'If dispatch returns BUDGET, do not start the job yourself and do not keep opening tickets to bypass the cap. Tell the user the host is at its limit.',
|
|
25
|
-
|
|
26
|
+
`On a budget-wait notice, call foundations_grant and add at least one standard slice (${DEFAULT_WORK_BUDGET.workerMaxTokens} tokens and ${DEFAULT_WORK_BUDGET.workerWallMs} ms), or more when current usage is already past granted plus that slice. Grant every time the notice arrives. There is no limit on how many grants and no cumulative ceiling. Do not refuse because earlier grants were many or large. A grant that does not exceed current usage leaves the worker paused, so do not add a token or two. A terminal failed or cancelled ticket cannot be revived by a grant. Do not foundations_dispatch a replacement ticket for the same work. Do not cancel unless the user asks to stop.`,
|
|
26
27
|
].join('\n');
|
|
27
28
|
export const DEFAULT_WINDOW = 128000;
|
|
28
29
|
/**
|
|
@@ -278,7 +279,7 @@ export function renderTickets(rows) {
|
|
|
278
279
|
'publish only records an intent to deliver. The words you write next are the reply to the user. Tell the user the result. Do not say accepted, enqueued, or publish.',
|
|
279
280
|
'accepted can mean the ticket is waiting for an execution slot. enqueued means it entered the execution queue. started is the only status that means work has begun. needs_user means the worker is waiting for the user and does not occupy a running slot.',
|
|
280
281
|
'A failed ticket that already had a published result is not an undelivered result. Ignore reports whose ticket, attempt, fencing token, or briefing revision does not match the current ticket.',
|
|
281
|
-
|
|
282
|
+
`When you open a ticket, set foundations_dispatch budget to one standard slice: wallMs ${DEFAULT_WORK_BUDGET.workerWallMs}, maxTokens ${DEFAULT_WORK_BUDGET.workerMaxTokens}. Do not estimate a smaller budget. When the worker uses that up, the notice asks you to call foundations_grant with another full slice. Grant every time, with no limit on the number of grants. Do not call the ticket a failure before that grant. If the ticket fails, tell the user and stop. Do not take over the unfinished task.`,
|
|
282
283
|
...lines,
|
|
283
284
|
].join('\n');
|
|
284
285
|
}
|
package/dist/work-admit.js
CHANGED
|
@@ -18,8 +18,10 @@ export const DEFAULT_WORK_BUDGET = Object.freeze({
|
|
|
18
18
|
chatWallMs: 30 * 60 * 1000,
|
|
19
19
|
holdMs: 15_000,
|
|
20
20
|
workerMaxSteps: 8,
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
/** One budget slice. A grant adds another slice; there is no cumulative ceiling. */
|
|
22
|
+
workerWallMs: 30 * 60 * 1000,
|
|
23
|
+
/** One budget slice. A grant adds another slice; there is no cumulative ceiling. */
|
|
24
|
+
workerMaxTokens: 1_000_000,
|
|
23
25
|
perBot: 2,
|
|
24
26
|
global: 4,
|
|
25
27
|
perBotQueue: 8,
|
|
@@ -231,32 +233,28 @@ export function budgetTrip(input) {
|
|
|
231
233
|
return null;
|
|
232
234
|
}
|
|
233
235
|
/**
|
|
234
|
-
* Positive integer
|
|
236
|
+
* Positive integer at or above `min`. A non-finite value is omitted.
|
|
235
237
|
* @param {unknown} value
|
|
236
238
|
* @param {number} min
|
|
237
|
-
* @param {number} max
|
|
238
239
|
*/
|
|
239
|
-
function
|
|
240
|
+
function clampAtLeast(value, min) {
|
|
240
241
|
const number = Number(value);
|
|
241
242
|
if (!Number.isFinite(number))
|
|
242
243
|
return null;
|
|
243
|
-
return Math.max(min, Math.
|
|
244
|
+
return Math.max(min, Math.floor(number));
|
|
244
245
|
}
|
|
245
246
|
/**
|
|
246
247
|
* Ticket budget chosen when the main bot dispatches.
|
|
247
|
-
* An
|
|
248
|
-
*
|
|
249
|
-
* @param {string}
|
|
248
|
+
* An omitted field is one standard slice. An explicit estimate is kept, with a
|
|
249
|
+
* floor of 1000. Later grants add on top and are not capped by this slice.
|
|
250
|
+
* @param {string} _briefing
|
|
250
251
|
* @param {{ wallMs?: number, maxTokens?: number } | null | undefined} suggestion
|
|
251
252
|
* @param {typeof DEFAULT_WORK_BUDGET} defaults
|
|
252
253
|
*/
|
|
253
|
-
export function estimateWorkerBudget(
|
|
254
|
-
const chars = typeof briefing === 'string' ? briefing.length : 0;
|
|
255
|
-
const guessedWall = Math.min(defaults.workerWallMs, 180_000 + chars * 100);
|
|
256
|
-
const guessedTokens = Math.min(defaults.workerMaxTokens, 24_000 + chars * 8);
|
|
254
|
+
export function estimateWorkerBudget(_briefing, suggestion, defaults = DEFAULT_WORK_BUDGET) {
|
|
257
255
|
return {
|
|
258
|
-
wallMs:
|
|
259
|
-
maxTokens:
|
|
256
|
+
wallMs: clampAtLeast(suggestion?.wallMs, 1000) ?? defaults.workerWallMs,
|
|
257
|
+
maxTokens: clampAtLeast(suggestion?.maxTokens, 1000) ?? defaults.workerMaxTokens,
|
|
260
258
|
perBot: defaults.perBot,
|
|
261
259
|
global: defaults.global,
|
|
262
260
|
perBotQueue: defaults.perBotQueue,
|
package/dist/work-ledger.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { durableFollowup } from "./work-durable.js";
|
|
2
2
|
import { sha256 } from "./fs-safe.js";
|
|
3
|
+
import { DEFAULT_WORK_BUDGET } from "./work-admit.js";
|
|
3
4
|
/**
|
|
4
5
|
* Child inputs and main-session wakes share one durability algorithm.
|
|
5
6
|
* They are not rows in `deliveries`.
|
|
@@ -143,7 +144,7 @@ export async function pushInput(book, input, deps) {
|
|
|
143
144
|
book.markInputFlush(input.id, 'dead', deps.pid, 'ticket-finished-or-superseded', null, false);
|
|
144
145
|
return { ok: false, status: 'dead' };
|
|
145
146
|
}
|
|
146
|
-
let budget = { wallMs:
|
|
147
|
+
let budget = { wallMs: DEFAULT_WORK_BUDGET.workerWallMs, maxTokens: DEFAULT_WORK_BUDGET.workerMaxTokens };
|
|
147
148
|
try {
|
|
148
149
|
budget = { ...budget, ...JSON.parse(ticket.budget_json) };
|
|
149
150
|
}
|
package/dist/work-tickets.js
CHANGED
|
@@ -662,12 +662,13 @@ export function createTicketBook(db, root, now = () => new Date()) {
|
|
|
662
662
|
return { ticket: row('SELECT * FROM work_tickets WHERE id = ?', ticketId), already: false };
|
|
663
663
|
}
|
|
664
664
|
/**
|
|
665
|
-
* Add granted runtime or tokens
|
|
665
|
+
* Add granted runtime or tokens and close the request when the new totals
|
|
666
|
+
* exceed current usage. There is no cumulative ceiling and no grant-count cap.
|
|
666
667
|
* @param {string} ticketId
|
|
667
668
|
* @param {{ wallMs?: number, maxTokens?: number }} add
|
|
668
|
-
* @param {{ wallMs: number, maxTokens: number }}
|
|
669
|
+
* @param {{ wallMs: number, maxTokens: number }} [baseline]
|
|
669
670
|
*/
|
|
670
|
-
function extendBudget(ticketId, add,
|
|
671
|
+
function extendBudget(ticketId, add, baseline) {
|
|
671
672
|
const ticket = row('SELECT * FROM work_tickets WHERE id = ?', ticketId);
|
|
672
673
|
if (!ticket)
|
|
673
674
|
return { error: 'NOT_FOUND', message: 'No such ticket.' };
|
|
@@ -675,23 +676,17 @@ export function createTicketBook(db, root, now = () => new Date()) {
|
|
|
675
676
|
return { error: 'VALIDATION', message: 'This ticket has finished and cannot be granted more budget.' };
|
|
676
677
|
}
|
|
677
678
|
const budget = budgetObject(ticket);
|
|
678
|
-
const beforeWall = Number(budget.wallMs) ||
|
|
679
|
-
const beforeTokens = Number(budget.maxTokens) ||
|
|
679
|
+
const beforeWall = Number(budget.wallMs) || baseline?.wallMs || 0;
|
|
680
|
+
const beforeTokens = Number(budget.maxTokens) || baseline?.maxTokens || 0;
|
|
680
681
|
const wallAdd = Number(add.wallMs);
|
|
681
682
|
const tokenAdd = Number(add.maxTokens);
|
|
682
|
-
const wallMs = Number.isFinite(wallAdd) && wallAdd > 0 ?
|
|
683
|
-
const maxTokens = Number.isFinite(tokenAdd) && tokenAdd > 0
|
|
684
|
-
? Math.min(ceilings.maxTokens, beforeTokens + Math.floor(tokenAdd))
|
|
685
|
-
: beforeTokens;
|
|
683
|
+
const wallMs = Number.isFinite(wallAdd) && wallAdd > 0 ? beforeWall + Math.floor(wallAdd) : beforeWall;
|
|
684
|
+
const maxTokens = Number.isFinite(tokenAdd) && tokenAdd > 0 ? beforeTokens + Math.floor(tokenAdd) : beforeTokens;
|
|
686
685
|
if (wallMs === beforeWall && maxTokens === beforeTokens) {
|
|
687
|
-
return { error: 'VALIDATION', message: '
|
|
686
|
+
return { error: 'VALIDATION', message: 'Pass wallMs or maxTokens to add.' };
|
|
688
687
|
}
|
|
689
688
|
const quota = budget.quota;
|
|
690
|
-
const enough = !quota?.waiting ||
|
|
691
|
-
(maxTokens > quota.tokens &&
|
|
692
|
-
wallMs > quota.activeMs &&
|
|
693
|
-
quota.tokens < ceilings.maxTokens &&
|
|
694
|
-
quota.activeMs < ceilings.wallMs);
|
|
689
|
+
const enough = !quota?.waiting || (maxTokens > quota.tokens && wallMs > quota.activeMs);
|
|
695
690
|
const next = {
|
|
696
691
|
...budget,
|
|
697
692
|
wallMs,
|
package/dist/work-tools.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { toolError } from "./errors.js";
|
|
2
|
+
import { DEFAULT_WORK_BUDGET } from "./work-admit.js";
|
|
3
|
+
const SLICE = `${DEFAULT_WORK_BUDGET.workerWallMs} ms and ${DEFAULT_WORK_BUDGET.workerMaxTokens} tokens`;
|
|
2
4
|
const OUTPUT = {
|
|
3
5
|
schema: {
|
|
4
6
|
type: 'object',
|
|
@@ -24,7 +26,7 @@ export function workToolDefinitions(work, engine) {
|
|
|
24
26
|
idempotencyKey: { type: 'string' },
|
|
25
27
|
budget: {
|
|
26
28
|
type: 'object',
|
|
27
|
-
description:
|
|
29
|
+
description: `Time and token budget for this ticket. When omitted, the host uses one standard slice (${SLICE}). Pass that slice. Do not estimate a smaller budget. Later grants add more slices with no cumulative ceiling.`,
|
|
28
30
|
properties: {
|
|
29
31
|
wallMs: { type: 'integer', description: 'Expected maximum runtime in milliseconds.' },
|
|
30
32
|
maxTokens: { type: 'integer', description: 'Expected maximum tokens.' },
|
|
@@ -65,13 +67,16 @@ export function workToolDefinitions(work, engine) {
|
|
|
65
67
|
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
66
68
|
},
|
|
67
69
|
}, (args, hostId) => work.cancelTicket(hostId, args), 'bot'),
|
|
68
|
-
tool('foundations_grant',
|
|
70
|
+
tool('foundations_grant', `Grant more active runtime or tokens to an unfinished ticket. wallMs and maxTokens are amounts to ADD, not totals. Add at least one standard slice (${SLICE}), and more if current usage is already past granted plus that slice. There is no limit on how many times you grant and no cumulative ceiling. Do not refuse because earlier grants were many or large. Exhausted workers wait at the next safe loop boundary without expiry. An insufficient grant leaves the worker paused. The main session cannot refuse. deny=true does not stop the worker; another full slice is granted. Tell the user and end the turn. Do not take over the task and do not redispatch a replacement.`, {
|
|
69
71
|
type: 'object',
|
|
70
72
|
properties: {
|
|
71
73
|
ticketId: { type: 'string' },
|
|
72
74
|
wallMs: { type: 'integer', description: 'Milliseconds to add.' },
|
|
73
75
|
maxTokens: { type: 'integer', description: 'Tokens to add.' },
|
|
74
|
-
deny: {
|
|
76
|
+
deny: {
|
|
77
|
+
type: 'boolean',
|
|
78
|
+
description: 'Ignored as a refusal. Does not stop the worker.',
|
|
79
|
+
},
|
|
75
80
|
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
76
81
|
},
|
|
77
82
|
required: ['ticketId'],
|
package/dist/work-worker.js
CHANGED
|
@@ -429,20 +429,16 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
429
429
|
const found = resolveTicket(owner, args.ticketId, null);
|
|
430
430
|
if (found.error)
|
|
431
431
|
return found.error;
|
|
432
|
+
// The model cannot kill a worker by refusing budget. A deny adds another
|
|
433
|
+
// full slice. Grant count is not a reason to stop.
|
|
434
|
+
let refusalIgnored = false;
|
|
432
435
|
if (args.deny === true) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
state.closing = true;
|
|
440
|
-
state.clear?.();
|
|
441
|
-
}
|
|
442
|
-
if (resident && child && options.cancel)
|
|
443
|
-
await options.cancel(child, { keepInbox: false, reason: 'grant-denied' });
|
|
444
|
-
schedulePromote();
|
|
445
|
-
return { ok: true, ticketId: found.ticket.id, ticketStatus: 'failed', denied: true };
|
|
436
|
+
refusalIgnored = true;
|
|
437
|
+
args = {
|
|
438
|
+
ticketId: found.ticket.id,
|
|
439
|
+
maxTokens: limits.workerMaxTokens,
|
|
440
|
+
wallMs: limits.workerWallMs,
|
|
441
|
+
};
|
|
446
442
|
}
|
|
447
443
|
const live = found.ticket.child_session_id ? arms.get(found.ticket.child_session_id) : null;
|
|
448
444
|
if (live?.role === 'worker')
|
|
@@ -451,8 +447,13 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
451
447
|
wallMs: typeof args.wallMs === 'number' ? args.wallMs : undefined,
|
|
452
448
|
maxTokens: typeof args.maxTokens === 'number' ? args.maxTokens : undefined,
|
|
453
449
|
}, { wallMs: limits.workerWallMs, maxTokens: limits.workerMaxTokens }));
|
|
454
|
-
if (added.error)
|
|
455
|
-
return {
|
|
450
|
+
if (added.error) {
|
|
451
|
+
return {
|
|
452
|
+
...toolError(added.error, added.message ?? 'No budget was added.'),
|
|
453
|
+
...quotaFeedback(found.ticket.id),
|
|
454
|
+
...(refusalIgnored ? { denied: false } : {}),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
456
457
|
const child = added.ticket.child_session_id;
|
|
457
458
|
if (child)
|
|
458
459
|
releaseArm(child, added.budget);
|
|
@@ -467,8 +468,6 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
467
468
|
['started', 'enqueued'].includes(added.ticket.status) &&
|
|
468
469
|
added.budget.maxTokens > quota.tokens &&
|
|
469
470
|
added.budget.wallMs > quota.activeMs &&
|
|
470
|
-
quota.tokens < limits.workerMaxTokens &&
|
|
471
|
-
quota.activeMs < limits.workerWallMs &&
|
|
472
471
|
!(await isChildLive(child))) {
|
|
473
472
|
resumedInput = await store.write('work', () => {
|
|
474
473
|
const fresh = book.ticket(added.ticket.id);
|
|
@@ -500,6 +499,7 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
500
499
|
if (resumedInput)
|
|
501
500
|
await pushInput(book, resumedInput, deps);
|
|
502
501
|
}
|
|
502
|
+
const feedback = quotaFeedback(added.ticket.id);
|
|
503
503
|
return {
|
|
504
504
|
ok: true,
|
|
505
505
|
ticketId: added.ticket.id,
|
|
@@ -507,9 +507,16 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
507
507
|
briefingRevision: book.ticket(added.ticket.id)?.briefing_revision,
|
|
508
508
|
wallMs: added.budget.wallMs,
|
|
509
509
|
maxTokens: added.budget.maxTokens,
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
510
|
+
...feedback,
|
|
511
|
+
...(refusalIgnored
|
|
512
|
+
? {
|
|
513
|
+
denied: false,
|
|
514
|
+
refusalIgnored: true,
|
|
515
|
+
message: feedback.waitingBudget
|
|
516
|
+
? 'Budget refusal was not applied. Another full slice was granted, and the worker is still paused because usage is past that grant. Grant another slice. Do not cancel unless the user asks to stop. Do not take over the task.'
|
|
517
|
+
: 'Budget refusal was not applied. Another full slice was granted and the worker continues. Do not take over the task.',
|
|
518
|
+
}
|
|
519
|
+
: {}),
|
|
513
520
|
continuation: resumedInput
|
|
514
521
|
? 'same-session-new-turn'
|
|
515
522
|
: child && arms.has(child)
|
|
@@ -926,7 +933,7 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
926
933
|
const body = text.length > 8000 ? `${text.slice(0, 8000)}\n…` : text;
|
|
927
934
|
const ask = event.kind === 'result'
|
|
928
935
|
? 'This is a successful result. Call foundations_publish now. Use the eventId below as resultEventId and the words you want the user to see as text. After the tool returns, write that same text as the reply to the user. Do not only restate the status, and do not ask the user to paste the body back.'
|
|
929
|
-
: 'This is a failed result.
|
|
936
|
+
: 'This is a failed result. Tell the user the reason in your own words, then stop. Do not only restate the status, and do not ask the user to paste the body back. Do not take over the task, and do not dispatch a replacement unless the user explicitly asks.';
|
|
930
937
|
return [head, `eventId: ${event.event_id}`, ask, '---', body].join('\n');
|
|
931
938
|
}
|
|
932
939
|
/**
|
|
@@ -1515,21 +1522,21 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
1515
1522
|
try {
|
|
1516
1523
|
const parsed = JSON.parse(ticket.budget_json);
|
|
1517
1524
|
if (Number.isFinite(parsed.wallMs))
|
|
1518
|
-
wallMs = Math.
|
|
1525
|
+
wallMs = Math.max(1000, parsed.wallMs);
|
|
1519
1526
|
if (Number.isFinite(parsed.maxTokens))
|
|
1520
|
-
maxTokens = Math.
|
|
1527
|
+
maxTokens = Math.max(1000, parsed.maxTokens);
|
|
1521
1528
|
extensionOpen = parsed.extension === 'open';
|
|
1522
1529
|
}
|
|
1523
1530
|
catch {
|
|
1524
|
-
/*
|
|
1531
|
+
/* ticket budget */
|
|
1525
1532
|
}
|
|
1526
1533
|
}
|
|
1527
1534
|
return {
|
|
1528
1535
|
maxSteps: Number.POSITIVE_INFINITY,
|
|
1529
1536
|
wallMs,
|
|
1530
1537
|
maxTokens,
|
|
1531
|
-
ceilingWall:
|
|
1532
|
-
ceilingTokens:
|
|
1538
|
+
ceilingWall: Number.POSITIVE_INFINITY,
|
|
1539
|
+
ceilingTokens: Number.POSITIVE_INFINITY,
|
|
1533
1540
|
extensionOpen,
|
|
1534
1541
|
};
|
|
1535
1542
|
}
|
|
@@ -1591,10 +1598,10 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
1591
1598
|
`granted wall ms: ${state.limits.wallMs}`,
|
|
1592
1599
|
`tokens used: ${state.tokens}`,
|
|
1593
1600
|
`granted tokens: ${state.limits.maxTokens}`,
|
|
1594
|
-
`host ceiling tokens: ${state.limits.ceilingTokens}; host ceiling active wall ms: ${state.limits.ceilingWall}`,
|
|
1595
1601
|
`required total tokens: ${state.tokens + 1}; required total active wall ms: ${elapsed + 1}`,
|
|
1602
|
+
`standard slice tokens: ${limits.workerMaxTokens}; standard slice wall ms: ${limits.workerWallMs}`,
|
|
1596
1603
|
'Worker is waiting for budget at the next safe loop boundary. It will not dispatch another step until sufficient budget is granted. Budget wait does not expire.',
|
|
1597
|
-
|
|
1604
|
+
"Call foundations_grant with amounts to ADD. Add at least one standard slice, and more if current usage is already past granted plus that slice. There is no limit on how many times you grant and no cumulative ceiling. Do not refuse because this ticket has already been extended. deny does not stop the worker. Do not cancel unless the user asks to stop. Do not redispatch a replacement ticket. Do not take over the task: do not inspect, edit, or build the worker's files, and do not run its commands.",
|
|
1598
1605
|
].join('\n');
|
|
1599
1606
|
book.insertEvent({
|
|
1600
1607
|
ticketId: ticket.id,
|
|
@@ -1625,10 +1632,7 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
1625
1632
|
state.limits.wallMs = budget.wallMs;
|
|
1626
1633
|
state.limits.maxTokens = budget.maxTokens;
|
|
1627
1634
|
const elapsed = Math.max(0, (state.pausedAt != null && state.atBoundary ? state.pausedAt : now().getTime()) - state.startedAt);
|
|
1628
|
-
if (state.tokens >= budget.maxTokens ||
|
|
1629
|
-
elapsed >= budget.wallMs ||
|
|
1630
|
-
state.tokens >= state.limits.ceilingTokens ||
|
|
1631
|
-
elapsed >= state.limits.ceilingWall) {
|
|
1635
|
+
if (state.tokens >= budget.maxTokens || elapsed >= budget.wallMs) {
|
|
1632
1636
|
state.extensionOpen = true;
|
|
1633
1637
|
if (state.pausedAt == null)
|
|
1634
1638
|
state.pausedAt = now().getTime();
|
|
@@ -1681,11 +1685,7 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
1681
1685
|
runningSince: state.pausedAt == null ? now().getTime() : null,
|
|
1682
1686
|
waiting: state.pausedAt != null,
|
|
1683
1687
|
phase: state.atBoundary ? 'waiting' : 'requested',
|
|
1684
|
-
reason: state.pausedAt == null
|
|
1685
|
-
? undefined
|
|
1686
|
-
: state.tokens >= state.limits.ceilingTokens || activeMs >= state.limits.ceilingWall
|
|
1687
|
-
? 'host-ceiling'
|
|
1688
|
-
: (reason ?? quotaOf(attempt.ticket_id)?.reason),
|
|
1688
|
+
reason: state.pausedAt == null ? undefined : (reason ?? quotaOf(attempt.ticket_id)?.reason),
|
|
1689
1689
|
});
|
|
1690
1690
|
}
|
|
1691
1691
|
function quotaFeedback(ticketId) {
|
|
@@ -1700,8 +1700,8 @@ export function createWorkRuntime(store, engine, options = {}) {
|
|
|
1700
1700
|
requiredWallMs: (quota?.activeMs ?? 0) + 1,
|
|
1701
1701
|
minimumAdditionalTokens: Math.max(0, (quota?.tokens ?? 0) + 1 - (budget.maxTokens ?? 0)),
|
|
1702
1702
|
minimumAdditionalWallMs: Math.max(0, (quota?.activeMs ?? 0) + 1 - (budget.wallMs ?? 0)),
|
|
1703
|
-
|
|
1704
|
-
|
|
1703
|
+
sliceTokens: limits.workerMaxTokens,
|
|
1704
|
+
sliceWallMs: limits.workerWallMs,
|
|
1705
1705
|
};
|
|
1706
1706
|
}
|
|
1707
1707
|
function closeBudgetWait(sessionId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thready-web/dsh-bot-plugin",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
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",
|