@tnunamak/dalan 0.8.5 → 0.9.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 +9 -0
- package/bin/dot-acp-agent.mjs +197 -43
- package/bin/dot-worker.mjs +75 -11
- package/docs/design/target-architecture-v2.md +1 -0
- package/docs/t3-integration.md +6 -0
- package/integrations/t3/acp-kit/src/t3-envelope.mjs +20 -2
- package/package.json +1 -1
- package/src/acp-bridge.mjs +80 -15
- package/src/host-execution-policy.mjs +1 -1
- package/src/inbox.mjs +44 -2
- package/src/patch-apply.mjs +125 -42
- package/src/server.mjs +196 -46
- package/src/store.mjs +371 -68
- package/src/submission-policy.mjs +59 -8
- package/src/tool-registry.mjs +6 -0
- package/src/workspace.mjs +92 -5
|
@@ -125,6 +125,7 @@ When a peer speaks A2A, Dalan maps A2A task, message and artifact to work, quest
|
|
|
125
125
|
- Priority classes: `normal` (queue, with an estimate) and `background` (queue behind normal), as stored today (`CHECK(priority IN ('normal','background'))`). A start-or-refuse class would need a schema and admission change; v2 does not add one. The parent gets the admission answer within seconds and can cancel and route elsewhere.
|
|
126
126
|
- A free lane or a first claim is not a start. Today `queueWaitEvidence` (`src/store.mjs#queueWaitEvidence`) measures to the first stored claim and uses lower bounds for work that expired unclaimed. v2 measures two latencies: **claimed** (first claim) and **started** (the worker's first substantive event on the work, such as a workspace read or a progress event). Censored samples (expired or cancelled before a claim or a start) are counted in their own group and never mixed into the percentiles.
|
|
127
127
|
- Admission answer, computed before submit with a defined stale-answer policy: `start: "now"` only when Dalan has reserved a lane for this work and the worker's subscription is live at that moment. Otherwise `start: "queued"` with the facts: eligible ready work ahead (count and oldest age, same or higher class), measured claimed and started latencies (p50/p90, n, window, censored count), and the worker state (`live`, `break until T`, `no live subscription`). Below the existing minimum of 5 samples (`QUEUE_WINDOW.minSamples`, `src/store.mjs#QUEUE_WINDOW`) it says `insufficient_history` and gives no number. Lower bounds from work that expired unclaimed are reported as their own group; today they are mixed into the percentiles, which understates waits.
|
|
128
|
+
- A preview reports a forecast. A normal waiting caller can reserve capacity for its request as part of a successful submit when it is the eligible queue head. The reservation expires at `reserved_until` after at most 15 seconds, and a delayed native reply displays it as queued. Replaying a submit does not extend a reservation. Claiming the request consumes the hold. Its claim and first substantive worker event remain separate measurements.
|
|
128
129
|
- Track record, with outcomes kept apart: `unable_to_run`, `checks_failed`, `check_passed`, `landed` (merged or applied by the owner), plus `refused_by_provider`, n and window. "No passing check" is never reported as one blocked number.
|
|
129
130
|
- `status.dispatch` stays as a simple diagnostic beside this answer (section 2).
|
|
130
131
|
- No delegated-agent product shows a reliable ETA (see the prior-art list). Dalan reports only measured values with their basis, so a caller can judge them.
|
package/docs/t3-integration.md
CHANGED
|
@@ -20,6 +20,8 @@ DOT_ACP_SOCKET=/path/to/admin.sock # the bridge's admin socket; the default is
|
|
|
20
20
|
|
|
21
21
|
Add one entry for each worker, so a ChatGPT worker and Muse (muse.ai), a hosted cloud agent, each appear as a model. These adapter settings keep the `DOT_ACP_*` names. Builds also need `DALAN_ACP_BUILD_OWNERS`: see [Builds through the T3 worker provider](#builds-through-the-t3-worker-provider).
|
|
22
22
|
|
|
23
|
+
If the adapter exits before returning the result, the owner can find unread native work in `dalan inbox --all` from the requester host. Use the same bridge home and private adapter configuration. When the adapter's private state lives outside that bridge home, set `DOT_ACP_STATE_DIR` and `DOT_ACP_SECRET_FILE` to the matching local paths on the owner CLI. `dalan inbox --producer ID` accepts the saved ACP session ID or the original host task ID when the host supplies it. The inbox and the native result count in `dalan status` are passive reads. The count describes results available to this CLI. It does not confirm whether T3 accepted a completion before the adapter stopped.
|
|
24
|
+
|
|
23
25
|
A separate, opt-in feature lets a worker list, read and write T3 threads. It gives the worker write and control access to your T3 threads, so read [T3 tools](t3-reverse-control.md) before you enable it.
|
|
24
26
|
|
|
25
27
|
<a id="t3-task-thread-delivery"></a>
|
|
@@ -44,6 +46,10 @@ After verifying the destination, submit with `dalan submit --worker NAME --execu
|
|
|
44
46
|
|
|
45
47
|
To send a corrected version of earlier work, add `--revises REQUEST_ID` and a new `--revision` (the same value as the earlier job is refused). `dalan submit` reads the earlier job's owner capability from its local receipt, so run it where the earlier job was submitted. It does not cancel the earlier job. A queued or running earlier job gets an owner note that it is superseded. When it finishes, `dalan get` shows `revised_by`, and `dalan decide`/`accept`/`apply` refuse it with `stale_revision`; the report stays readable as evidence, and `dalan decide ID not_useful` still works. A job that finished before the correction arrived is unchanged, and the correction is queued as new work. `--revises` cannot be combined with `--eligible` or `--policy`.
|
|
46
48
|
|
|
49
|
+
## Scoped reviews through the T3 worker provider
|
|
50
|
+
|
|
51
|
+
Start a scoped review with `[dalan-read] OWNER/REPO@FULL_SHA path/to/file another/file` after any decision, priority or requirements lines. Put the review question below it. Dalan reads from the authorized repository revision and reports the accepted paths on admission and recovery. To change the revision or path list, start a new task.
|
|
52
|
+
|
|
47
53
|
## Builds through the T3 worker provider
|
|
48
54
|
|
|
49
55
|
Builds never publish a branch for you. A refusal tells you whether to commit tracked edits or, if you are authorized to publish the revision, gives the exact ref to push before delegating again. The worker cannot open a file just because the brief names a path on your computer; paste only the text you are authorized to share.
|
|
@@ -37,14 +37,32 @@ function stripTrailingT3Blocks(text) {
|
|
|
37
37
|
|
|
38
38
|
// runtimeInstructions.ts supplies this as a separate final text block, not part of the user's text. Check its generated
|
|
39
39
|
// shape and recognizable copy before dropping it; never cut at an embedded tag.
|
|
40
|
+
const RUNTIME_INFO = /^<runtime_info>In case you're asked: you are running in T3 Code through the [^<>\n]+ harness[^<>\n]*\. No need to mention this otherwise\. You can embed (images and videos|images, video, and audio) in your response using Markdown with absolute file paths\.<\/runtime_info>$/;
|
|
41
|
+
const PR_LINKING = /^<pull_request_linking>\nWhen the t3-code MCP server exposes link_pull_request, you must use it to register every pull request [\s\S]+call unwatch_pull_request first so the thread returns to their inbox\.\n<\/pull_request_linking>$/;
|
|
42
|
+
const CURRENT_RUNTIME_INFO = /^<runtime_info>In case you're asked: you are running in T3 Code through the [^<>\r\n]+ harness(?:(?:, as | with )[^<>\r\n]+)?\. No need to mention this otherwise\. You can embed images, video, and audio(?: in your response)? using Markdown image syntax with absolute file paths\. (?:Link any other file you produce using its absolute path|Link every other file you cite or produce by its absolute path, as in \[http\.ts:42\]\(\/abs\/path\/http\.ts:42\),) so the user can open it in T3 Code's files viewer\.<\/runtime_info>$/;
|
|
43
|
+
// The newer footer uses literal placeholders in its example and adds a second line.
|
|
44
|
+
const CURRENT_PR_LINKING = /^<pull_request_linking>\n?Link each PR you create, take over, or push to:(?:[^<>\r\n]|<full URL>|<SHA>|<state>)* Before handback, call unwatch_pull_request on any PR you watch\.(?: When pull_request_\* tools are listed,[^<>\r\n]* pull_request_create links for you\.\nIf available, call link_issue for each issue you take on or file, even via CLI; skip issues you only read\.)?\n?<\/pull_request_linking>$/;
|
|
40
45
|
export function isT3RuntimeBlock(text) {
|
|
41
|
-
|
|
46
|
+
const split = text.indexOf('\n\n');
|
|
47
|
+
const finalInfo = split < 0 ? text : text.slice(0, split);
|
|
48
|
+
const info = RUNTIME_INFO.exec(finalInfo);
|
|
49
|
+
if (CURRENT_RUNTIME_INFO.test(finalInfo)) {
|
|
50
|
+
return split < 0 || CURRENT_PR_LINKING.test(text.slice(split + 2));
|
|
51
|
+
}
|
|
52
|
+
if (!info) return false;
|
|
53
|
+
if (split >= 0) return PR_LINKING.test(text.slice(split + 2));
|
|
54
|
+
// Newer T3 delegation can send runtime_info as its own full final block.
|
|
55
|
+
return info[1] === 'images, video, and audio';
|
|
42
56
|
}
|
|
43
57
|
|
|
44
58
|
// The user's text from a prompt's content blocks. One user block is never discarded, even if it looks like the runtime block.
|
|
45
59
|
export function promptText(blocks) {
|
|
46
60
|
const texts = blocks.filter(b => b.type === 'text').map(b => b.text);
|
|
47
|
-
if (texts.length >
|
|
61
|
+
if (texts.length > 2 && CURRENT_RUNTIME_INFO.test(texts.at(-2)) && CURRENT_PR_LINKING.test(texts.at(-1))) {
|
|
62
|
+
texts.splice(-2);
|
|
63
|
+
} else if (texts.length > 1 && isT3RuntimeBlock(texts.at(-1))) {
|
|
64
|
+
texts.pop();
|
|
65
|
+
}
|
|
48
66
|
return unwrapUserRequest(texts.join('\n'));
|
|
49
67
|
}
|
|
50
68
|
|
package/package.json
CHANGED
package/src/acp-bridge.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { materialize } from './patch-apply.mjs';
|
|
1
|
+
import { materialize, publicationFailureText } from './patch-apply.mjs';
|
|
2
2
|
import { defaultPath } from './paths.mjs';
|
|
3
3
|
// Bridge-facing pieces of the ACP adapter (bin/dot-acp-agent.mjs): the admin-socket client, the owner token, brief and
|
|
4
4
|
// request-id rules, submit eligibility and the payload builder. Nothing here speaks ACP.
|
|
@@ -12,7 +12,8 @@ import { promisify } from 'node:util';
|
|
|
12
12
|
import { packRepoDiff, stripPacked } from './acp-context.mjs';
|
|
13
13
|
import { hostCheckRefusal } from './host-execution-policy.mjs';
|
|
14
14
|
import { redactLogEntry } from './redaction.mjs';
|
|
15
|
-
import { submissionLimits } from './submission-policy.mjs';
|
|
15
|
+
import { isLiteralScopePath, submissionLimits } from './submission-policy.mjs';
|
|
16
|
+
import { readablePath } from './path-syntax.mjs';
|
|
16
17
|
import { readOrCreateSecret, ownerToken } from '../integrations/t3/acp-kit/src/capability.mjs';
|
|
17
18
|
import { CONTINUE_PROMPT, promptText, unwrapUserRequest, isT3RuntimeBlock, parseIdentity } from '../integrations/t3/acp-kit/src/t3-envelope.mjs';
|
|
18
19
|
import { adminSocketPathError, adminSocketPath } from './admin-socket.mjs';
|
|
@@ -338,6 +339,35 @@ export async function prepareAssignmentWithContext(request, options, env = proce
|
|
|
338
339
|
throw error;
|
|
339
340
|
}
|
|
340
341
|
}
|
|
342
|
+
// Older hosts carry explicit repository intent in a marked first line. The
|
|
343
|
+
// existing submission compiler still authorizes the pinned tree and paths.
|
|
344
|
+
export function explicitReadIntent(brief) {
|
|
345
|
+
const lines=brief.split(/\r?\n/);
|
|
346
|
+
const markers=[];
|
|
347
|
+
let fence=null,buildMarker=false;
|
|
348
|
+
for(const [index,line] of lines.entries()) {
|
|
349
|
+
const delimiter=/^[ \t]*(\x60{3,}|~{3,})/.exec(line)?.[1];
|
|
350
|
+
if(delimiter) {
|
|
351
|
+
if(!fence) fence=delimiter;
|
|
352
|
+
else if(delimiter[0]===fence[0]&&delimiter.length>=fence.length) fence=null;
|
|
353
|
+
} else if(!fence) {
|
|
354
|
+
if(/^[ \t]*\[dalan-read\b/i.test(line)) markers.push(index);
|
|
355
|
+
if(/^[ \t]*\[dot-build\b/i.test(line)) buildMarker=true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if(!markers.length) return null;
|
|
359
|
+
const header=/^\[dalan-read\][ \t]+([A-Za-z0-9][\w.-]*\/[A-Za-z0-9][\w.-]*)@([a-f0-9]{40})[ \t]+(\S+(?:[ \t]+\S+)*)[ \t]*$/i.exec(lines[0]);
|
|
360
|
+
if(!header||markers.length!==1||markers[0]!==0||buildMarker) {
|
|
361
|
+
throw new Refusal('Use one first-line [dalan-read] owner/repo@FULL_SHA followed by the allowed paths.');
|
|
362
|
+
}
|
|
363
|
+
const [,repo,sha,list]=header;
|
|
364
|
+
const scope=list.split(/[ \t]+/).map(file=>file.replace(/^\.\//,''));
|
|
365
|
+
if(scope.length>200||new Set(scope).size!==scope.length||!scope.every(file=>readablePath(file)&&isLiteralScopePath(file))) {
|
|
366
|
+
throw new Refusal('The [dalan-read] line must name distinct repository-relative paths.');
|
|
367
|
+
}
|
|
368
|
+
return {repo,sha:sha.toLowerCase(),scope};
|
|
369
|
+
}
|
|
370
|
+
|
|
341
371
|
async function prepareUnexplained({ cwd, ...request }, options, env) {
|
|
342
372
|
// A text-only worker cannot open host files, so a brief that names one would end BLOCKED after a wake-up cycle. Refuse
|
|
343
373
|
// at submit, while the sender can still paste the content. URLs and repository-relative names are allowed.
|
|
@@ -347,9 +377,10 @@ async function prepareUnexplained({ cwd, ...request }, options, env) {
|
|
|
347
377
|
}
|
|
348
378
|
const textOnly = env.DOT_ACP_TEXT_ONLY === '1';
|
|
349
379
|
const build = isBuild(request.brief);
|
|
380
|
+
const explicitRead = explicitReadIntent(request.brief);
|
|
350
381
|
// Without an explicit list, a named repository is allowed when a build of it would be: its owner is in the configured owner
|
|
351
382
|
// list and no exclusion rule covers it (the same rules as buildIneligible, so a review reads what a build may read).
|
|
352
|
-
const named = namedRepoInputs(request.brief, options?.allowedRepos ?? (repo => buildIneligible(repo, [], env) === null ? repo : null));
|
|
383
|
+
const named = namedRepoInputs(explicitRead ? `${explicitRead.repo}@${explicitRead.sha}` : request.brief, options?.allowedRepos ?? (repo => buildIneligible(repo, [], env) === null ? repo : null));
|
|
353
384
|
const hint = 'File it as a backlog row instead, or name owner/repo@FULL_SHA';
|
|
354
385
|
const refuseNamed = (code, reason) => new Refusal(`${reason}. ${hint}`, 'admission_refused', {code, refused: code});
|
|
355
386
|
if (named?.refused) {
|
|
@@ -392,7 +423,7 @@ async function prepareUnexplained({ cwd, ...request }, options, env) {
|
|
|
392
423
|
}
|
|
393
424
|
}
|
|
394
425
|
// Identity is the requester's brief only; packed context and notes are presentation and never enter this hash.
|
|
395
|
-
let assignment = { ...buildAssignment({ ...request, inputs: context.inputs, build, newFiles, repoScope: build && buildExecution(env) === 'host' }), acp_brief_hash: sha256(request.brief) };
|
|
426
|
+
let assignment = { ...buildAssignment({ ...request, inputs: context.inputs, build, newFiles, repoScope: build && buildExecution(env) === 'host' }), acp_brief_hash: sha256(request.brief), ...(explicitRead ? { scope_paths: explicitRead.scope, read_paths: explicitRead.scope } : {}) };
|
|
396
427
|
if (context.packBase) assignment = await packRepoDiff(cwd, assignment, context.packBase, NO_REPO_NOTE);
|
|
397
428
|
else if (context.untracked && !build) assignment.brief = `${UNTRACKED_NOTE}\n\n${assignment.brief}`;
|
|
398
429
|
else if (context.note) assignment.brief = `${context.note}\n\n${assignment.brief}`;
|
|
@@ -487,7 +518,11 @@ export function buildAssignment({ requestId, brief, inputs, validUntil, build =
|
|
|
487
518
|
schema_version: 1, request_id: requestId, brief, inputs,
|
|
488
519
|
...(inputs.length ? { scope_paths: build && !repoScope ? buildScope(brief).filter(p => !created.includes(p)) : ['.'] } : {}),
|
|
489
520
|
...(inputs.length && created.length ? { output_paths: created } : {}),
|
|
490
|
-
expected_output: build ? BUILD_OUTPUT : 'A complete answer as plain text. Put the result in the finish call.'
|
|
521
|
+
expected_output: build ? BUILD_OUTPUT : 'A complete answer as plain text. Put the result in the finish call.' +
|
|
522
|
+
(inputs.length ? ' When asked to run checks, use your own permitted tools on the authorized files at the pinned commit. '+
|
|
523
|
+
'Use a disposable checkout only if your repository grant permits it, or use the granted scoped file set. '+
|
|
524
|
+
'Leave the source unchanged and do not push. Record each command and exit code in finish.runs. '+
|
|
525
|
+
'If the workspace, shell, or other required access is unavailable, report that limit and which checks did not run.' : ''),
|
|
491
526
|
execution_scope: build ? 'implementation' : 'read-only', valid_until: validUntil,
|
|
492
527
|
};
|
|
493
528
|
}
|
|
@@ -611,32 +646,58 @@ export const decideHint = rid => `decide: dalan decide ${rid} accepted|applied|u
|
|
|
611
646
|
// A build answer includes the worker's result, patch evidence and owner-decision instructions.
|
|
612
647
|
// patch is the artifact's bytes (Buffer or string) or null when it could not be read.
|
|
613
648
|
// Publication is best effort: keep all build evidence and the patch on every failure.
|
|
614
|
-
export async function materializeBuildResult(row, text, patch, proseCheck, {cwd, getCurrent}) {
|
|
649
|
+
export async function materializeBuildResult(row, text, patch, proseCheck, {cwd, getCurrent, timeoutMs}) {
|
|
615
650
|
let publication;
|
|
616
651
|
try {
|
|
617
652
|
const result=await materialize({id:row.request_id, got:row, dir:cwd, recheck:getCurrent,
|
|
618
653
|
grantFile:path.join(os.homedir(),'.config/dot-bridge/materialize.json'),
|
|
619
|
-
download:async()=>patch, standingOnly:true, fetchBase:true});
|
|
654
|
+
download:async()=>patch, standingOnly:true, fetchBase:true, timeoutMs});
|
|
620
655
|
publication=result;
|
|
621
|
-
} catch(error) {
|
|
656
|
+
} catch(error) {
|
|
657
|
+
publication={published:false,reason:publicationFailureText(error),
|
|
658
|
+
remote_effect:error?.remote_effect,cleanup_pending:error?.cleanup_pending===true};
|
|
659
|
+
}
|
|
622
660
|
return buildResultText(row,text,patch,proseCheck,publication);
|
|
623
661
|
}
|
|
624
662
|
|
|
663
|
+
export function workerRunEvidenceLines(row) {
|
|
664
|
+
const lines = [];
|
|
665
|
+
const runs = (row.worker_runs ?? []).map(run => `${run.command} exit ${run.exit_code}`);
|
|
666
|
+
if (runs.length) lines.push(`worker runs (worker_reported, not checked by the bridge): ${runs.join('; ')}`);
|
|
667
|
+
if (row.worker_run_limit) lines.push(`worker run limit (worker_reported): ${row.worker_run_limit}`);
|
|
668
|
+
return lines;
|
|
669
|
+
}
|
|
670
|
+
|
|
625
671
|
export function buildResultText(row, text, patch, proseCheck = null, publication = null) {
|
|
626
672
|
const rid = row.request_id, ev = row.report?.workspace_evidence ?? {}, input = row.assignment?.inputs?.[0] ?? {};
|
|
627
|
-
const art = ev.patch_artifact
|
|
673
|
+
const art = ev.patch_artifact;
|
|
674
|
+
const published=publication?.published === true && /^[a-f0-9]{40}$/.test(publication.verified_head_sha ?? '');
|
|
675
|
+
const lines = [];
|
|
676
|
+
if (published) {
|
|
677
|
+
lines.push('Published and verified by Dalan.',
|
|
678
|
+
`Branch: ${publication.branch}`, `Draft PR: ${publication.pr_url}`,
|
|
679
|
+
`Verified head SHA: ${publication.verified_head_sha} (remote head matches the sealed patch and pinned base)`,
|
|
680
|
+
'', 'Worker report (before publication verification):');
|
|
681
|
+
}
|
|
682
|
+
lines.push(text, '', `--- worker build evidence (request ${rid}) ---`, `base: ${input.github_repo ?? '?'}@${ev.base_sha ?? input.base_sha ?? '?'}`);
|
|
628
683
|
const checks = (ev.checks ?? []).map(c => `${c.check_id} ${c.status}${c.exit_code === null || c.exit_code === undefined ? '' : ` exit ${c.exit_code}`} on diff ${String(c.diff_sha256 ?? '').slice(0, 12)}${c.check_summary?`; ${c.check_summary}`:''}`);
|
|
629
684
|
const skippedReason=ev.checks_skipped?.at(-1)?.reason;
|
|
630
685
|
// A check from an older diff does not cover this one: then the skip reason still explains the current diff.
|
|
631
686
|
const currentChecked = (ev.checks ?? []).some(c => c.applies_to_current_diff === true);
|
|
632
687
|
lines.push(`worker checks: ${checks.length ? checks.join('; ') : 'none run'}${skippedReason && !currentChecked ? ` (check not run${checks.length ? ' on the current diff' : ''}: ${skippedReason})` : ''}`);
|
|
633
|
-
|
|
634
|
-
if (runs.length) lines.push(`worker runs (worker_reported, not checked by the bridge): ${runs.join('; ')}`);
|
|
635
|
-
if (row.worker_run_limit) lines.push(`worker run limit (worker_reported): ${row.worker_run_limit}`);
|
|
688
|
+
lines.push(...workerRunEvidenceLines(row));
|
|
636
689
|
if (proseCheck) lines.push(proseCheckText(proseCheck));
|
|
637
|
-
const
|
|
638
|
-
if (
|
|
639
|
-
|
|
690
|
+
const remote = published ? null : publication?.remote_effect;
|
|
691
|
+
if (remote) {
|
|
692
|
+
lines.push(`Publication unverified: ${publication.reason}`);
|
|
693
|
+
const branchStatus = remote.branch_state === 'push_succeeded' ? 'Branch push succeeded'
|
|
694
|
+
: remote.branch_state === 'observed' ? 'Observed remote branch' : 'Branch push unconfirmed';
|
|
695
|
+
lines.push(`${branchStatus}: ${remote.branch}.`);
|
|
696
|
+
if (remote.draft_attempted) lines.push('A draft pull request may already exist.');
|
|
697
|
+
} else if (!published && publication) {
|
|
698
|
+
lines.push(typeof publication === 'string' ? publication : `Not published: ${publication.reason ?? 'head not verified'}`);
|
|
699
|
+
}
|
|
700
|
+
if (publication?.cleanup_pending) lines.push('Temporary checkout cleanup is pending on the publication host.');
|
|
640
701
|
if (!art?.artifact_id || !art.size) lines.push('patch: none (empty diff). Nothing to apply.');
|
|
641
702
|
else {
|
|
642
703
|
const body = patch === null || patch === undefined ? null : Buffer.from(patch).toString('utf8');
|
|
@@ -648,6 +709,10 @@ export function buildResultText(row, text, patch, proseCheck = null, publication
|
|
|
648
709
|
lines.push(`Next: review the published draft and its checks. ${decideHint(rid)}`);
|
|
649
710
|
return lines.join('\n');
|
|
650
711
|
}
|
|
712
|
+
if (remote) {
|
|
713
|
+
lines.push(`Next: Check the existing branch and any draft before retrying. ${decideHint(rid)}`);
|
|
714
|
+
return lines.join('\n');
|
|
715
|
+
}
|
|
651
716
|
lines.push(`Next: on a clean checkout of that base, git apply the patch, re-run the tests yourself, push only if they pass. Then record the verdict: dalan accept ${rid}, or dalan reject ${rid} --note '<why>'. The delegation gate offers the worker builds only while these verdicts stay good.`);
|
|
652
717
|
lines.push(`Or apply it for you: dalan apply ${rid} [--dir <checkout>] (checks the digest and base, then records applied). ${decideHint(rid)}`);
|
|
653
718
|
return lines.join('\n');
|
|
@@ -34,7 +34,7 @@ export function hostCheckAuthorization(repo, checkId, expectedSpec = null, assig
|
|
|
34
34
|
export function hostCheckRefusal(assignment={}, repo=null, checkId=null, expectedSpec=null,excludedPathsAbsent=false) {
|
|
35
35
|
const scope=assignment.scope_paths;
|
|
36
36
|
const narrow=Array.isArray(scope)&&scope.length&&!scope.some(p=>p.replace(/^\.\//,'').replace(/\/$/,'')==='.');
|
|
37
|
-
if(narrow||(assignment.scope_excluded?.length&&!excludedPathsAbsent)) {
|
|
37
|
+
if(assignment.paged_read_scope===true||narrow||(assignment.scope_excluded?.length&&!excludedPathsAbsent)) {
|
|
38
38
|
return 'scope_paths_read_isolation_unavailable: this executor exposes the whole checkout; a check needs an owner-approved repository-wide read grant';
|
|
39
39
|
}
|
|
40
40
|
if(sensitivePolicyPaths().error) return 'sensitive_policy_unavailable: restore a valid mode-0600 submission policy before running host checks';
|
package/src/inbox.mjs
CHANGED
|
@@ -51,10 +51,52 @@ export function buildInbox(states,scope,{cutoff=null}={}) {
|
|
|
51
51
|
return {scope,total:items.length,counts,hidden_older,delivered_t3,items,...(unknown.length?{unknown}:{})};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
|
|
55
|
+
// Keep passive reads bounded without changing wait/mark-read behavior. The
|
|
56
|
+
// caller supplies the non-consuming route, not a fallback to a result fetch.
|
|
57
|
+
export async function readInboxPages(receipts,readPage,{budgetMs=3000,concurrency=3}={}) {
|
|
58
|
+
const pages=[];
|
|
59
|
+
for(let i=0;i===0||i<receipts.length;i+=500) pages.push(receipts.slice(i,i+500));
|
|
60
|
+
const deadline=performance.now()+budgetMs, results=new Array(pages.length);
|
|
61
|
+
let cursor=0;
|
|
62
|
+
await Promise.all(Array.from({length:Math.min(concurrency,pages.length)},async()=>{
|
|
63
|
+
while(cursor<pages.length) {
|
|
64
|
+
const time=Math.floor(deadline-performance.now());
|
|
65
|
+
if(time<=0) return;
|
|
66
|
+
const index=cursor++, page=pages[index];
|
|
67
|
+
try {
|
|
68
|
+
const result=await readPage(page.map(x=>({id:x.id,capability:x.token})),time);
|
|
69
|
+
if(!Array.isArray(result?.states)) throw new Error('invalid inbox page');
|
|
70
|
+
const owned=new Set(page.map(x=>x.id)), states=[];
|
|
71
|
+
for(const state of result.states) if(owned.delete(state?.request_id)) states.push(state);
|
|
72
|
+
results[index]={states,missing:owned.size};
|
|
73
|
+
} catch(error) { results[index]={error}; }
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
const states=[], failed=[];
|
|
77
|
+
let unresolved=0, resolvedPages=0;
|
|
78
|
+
for(const [index,page] of pages.entries()) {
|
|
79
|
+
const part=results[index];
|
|
80
|
+
if(part?.states) {
|
|
81
|
+
resolvedPages++;
|
|
82
|
+
for(const state of part.states) states.push(state);
|
|
83
|
+
if(!part.missing) continue;
|
|
84
|
+
}
|
|
85
|
+
failed.push(index+1);
|
|
86
|
+
unresolved+=part?.missing??page.length;
|
|
87
|
+
}
|
|
88
|
+
const partial = failed.length ? {partial_read:{failed_pages:failed,unresolved_receipts:unresolved}} : {};
|
|
89
|
+
if (resolvedPages > 0) return {states,...partial};
|
|
90
|
+
if (pages.every((_, index) => results[index]?.error?.http_status === 404)) return {legacy:true,states:[]};
|
|
91
|
+
const error = results.find(part => part?.error && part.error.http_status !== 404)?.error;
|
|
92
|
+
return {states,...partial,...(error ? {error} : {})};
|
|
93
|
+
}
|
|
94
|
+
|
|
54
95
|
export function formatInbox(inbox) {
|
|
55
96
|
const hidden=inbox.hidden_older?`${inbox.hidden_older} older item${inbox.hidden_older===1?'':'s'} hidden (--since all to show)`:'';
|
|
56
|
-
|
|
57
|
-
|
|
97
|
+
const partial=inbox.partial_read?`Inbox partially read: could not check ${inbox.partial_read.unresolved_receipts} receipt(s) on ${inbox.partial_read.failed_pages.length} page(s). Try again for the full inbox.`:'';
|
|
98
|
+
if(!inbox.total) return [partial||'inbox empty',hidden].filter(Boolean).join('\n');
|
|
99
|
+
const lines=partial?[partial]:[];
|
|
58
100
|
for(const g of inboxGroups) for(const i of inbox.items.filter(x=>x.group===g)) {
|
|
59
101
|
const held=i.wake_held?` [wake held: ${i.wake_held.reason}${i.wake_held.detail?`, ${i.wake_held.detail}`:''}; it sends when the parent runs again]`:'';
|
|
60
102
|
const why=(i.group==='cancelled_unread'?` (${i.reason??'cancelled'})`:i.group==='question'?` ${i.text}`:'')+held;
|