dsh-taskbridge 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/README.md +10 -19
- package/bin/dsh-delegate-mcp.d.ts +20 -3
- package/bin/dsh-delegate-mcp.js +15 -0
- package/codex/dsh-taskbridge.toml +74 -5
- package/docs/INTRODUCTION.md +2 -2
- package/docs/INTRODUCTION.zh.md +2 -2
- package/docs/codex-integration.md +6 -3
- package/docs/conversation-placement.md +44 -7
- package/docs/plugin-market.md +2 -2
- package/docs/redaction-contract.md +47 -4
- package/docs/releases/1.4.2.zh.md +23 -0
- package/docs/releases/1.5.0-token-benchmark.zh.md +73 -0
- package/docs/releases/1.5.0.zh.md +51 -0
- package/docs/runtime-compatibility.md +30 -51
- package/docs/silent-wait.md +84 -0
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +154 -17
- package/lib/client.js +3 -0
- package/package.json +11 -9
- package/src/client/api.js +26 -0
- package/src/codex/installer.js +18 -0
- package/src/config/redact.js +72 -11
- package/src/http/execution-plane.js +76 -5
- package/src/index.d.ts +285 -0
- package/src/index.js +72 -2
- package/src/jobs/activity.js +10 -0
- package/src/jobs/continuation-identity.js +278 -0
- package/src/jobs/engine.js +326 -36
- package/src/jobs/history.js +53 -0
- package/src/mcp/continuation.js +317 -0
- package/src/mcp/metrics.js +343 -0
- package/src/mcp/server.js +1079 -47
- package/src/mcp/wait.js +266 -74
- package/src/review/prompts.js +145 -126
- package/src/runtime/agent-runner.js +165 -0
- package/src/runtime/permissions.js +192 -2
- package/src/runtime/question-call.js +162 -0
- package/src/runtime/questions.js +909 -0
- package/src/runtime/session-placement.js +78 -5
- package/src/version.js +99 -0
package/src/jobs/engine.js
CHANGED
|
@@ -75,8 +75,17 @@ import { resolveRoute } from '../model/routing.js';
|
|
|
75
75
|
import { PROVIDER_SET_CODES, managedProvidersOf } from '../model/providers.js';
|
|
76
76
|
import { RUN_OUTCOMES, RunError, SessionPlacementRefusal, diagnostic, runAgent } from '../runtime/agent-runner.js';
|
|
77
77
|
import { PermissionBridge, PermissionError, PERMISSION_CODES } from '../runtime/permissions.js';
|
|
78
|
+
import { QuestionBridge, QuestionError, QUESTION_CODES } from '../runtime/questions.js';
|
|
78
79
|
import { DELEGATE_SANDBOX_MODE } from '../runtime/sandbox.js';
|
|
79
80
|
import { rememberSession, SESSION_CODES } from '../runtime/session-placement.js';
|
|
81
|
+
import {
|
|
82
|
+
continuationIdentityOf,
|
|
83
|
+
isPathDigest,
|
|
84
|
+
pathDigest,
|
|
85
|
+
recordedDirectoryIs,
|
|
86
|
+
recordedPathIsMasked,
|
|
87
|
+
sameRecordedDirectory,
|
|
88
|
+
} from './continuation-identity.js';
|
|
80
89
|
import { taskTitle } from './title.js';
|
|
81
90
|
import { REVIEW_STATES, reviewWork } from '../review/reviewer.js';
|
|
82
91
|
import { buildReviewPrompt, buildWorkerPrompt } from '../review/prompts.js';
|
|
@@ -261,6 +270,10 @@ const HOST_REVIEW_BY = 'host-commander';
|
|
|
261
270
|
* new lifecycle.
|
|
262
271
|
*/
|
|
263
272
|
const PHASE_AWAITING_PERMISSION = 'awaiting-permission';
|
|
273
|
+
// A distinct phase for a waiting QUESTION, because the two waits need different
|
|
274
|
+
// answers and only one of them can grant anything. The task state stays `running`
|
|
275
|
+
// either way, so no existing reader has to learn a new lifecycle value.
|
|
276
|
+
const PHASE_AWAITING_QUESTION = 'awaiting-question';
|
|
264
277
|
const PHASE_EXECUTE = 'execute';
|
|
265
278
|
|
|
266
279
|
/**
|
|
@@ -294,6 +307,10 @@ export const OBSERVE_TASK_REASONS = Object.freeze({
|
|
|
294
307
|
heartbeat: 'heartbeat',
|
|
295
308
|
attention: 'attention',
|
|
296
309
|
permission: 'permission',
|
|
310
|
+
// The worker asked a human a question through the native question channel. It is a
|
|
311
|
+
// distinct reason from `permission` because answering it grants NOTHING: the
|
|
312
|
+
// commander answers, and any widening still needs its own approval request.
|
|
313
|
+
question: 'question',
|
|
297
314
|
ready: 'ready',
|
|
298
315
|
failed: 'failed',
|
|
299
316
|
cancelled: 'cancelled',
|
|
@@ -652,6 +669,12 @@ export class JobEngine {
|
|
|
652
669
|
// timer when the request settles, so an approval wait can never be charged
|
|
653
670
|
// to the execution timeout.
|
|
654
671
|
permission: { bridge: null, pending: null, evidence: [], pausedAt: null, pausedExecutionMs: 0 },
|
|
672
|
+
// The ordinary-question surface of this run, deliberately SEPARATE from the
|
|
673
|
+
// permission block: a question can never grant access, so it must not be readable
|
|
674
|
+
// as an approval. `pending` is the one question set the worker is waiting on,
|
|
675
|
+
// `evidence` is the bounded settled trail, and `pausedExecutionMs` is the same
|
|
676
|
+
// account the approval wait keeps: time spent waiting for a human is not work.
|
|
677
|
+
question: { bridge: null, pending: null, evidence: [], pausedAt: null, pausedExecutionMs: 0 },
|
|
655
678
|
// The activity monitor for this run. Created with the task, fed from the
|
|
656
679
|
// runner's `onEvent` hook, and disposed with the task: its counters describe
|
|
657
680
|
// THIS run and must not outlive it. It holds metadata only (counts,
|
|
@@ -1596,6 +1619,10 @@ export class JobEngine {
|
|
|
1596
1619
|
state: parent.state,
|
|
1597
1620
|
sourcePath: parent.sourcePath,
|
|
1598
1621
|
executionWorkspacePath: parent.executionPath,
|
|
1622
|
+
// A live record keeps its own exact paths and their digests, so the same
|
|
1623
|
+
// proof a durable row carries is available without a projection.
|
|
1624
|
+
sourcePathDigest: pathDigest(parent.sourcePath),
|
|
1625
|
+
executionPathDigest: pathDigest(parent.executionPath),
|
|
1599
1626
|
isolation: parent.effective?.worker?.isolation ?? null,
|
|
1600
1627
|
conversation: parent.execution?.conversation ?? null,
|
|
1601
1628
|
};
|
|
@@ -1606,6 +1633,8 @@ export class JobEngine {
|
|
|
1606
1633
|
state: durable.state ?? null,
|
|
1607
1634
|
sourcePath: durable.sourcePath ?? null,
|
|
1608
1635
|
executionWorkspacePath: durable.executionWorkspacePath ?? null,
|
|
1636
|
+
sourcePathDigest: durable.sourcePathDigest ?? null,
|
|
1637
|
+
executionPathDigest: durable.executionPathDigest ?? null,
|
|
1609
1638
|
isolation: durable.isolation ?? null,
|
|
1610
1639
|
conversation: durable.execution?.conversation ?? null,
|
|
1611
1640
|
};
|
|
@@ -1731,17 +1760,23 @@ export class JobEngine {
|
|
|
1731
1760
|
SESSION_CODES.continuationState, typeof state === 'string' ? state : 'no recorded end state');
|
|
1732
1761
|
}
|
|
1733
1762
|
// Paths are proof, not a hint: a value written through a projection that rewrote it
|
|
1734
|
-
// (a mask)
|
|
1735
|
-
//
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1763
|
+
// (a mask) can no longer say which directory it named, so it has to be backed by the
|
|
1764
|
+
// digest the same row recorded. Neither a path nor a digest is ever a wildcard, and a
|
|
1765
|
+
// row that proves neither is refused exactly like one with no path at all. This is
|
|
1766
|
+
// only reached for a path that REALLY was shortened: the redaction pattern itself is
|
|
1767
|
+
// narrow (see `config/redact.js`), so an ordinary checkout such as this one keeps its
|
|
1768
|
+
// readable path and is compared directly.
|
|
1769
|
+
for (const [field, digestField, session] of [
|
|
1770
|
+
['sourcePath', 'sourcePathDigest', SESSION_CODES.continuationWorkspaceMismatch],
|
|
1771
|
+
['executionWorkspacePath', 'executionPathDigest', SESSION_CODES.continuationUnavailable],
|
|
1739
1772
|
]) {
|
|
1740
|
-
|
|
1773
|
+
const value = row[field];
|
|
1774
|
+
if (typeof value !== 'string' || value.trim() === ''
|
|
1775
|
+
|| (recordedPathIsMasked(value) && !isPathDigest(row[digestField]))) {
|
|
1741
1776
|
throw refuse('the named task has no reliably recorded path, so its conversation cannot be continued', session, `unusable recorded ${field}`);
|
|
1742
1777
|
}
|
|
1743
1778
|
}
|
|
1744
|
-
if (!
|
|
1779
|
+
if (!recordedDirectoryIs({ path: row.sourcePath, digest: row.sourcePathDigest }, sourcePath)) {
|
|
1745
1780
|
throw refuse('the named task belongs to another source repository, so its conversation was not continued',
|
|
1746
1781
|
SESSION_CODES.continuationWorkspaceMismatch, 'different source repository');
|
|
1747
1782
|
}
|
|
@@ -1763,11 +1798,11 @@ export class JobEngine {
|
|
|
1763
1798
|
SESSION_CODES.continuationUnavailable, 'no recorded session');
|
|
1764
1799
|
}
|
|
1765
1800
|
if (typeof identity.executionPath !== 'string' || identity.executionPath.trim() === ''
|
|
1766
|
-
|| recordedPathIsMasked(identity.executionPath)) {
|
|
1801
|
+
|| (recordedPathIsMasked(identity.executionPath) && !isPathDigest(identity.executionPathDigest))) {
|
|
1767
1802
|
throw refuse('the named task has no usable execution-path identity, so its conversation cannot be continued',
|
|
1768
1803
|
SESSION_CODES.continuationUnavailable, 'unusable recorded execution path');
|
|
1769
1804
|
}
|
|
1770
|
-
if (!
|
|
1805
|
+
if (!recordedDirectoryIs({ path: identity.sourcePath, digest: identity.sourcePathDigest }, sourcePath)) {
|
|
1771
1806
|
throw refuse('the named task belongs to another source repository, so its conversation was not continued',
|
|
1772
1807
|
SESSION_CODES.continuationWorkspaceMismatch, 'identity source repository differs');
|
|
1773
1808
|
}
|
|
@@ -1780,11 +1815,27 @@ export class JobEngine {
|
|
|
1780
1815
|
// is masked cannot say which directory that was, and one that names a different
|
|
1781
1816
|
// execution directory than the identity resolves is another directory's thread —
|
|
1782
1817
|
// the Workspace id alone is not proof, so the Session is never resolved for either.
|
|
1783
|
-
|
|
1818
|
+
//
|
|
1819
|
+
// The conversation lives in the ROW, so the digest it may fall back on is the row's
|
|
1820
|
+
// own execution digest: that digest is the digest of the same directory this path
|
|
1821
|
+
// was written for, so agreement here is a comparison of one fact recorded twice, not
|
|
1822
|
+
// a borrowed proof.
|
|
1823
|
+
const recordedConversation = {
|
|
1824
|
+
path: conversation.workspacePath,
|
|
1825
|
+
digest: row.executionPathDigest,
|
|
1826
|
+
};
|
|
1827
|
+
if (!recordedDirectoryIs(recordedConversation, identity.executionPath)) {
|
|
1784
1828
|
throw refuse('the recorded conversation path does not match its execution directory',
|
|
1785
1829
|
SESSION_CODES.continuationUnavailable, 'conversation workspace path differs');
|
|
1786
1830
|
}
|
|
1787
|
-
|
|
1831
|
+
// The identity's execution directory and the snapshot's must be one directory. The
|
|
1832
|
+
// two documents are written from the same live value, so their digests are the
|
|
1833
|
+
// second proof for a path either projection may have shortened — and two digests
|
|
1834
|
+
// that disagree are a real disagreement, refused like two readable paths that differ.
|
|
1835
|
+
if (!sameRecordedDirectory(
|
|
1836
|
+
{ path: identity.executionPath, digest: identity.executionPathDigest },
|
|
1837
|
+
{ path: row.executionWorkspacePath, digest: row.executionPathDigest },
|
|
1838
|
+
)) {
|
|
1788
1839
|
throw refuse('the recorded conversation identity does not match the named task',
|
|
1789
1840
|
SESSION_CODES.continuationUnavailable, 'identity execution path differs');
|
|
1790
1841
|
}
|
|
@@ -2077,6 +2128,83 @@ export class JobEngine {
|
|
|
2077
2128
|
return bridge;
|
|
2078
2129
|
}
|
|
2079
2130
|
|
|
2131
|
+
/**
|
|
2132
|
+
* Create the ordinary-question bridge for one task, or null when the deployment
|
|
2133
|
+
* cannot offer one.
|
|
2134
|
+
*
|
|
2135
|
+
* The factory is the same shape as the permission factory: the engine owns the task
|
|
2136
|
+
* lifecycle, so it hands the bridge the two observer hooks that keep the task view and
|
|
2137
|
+
* the durable record honest. A deployment without the factory simply cannot surface
|
|
2138
|
+
* questions, which is the safe default.
|
|
2139
|
+
* @param {object} task - the running task.
|
|
2140
|
+
* @returns {object | null} a bridge to arm, or null when unavailable.
|
|
2141
|
+
*/
|
|
2142
|
+
createQuestionBridge(task) {
|
|
2143
|
+
const factory = this.deps?.questionBridge;
|
|
2144
|
+
if (typeof factory !== 'function') return null;
|
|
2145
|
+
let bridge;
|
|
2146
|
+
try {
|
|
2147
|
+
bridge = factory({
|
|
2148
|
+
taskId: task.taskId,
|
|
2149
|
+
connectionId: task.connectionId,
|
|
2150
|
+
onPending: (view) => this.onQuestionPending(task, view),
|
|
2151
|
+
onSettled: (entry) => this.onQuestionSettled(task, entry),
|
|
2152
|
+
});
|
|
2153
|
+
} catch (error) {
|
|
2154
|
+
this.deps?.logger?.warn?.('dsh-delegate: the question bridge could not be created', String(error?.code ?? ''));
|
|
2155
|
+
return null;
|
|
2156
|
+
}
|
|
2157
|
+
if (bridge === null || bridge === undefined || typeof bridge !== 'object'
|
|
2158
|
+
|| typeof bridge.arm !== 'function' || typeof bridge.answer !== 'function') {
|
|
2159
|
+
return null;
|
|
2160
|
+
}
|
|
2161
|
+
return bridge;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
/**
|
|
2165
|
+
* Record one question set the worker is now waiting on.
|
|
2166
|
+
*
|
|
2167
|
+
* The task stays `running` and only its PHASE changes to `awaiting-question`, so
|
|
2168
|
+
* nothing that reads the state contract learns a new lifecycle value. The reason an
|
|
2169
|
+
* observation reports is `question` — immediately, not after a silence threshold.
|
|
2170
|
+
* @param {object} task - the running task.
|
|
2171
|
+
* @param {object} view - the bridge's bounded pending view.
|
|
2172
|
+
* @returns {void}
|
|
2173
|
+
*/
|
|
2174
|
+
onQuestionPending(task, view) {
|
|
2175
|
+
if (TERMINAL.has(task.state)) return;
|
|
2176
|
+
task.question.pending = view;
|
|
2177
|
+
task.question.pausedAt = Date.now();
|
|
2178
|
+
if (task.state === TASK_STATES.running) task.phase = PHASE_AWAITING_QUESTION;
|
|
2179
|
+
this.checkpointHistory(task);
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
/**
|
|
2183
|
+
* Record one settled question set and account for the time spent waiting.
|
|
2184
|
+
* @param {object} task - the task the question belonged to.
|
|
2185
|
+
* @param {object} entry - the bridge's bounded settled view.
|
|
2186
|
+
* @returns {void}
|
|
2187
|
+
*/
|
|
2188
|
+
onQuestionSettled(task, entry) {
|
|
2189
|
+
if (task.question.pending !== null && entry?.requestId === task.question.pending.requestId) {
|
|
2190
|
+
task.question.pending = null;
|
|
2191
|
+
}
|
|
2192
|
+
if (task.question.pausedAt !== null) {
|
|
2193
|
+
task.question.pausedExecutionMs += Math.max(0, Date.now() - task.question.pausedAt);
|
|
2194
|
+
task.question.pausedAt = null;
|
|
2195
|
+
}
|
|
2196
|
+
if (entry !== null && entry !== undefined) {
|
|
2197
|
+
task.question.evidence.push(entry);
|
|
2198
|
+
if (task.question.evidence.length > 8) task.question.evidence.shift();
|
|
2199
|
+
}
|
|
2200
|
+
// Back to execution, never to a new state: an answered question and an abandoned one
|
|
2201
|
+
// both leave the task `running` until the run itself reaches an outcome.
|
|
2202
|
+
if (task.state === TASK_STATES.running && task.phase === PHASE_AWAITING_QUESTION) {
|
|
2203
|
+
task.phase = PHASE_EXECUTE;
|
|
2204
|
+
}
|
|
2205
|
+
this.checkpointHistory(task);
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2080
2208
|
/**
|
|
2081
2209
|
* Record one request the worker is now waiting on.
|
|
2082
2210
|
*
|
|
@@ -2278,6 +2406,66 @@ export class JobEngine {
|
|
|
2278
2406
|
return { task: this.view(task), permission: settled, hostAcceptance: null };
|
|
2279
2407
|
}
|
|
2280
2408
|
|
|
2409
|
+
/**
|
|
2410
|
+
* Answer one pending QUESTION for one task.
|
|
2411
|
+
*
|
|
2412
|
+
* The checks are the permission decision's, in the same order, because the identity
|
|
2413
|
+
* rule is the same: a task this caller cannot prove is answered as absent, a sentinel
|
|
2414
|
+
* task has no pending question, and the authorization is re-checked at the answer so
|
|
2415
|
+
* a switch turned off or a revoked grant cannot be bypassed by answering late.
|
|
2416
|
+
*
|
|
2417
|
+
* What is DIFFERENT is what the answer can do: nothing here grants access. The bridge
|
|
2418
|
+
* validates the batch against the questions the worker actually asked and settles the
|
|
2419
|
+
* paused tool call with the native answer shape. Any widening the worker then wants
|
|
2420
|
+
* still goes through {@link decidePermission}.
|
|
2421
|
+
* @param {object} request - `taskId`, `requestId`, `answers`, and the authenticated
|
|
2422
|
+
* `connectionId` (supplied by the plane, never by the caller's body).
|
|
2423
|
+
* @returns {object} bounded result: `{ task, question, answer: receipt, hostAcceptance: null }`.
|
|
2424
|
+
* @throws {JobError} on any refusal.
|
|
2425
|
+
*/
|
|
2426
|
+
decideQuestion(request) {
|
|
2427
|
+
const connectionId = typeof request?.connectionId === 'string' ? request.connectionId : null;
|
|
2428
|
+
if (connectionId === null) {
|
|
2429
|
+
throw new JobError(JOB_CODES.taskNotFound, 'no such task for this connection', {});
|
|
2430
|
+
}
|
|
2431
|
+
const taskId = typeof request?.taskId === 'string' ? request.taskId.trim() : '';
|
|
2432
|
+
if (taskId === '') {
|
|
2433
|
+
throw new JobError(QUESTION_CODES.questionNotFound, 'taskId is required', { field: 'taskId' });
|
|
2434
|
+
}
|
|
2435
|
+
const task = this.tasks.get(taskId);
|
|
2436
|
+
if (task === undefined || task.connectionId !== connectionId) {
|
|
2437
|
+
throw new JobError(JOB_CODES.taskNotFound, 'no such task for this connection', { taskId });
|
|
2438
|
+
}
|
|
2439
|
+
if (TERMINAL.has(task.state)) {
|
|
2440
|
+
throw new JobError(QUESTION_CODES.questionSettled,
|
|
2441
|
+
'this task has already ended; its pending question is history only', { taskId, state: task.state });
|
|
2442
|
+
}
|
|
2443
|
+
if (this.posture().authorized !== true) {
|
|
2444
|
+
throw new JobError(JOB_CODES.notAuthorized, 'delegation is no longer authorized, so no answer may be applied', {});
|
|
2445
|
+
}
|
|
2446
|
+
this.assertLive(task, 'question-decide');
|
|
2447
|
+
const bridge = task.question?.bridge ?? null;
|
|
2448
|
+
if (bridge === null || bridge === undefined || typeof bridge.decide !== 'function') {
|
|
2449
|
+
throw new JobError(QUESTION_CODES.notPending, 'this task has no pending question', { taskId });
|
|
2450
|
+
}
|
|
2451
|
+
let receipt;
|
|
2452
|
+
try {
|
|
2453
|
+
receipt = bridge.decide({ requestId: request?.requestId, answers: request?.answers });
|
|
2454
|
+
} catch (error) {
|
|
2455
|
+
if (error instanceof QuestionError) {
|
|
2456
|
+
throw new JobError(error.code, error.message, error.details);
|
|
2457
|
+
}
|
|
2458
|
+
throw error;
|
|
2459
|
+
}
|
|
2460
|
+
return {
|
|
2461
|
+
task: this.view(task),
|
|
2462
|
+
question: task.question.pending === null ? this.questionView(task) : redactDeep(task.question.pending),
|
|
2463
|
+
answer: receipt,
|
|
2464
|
+
// Explicit: answering a question is never an approval of anything.
|
|
2465
|
+
hostAcceptance: null,
|
|
2466
|
+
};
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2281
2469
|
/**
|
|
2282
2470
|
* Record the commander's delivery review for one finished task.
|
|
2283
2471
|
*
|
|
@@ -2658,6 +2846,53 @@ export class JobEngine {
|
|
|
2658
2846
|
if (cause === 'dispose') task.permission.bridge = null;
|
|
2659
2847
|
}
|
|
2660
2848
|
|
|
2849
|
+
/**
|
|
2850
|
+
* Stop every outstanding QUESTION of one task and disarm its bridge.
|
|
2851
|
+
*
|
|
2852
|
+
* Same lifecycle as {@link releasePermissionBridge} and called from the same paths,
|
|
2853
|
+
* for the same reason: a worker paused on a question must be released with a native
|
|
2854
|
+
* refusal when the run is cancelled, switched off, revoked or disposed, instead of
|
|
2855
|
+
* waiting for an answer nobody will give.
|
|
2856
|
+
* @param {object} task - task record.
|
|
2857
|
+
* @param {string} [cause] - `stop` (default) or `dispose`.
|
|
2858
|
+
* @returns {void}
|
|
2859
|
+
*/
|
|
2860
|
+
releaseQuestionBridge(task, cause = 'stop') {
|
|
2861
|
+
const bridge = task.question?.bridge ?? null;
|
|
2862
|
+
if (bridge === null || bridge === undefined) return;
|
|
2863
|
+
try {
|
|
2864
|
+
if (cause === 'dispose') bridge.dispose?.();
|
|
2865
|
+
else bridge.stop?.();
|
|
2866
|
+
} catch (error) {
|
|
2867
|
+
this.deps?.logger?.warn?.('dsh-delegate: the question bridge could not be stopped', String(error?.code ?? ''));
|
|
2868
|
+
}
|
|
2869
|
+
if (task.question.pending !== null) task.question.pending = null;
|
|
2870
|
+
task.question.pausedAt = null;
|
|
2871
|
+
if (cause === 'dispose') task.question.bridge = null;
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
/**
|
|
2875
|
+
* The bounded, public QUESTION block of one task.
|
|
2876
|
+
*
|
|
2877
|
+
* It is separate from {@link permissionView} on purpose and says so: `grantsAccess`
|
|
2878
|
+
* is always false, so no reader can mistake an answered question for an authorization.
|
|
2879
|
+
* `pending` carries the questions actually asked — text, options, and whether the
|
|
2880
|
+
* caller declared an intent — and never a reasoning stream or transcript.
|
|
2881
|
+
* @param {object} task - task record.
|
|
2882
|
+
* @returns {object} bounded question view.
|
|
2883
|
+
*/
|
|
2884
|
+
questionView(task) {
|
|
2885
|
+
const pending = task.question?.pending ?? null;
|
|
2886
|
+
return {
|
|
2887
|
+
bridged: task.question?.bridge !== null && task.question?.bridge !== undefined,
|
|
2888
|
+
waiting: pending !== null,
|
|
2889
|
+
pending: pending === null ? null : redactDeep(pending),
|
|
2890
|
+
evidence: (task.question?.evidence ?? []).map((entry) => redactDeep(entry)),
|
|
2891
|
+
pausedExecutionMs: task.question?.pausedExecutionMs ?? 0,
|
|
2892
|
+
grantsAccess: false,
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2661
2896
|
/**
|
|
2662
2897
|
* The bounded, public permission block of one task.
|
|
2663
2898
|
*
|
|
@@ -2705,6 +2940,7 @@ export class JobEngine {
|
|
|
2705
2940
|
// `releasePermissionBridge(task, 'dispose')` is idempotent, so disposing here
|
|
2706
2941
|
// does not double-settle.
|
|
2707
2942
|
this.releasePermissionBridge(task, reason === 'dispose' ? 'dispose' : 'stop');
|
|
2943
|
+
this.releaseQuestionBridge(task, reason === 'dispose' ? 'dispose' : 'stop');
|
|
2708
2944
|
task.cancelRequested = true;
|
|
2709
2945
|
task.cancelledBy = task.cancelledBy ?? reason;
|
|
2710
2946
|
try {
|
|
@@ -2761,6 +2997,7 @@ export class JobEngine {
|
|
|
2761
2997
|
// Admission never created an executor, so any bridge it did create (it is
|
|
2762
2998
|
// created just before the runner call, so normally none) is disposed here too.
|
|
2763
2999
|
this.releasePermissionBridge(task, 'dispose');
|
|
3000
|
+
this.releaseQuestionBridge(task, 'dispose');
|
|
2764
3001
|
task.endedAt = task.endedAt ?? Date.now();
|
|
2765
3002
|
// A preflight that ran out of budget is a timeout, not a cancellation: it is
|
|
2766
3003
|
// the same budget the run itself would have failed on, and reporting it as
|
|
@@ -2930,6 +3167,11 @@ export class JobEngine {
|
|
|
2930
3167
|
// the run keeps the fail-closed `never` stance and nothing about it changes.
|
|
2931
3168
|
const bridge = this.createPermissionBridge(task);
|
|
2932
3169
|
task.permission.bridge = bridge;
|
|
3170
|
+
// The question bridge is its own surface, created the same way and for the same
|
|
3171
|
+
// reason: the runner arms it in the run's setup so the native answerer exists
|
|
3172
|
+
// before the prompt, and the engine records the wait here.
|
|
3173
|
+
const questionBridge = this.createQuestionBridge(task);
|
|
3174
|
+
task.question.bridge = questionBridge;
|
|
2933
3175
|
// `started` means "this task called the runner", not "the executor is
|
|
2934
3176
|
// running": placement resolves before the runner sees an Agent, so the task
|
|
2935
3177
|
// is handed over in `before-create` and only the executor's own events
|
|
@@ -2961,6 +3203,10 @@ export class JobEngine {
|
|
|
2961
3203
|
// run's setup, scanned by the engine before it is offered here, and
|
|
2962
3204
|
// disposed when the run ends. `null` keeps the deterministic `never` stance.
|
|
2963
3205
|
...(bridge === null ? {} : { permissionBridge: bridge }),
|
|
3206
|
+
// The ordinary-question answerer for THIS task's own Agent. Independent of the
|
|
3207
|
+
// approval bridge: a `never` approval stance still lets the worker ask a
|
|
3208
|
+
// question, and answering one grants nothing.
|
|
3209
|
+
...(questionBridge === null ? {} : { questionBridge }),
|
|
2964
3210
|
configureDelegatedSession: this.deps.configureDelegatedSession,
|
|
2965
3211
|
policyServices: this.deps.policyServices,
|
|
2966
3212
|
// The engine is the authority for "may this chain be joined": a parent it
|
|
@@ -3444,6 +3690,13 @@ export class JobEngine {
|
|
|
3444
3690
|
settleReason(task) {
|
|
3445
3691
|
const terminal = terminalReason(task);
|
|
3446
3692
|
if (terminal !== null) return terminal;
|
|
3693
|
+
// A QUESTION outranks silence for the same reason a permission does, and it is the
|
|
3694
|
+
// defect this reason exists to remove: a worker waiting for a human answer used to
|
|
3695
|
+
// be reported only when the ten-minute silence threshold fired, so the commander
|
|
3696
|
+
// learned about the question long after the worker had asked it.
|
|
3697
|
+
if (task?.question?.pending !== null && task?.question?.pending !== undefined) {
|
|
3698
|
+
return OBSERVE_TASK_REASONS.question;
|
|
3699
|
+
}
|
|
3447
3700
|
if (task?.permission?.pending !== null && task?.permission?.pending !== undefined) {
|
|
3448
3701
|
return OBSERVE_TASK_REASONS.permission;
|
|
3449
3702
|
}
|
|
@@ -3502,6 +3755,16 @@ export class JobEngine {
|
|
|
3502
3755
|
reason,
|
|
3503
3756
|
// The full, unshortened redacted request on the ONE reason that needs it.
|
|
3504
3757
|
permission: reason === OBSERVE_TASK_REASONS.permission ? pending : null,
|
|
3758
|
+
// The questions the worker actually asked, on the one reason that needs them.
|
|
3759
|
+
// Carried here rather than only inside the task summary so a waiting host gets the
|
|
3760
|
+
// question, its options and its detail in ONE answer — the same shape the
|
|
3761
|
+
// permission reason uses, and for the same reason: a commander that had to read
|
|
3762
|
+
// the task first would spend a round trip before it could answer.
|
|
3763
|
+
question: reason === OBSERVE_TASK_REASONS.question
|
|
3764
|
+
? (task?.question?.pending === null || task?.question?.pending === undefined
|
|
3765
|
+
? null
|
|
3766
|
+
: redactDeep(task.question.pending))
|
|
3767
|
+
: null,
|
|
3505
3768
|
// The typed, bounded diagnostic for a repeated-failure reminder. It is the only
|
|
3506
3769
|
// thing that distinguishes that reminder from an ordinary silence report, whose
|
|
3507
3770
|
// own diagnostic is `selfCheck`.
|
|
@@ -3605,6 +3868,7 @@ export class JobEngine {
|
|
|
3605
3868
|
// (the worker's paused tool call resumes `unavailable`) and the bridge can never
|
|
3606
3869
|
// answer a request that outlived the run it belonged to.
|
|
3607
3870
|
this.releasePermissionBridge(task, 'dispose');
|
|
3871
|
+
this.releaseQuestionBridge(task, 'dispose');
|
|
3608
3872
|
// The monitor is stopped BEFORE the record is persisted, so no observation can
|
|
3609
3873
|
// still be waiting on a run that has already ended. The summary survives on the
|
|
3610
3874
|
// task, so the stored view still says how much activity there was.
|
|
@@ -3696,6 +3960,7 @@ export class JobEngine {
|
|
|
3696
3960
|
let timer = null;
|
|
3697
3961
|
try {
|
|
3698
3962
|
const view = this.view(task);
|
|
3963
|
+
this.attachContinuationProof(view, task);
|
|
3699
3964
|
const bounded = new Promise((resolvePromise, rejectPromise) => {
|
|
3700
3965
|
timer = setTimeout(() => {
|
|
3701
3966
|
rejectPromise(new JobError(JOB_CODES.historyFailed, 'the job history write exceeded its time budget', {
|
|
@@ -3724,6 +3989,38 @@ export class JobEngine {
|
|
|
3724
3989
|
}
|
|
3725
3990
|
}
|
|
3726
3991
|
|
|
3992
|
+
/**
|
|
3993
|
+
* Put the verifiable continuation identity beside the two display paths.
|
|
3994
|
+
*
|
|
3995
|
+
* The stored record needs BOTH: the readable path an operator recognises, and a
|
|
3996
|
+
* proof that survives the projection it is written through. The digests are opaque
|
|
3997
|
+
* to redaction, so a row whose path was shortened still proves which directory it
|
|
3998
|
+
* named — and a row whose digest is absent proves nothing, which is what a follow-up
|
|
3999
|
+
* must refuse.
|
|
4000
|
+
*
|
|
4001
|
+
* The digests are taken from the identity {@link rememberConversation} actually
|
|
4002
|
+
* wrote when that ran for the same placement, so the two durable documents cannot
|
|
4003
|
+
* record two different identities for one task. Otherwise they are derived from the
|
|
4004
|
+
* task's own live paths.
|
|
4005
|
+
* @param {object} view - the public view about to be stored.
|
|
4006
|
+
* @param {object} task - terminal task record.
|
|
4007
|
+
* @returns {void}
|
|
4008
|
+
*/
|
|
4009
|
+
attachContinuationProof(view, task) {
|
|
4010
|
+
if (view === null || typeof view !== 'object') return;
|
|
4011
|
+
const placement = task.execution?.conversation ?? null;
|
|
4012
|
+
const written = task.continuationIdentityWritten ?? null;
|
|
4013
|
+
const usable = written !== null && placement !== null
|
|
4014
|
+
&& written.workspaceId === (placement.workspaceId ?? '')
|
|
4015
|
+
&& written.sessionId === (placement.sessionId ?? '');
|
|
4016
|
+
const identity = usable ? written : continuationIdentityOf(task, placement, task.effective?.worker?.isolation ?? null);
|
|
4017
|
+
if (identity === null) return;
|
|
4018
|
+
view.sourcePathDigest = identity.sourcePathDigest;
|
|
4019
|
+
view.executionPathDigest = identity.executionPathDigest;
|
|
4020
|
+
view.workspaceId = identity.workspaceId;
|
|
4021
|
+
view.sessionId = identity.sessionId;
|
|
4022
|
+
}
|
|
4023
|
+
|
|
3727
4024
|
/**
|
|
3728
4025
|
* Build the public view one review write should store.
|
|
3729
4026
|
*
|
|
@@ -4056,6 +4353,12 @@ export class JobEngine {
|
|
|
4056
4353
|
const placement = task.execution?.conversation ?? null;
|
|
4057
4354
|
if (store === null || store === undefined || placement === null) return;
|
|
4058
4355
|
const worktree = task.worktree === null || task.worktree === undefined ? null : task.worktree;
|
|
4356
|
+
// The canonical identity, computed once here and reused by the durable history row
|
|
4357
|
+
// (see {@link persistHistory}): the paths as one canonical spelling plus the digest
|
|
4358
|
+
// of each, so a later follow-up compares a verifiable identity instead of relying on
|
|
4359
|
+
// a display string that a projection may have shortened.
|
|
4360
|
+
const identity = continuationIdentityOf(task, placement, task.effective?.worker?.isolation ?? null);
|
|
4361
|
+
task.continuationIdentityWritten = identity;
|
|
4059
4362
|
try {
|
|
4060
4363
|
const saved = await rememberSession(store, {
|
|
4061
4364
|
workspaceId: placement.workspaceId,
|
|
@@ -4277,6 +4580,11 @@ export class JobEngine {
|
|
|
4277
4580
|
sourcePath: task.sourcePath,
|
|
4278
4581
|
workspacePath: task.executionPath ?? task.sourcePath,
|
|
4279
4582
|
executionWorkspacePath: task.executionPath,
|
|
4583
|
+
// The verifiable half of the same identity (a digest of each canonical path, plus
|
|
4584
|
+
// the DSH Workspace/Session the run drove) is attached by
|
|
4585
|
+
// {@link attachContinuationProof} when the view is STORED. It is not part of the
|
|
4586
|
+
// live projection: a reader of a running task does not need it, and one place
|
|
4587
|
+
// that decides it cannot disagree with another.
|
|
4280
4588
|
isolation: effective === null ? null : effective.worker.isolation,
|
|
4281
4589
|
connectionId: task.connectionId,
|
|
4282
4590
|
grantId: task.grantId,
|
|
@@ -4336,6 +4644,11 @@ export class JobEngine {
|
|
|
4336
4644
|
// the standing mode the decision did NOT change. Present on every task, so a
|
|
4337
4645
|
// reader never has to infer "no bridge" from a missing field.
|
|
4338
4646
|
permission: this.permissionView(task),
|
|
4647
|
+
// The ordinary-question surface: the questions the worker is actually waiting on,
|
|
4648
|
+
// the settled trail, and how much of the execution budget went to waiting. It is
|
|
4649
|
+
// a separate block because answering a question grants nothing — `grantsAccess`
|
|
4650
|
+
// is stated as `false` rather than left to be inferred.
|
|
4651
|
+
question: this.questionView(task),
|
|
4339
4652
|
// The approval stance the run installed and read back (`never` without a
|
|
4340
4653
|
// bridge, `ask` with an armed one), recorded from the run itself.
|
|
4341
4654
|
approval: task.execution?.approval ?? null,
|
|
@@ -4403,12 +4716,14 @@ export class JobEngine {
|
|
|
4403
4716
|
// A terminal task may still hold a bridge if its own teardown has not run
|
|
4404
4717
|
// yet; disposing is idempotent and cannot answer anything after this point.
|
|
4405
4718
|
this.releasePermissionBridge(task, 'dispose');
|
|
4719
|
+
this.releaseQuestionBridge(task, 'dispose');
|
|
4406
4720
|
continue;
|
|
4407
4721
|
}
|
|
4408
4722
|
this.abortTask(task, 'dispose');
|
|
4409
4723
|
// Teardown is not a cancel: the answerer goes away, so the worker's paused
|
|
4410
4724
|
// call must be told the channel is gone rather than that it was withdrawn.
|
|
4411
4725
|
this.releasePermissionBridge(task, 'dispose');
|
|
4726
|
+
this.releaseQuestionBridge(task, 'dispose');
|
|
4412
4727
|
count += 1;
|
|
4413
4728
|
}
|
|
4414
4729
|
await Promise.race([
|
|
@@ -4484,31 +4799,6 @@ function samePath(a, b) {
|
|
|
4484
4799
|
return normalize(a) === normalize(b);
|
|
4485
4800
|
}
|
|
4486
4801
|
|
|
4487
|
-
/**
|
|
4488
|
-
* The placeholder a redacted path segment is rewritten to.
|
|
4489
|
-
*/
|
|
4490
|
-
const PATH_MASK_SEGMENT = 'masks-user-profile-segment';
|
|
4491
|
-
|
|
4492
|
-
/**
|
|
4493
|
-
* Whether a persisted path cannot prove which directory it names.
|
|
4494
|
-
*
|
|
4495
|
-
* Durable documents are projected through redaction, which replaces an
|
|
4496
|
-
* account-identifying directory name with the placeholder above. A path carrying that
|
|
4497
|
-
* placeholder is a shortened spelling: nothing can prove which directory stood there,
|
|
4498
|
-
* so it is never compared into a match and is treated exactly like a missing path — the
|
|
4499
|
-
* mask only ever causes a refusal, it never stands for equality. A real directory whose
|
|
4500
|
-
* name merely *starts with* the placeholder is still its own directory, which is why the
|
|
4501
|
-
* test is for the whole segment.
|
|
4502
|
-
* @param {unknown} value - candidate path.
|
|
4503
|
-
* @returns {boolean} true when the path was rewritten and can only be refused.
|
|
4504
|
-
*/
|
|
4505
|
-
function recordedPathIsMasked(value) {
|
|
4506
|
-
if (typeof value !== 'string') return false;
|
|
4507
|
-
return value
|
|
4508
|
-
.split(/[\\/]+/)
|
|
4509
|
-
.some((part) => part.trim() === PATH_MASK_SEGMENT);
|
|
4510
|
-
}
|
|
4511
|
-
|
|
4512
4802
|
/**
|
|
4513
4803
|
* Review selection projection for a review that never ran.
|
|
4514
4804
|
* @param {object} review - effective review block.
|
package/src/jobs/history.js
CHANGED
|
@@ -573,6 +573,14 @@ function projectView(view, maxEntryBytes, options = {}) {
|
|
|
573
573
|
sourcePath: path(view.sourcePath, ctx, 'sourcePath'),
|
|
574
574
|
workspacePath: path(view.workspacePath, ctx, 'workspacePath'),
|
|
575
575
|
executionWorkspacePath: path(view.executionWorkspacePath, ctx, 'executionWorkspacePath'),
|
|
576
|
+
// The verifiable continuation identity stored beside those paths. A digest is
|
|
577
|
+
// opaque to redaction, so a row whose path a projection shortened can still prove
|
|
578
|
+
// which directory it named; a row without one proves nothing and is refused by a
|
|
579
|
+
// follow-up. Nothing here is executable material or conversation content.
|
|
580
|
+
sourcePathDigest: digest(view.sourcePathDigest),
|
|
581
|
+
executionPathDigest: digest(view.executionPathDigest),
|
|
582
|
+
workspaceId: label(view.workspaceId),
|
|
583
|
+
sessionId: label(view.sessionId),
|
|
576
584
|
isolation: knownValue(view.isolation, ['worktree', 'shared']),
|
|
577
585
|
interruptedFrom: knownValue(view.interruptedFrom, ['pending', 'running']),
|
|
578
586
|
// The connection identity is provenance: which external connection asked for
|
|
@@ -947,6 +955,37 @@ function permissionEntryView(value, ctx, field) {
|
|
|
947
955
|
reusable: grant.reusable === true,
|
|
948
956
|
},
|
|
949
957
|
standingModeUnchanged: value.standingModeUnchanged === true,
|
|
958
|
+
// Whether the commander's rejection reason actually reached the worker, and — only when
|
|
959
|
+
// it did — the exact text. Stored because "the worker was told why" is a claim that must
|
|
960
|
+
// be checkable after a restart, and bounded so one long note cannot grow the record.
|
|
961
|
+
rejectionFeedback: rejectionFeedbackView(value.rejectionFeedback, ctx, `${field}.rejectionFeedback`),
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Bounded projection of one rejection-feedback outcome.
|
|
967
|
+
*
|
|
968
|
+
* `delivered` and `reason` are kept VERBATIM (they are a closed vocabulary and the fact the
|
|
969
|
+
* record exists to state). `text` is kept only when delivery succeeded — a failed note has
|
|
970
|
+
* nothing to quote — and is bounded, because it is prose.
|
|
971
|
+
* @param {unknown} value - the delivered/not-delivered outcome.
|
|
972
|
+
* @param {object} ctx - cut context.
|
|
973
|
+
* @param {string} field - field label for a cut.
|
|
974
|
+
* @returns {object | null} bounded copy.
|
|
975
|
+
*/
|
|
976
|
+
function rejectionFeedbackView(value, ctx, field) {
|
|
977
|
+
if (!isPlainObject(value)) return null;
|
|
978
|
+
const delivered = value.delivered === true;
|
|
979
|
+
const quoted = delivered && typeof value.text === 'string' && value.text !== ''
|
|
980
|
+
? text(value.text, ctx, field, MAX_MESSAGE_CHARS)
|
|
981
|
+
: null;
|
|
982
|
+
return {
|
|
983
|
+
delivered,
|
|
984
|
+
reason: label(value.reason),
|
|
985
|
+
requestId: label(value.requestId),
|
|
986
|
+
callId: label(value.callId),
|
|
987
|
+
messageId: label(value.messageId),
|
|
988
|
+
text: quoted,
|
|
950
989
|
};
|
|
951
990
|
}
|
|
952
991
|
|
|
@@ -1486,6 +1525,20 @@ function path(value, ctx = null, field = '') {
|
|
|
1486
1525
|
return value.slice(0, MAX_PATH_CHARS);
|
|
1487
1526
|
}
|
|
1488
1527
|
|
|
1528
|
+
/**
|
|
1529
|
+
* A stored continuation digest, kept verbatim when well formed.
|
|
1530
|
+
*
|
|
1531
|
+
* A digest is fixed-length and opaque, so it is never shortened: a cut digest would
|
|
1532
|
+
* compare unequal to every real directory and turn "provable" into "refused" without
|
|
1533
|
+
* saying so. A value that is not a well-formed digest is dropped, which is the same
|
|
1534
|
+
* as the row having none — the follow-up then refuses rather than guesses.
|
|
1535
|
+
* @param {unknown} value - candidate digest.
|
|
1536
|
+
* @returns {string | null} the digest, or null.
|
|
1537
|
+
*/
|
|
1538
|
+
function digest(value) {
|
|
1539
|
+
return typeof value === 'string' && /^sha256:[0-9a-f]{64}$/u.test(value) ? value : null;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1489
1542
|
/**
|
|
1490
1543
|
* @param {unknown} value - value to read.
|
|
1491
1544
|
* @param {string} field - field label for truncation reporting.
|