@oyasmi/pipiclaw 0.9.0-beta.1 → 0.9.0-beta.3
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/dist/agent/channel-runner.d.ts +9 -0
- package/dist/agent/channel-runner.js +58 -4
- package/dist/agent/commands.js +11 -3
- package/dist/agent/job-manager.d.ts +6 -0
- package/dist/agent/job-manager.js +55 -1
- package/dist/agent/progress-formatter.js +3 -3
- package/dist/agent/run-queue.d.ts +10 -1
- package/dist/agent/run-queue.js +19 -2
- package/dist/agent/session-resource-gate.d.ts +17 -0
- package/dist/agent/session-resource-gate.js +33 -2
- package/dist/agent/status-render.js +1 -3
- package/dist/agent/types.d.ts +8 -0
- package/dist/runtime/bootstrap.d.ts +52 -0
- package/dist/runtime/bootstrap.js +192 -25
- package/dist/runtime/delivery.js +5 -5
- package/dist/runtime/dingtalk.d.ts +8 -0
- package/dist/runtime/durable-dispatch.d.ts +4 -0
- package/dist/runtime/durable-dispatch.js +16 -0
- package/dist/runtime/subagent-commands.d.ts +8 -6
- package/dist/runtime/subagent-commands.js +264 -64
- package/dist/security/logger.js +7 -0
- package/dist/shared/host-process.d.ts +7 -1
- package/dist/shared/host-process.js +7 -3
- package/dist/shared/jsonl-appender.d.ts +2 -0
- package/dist/shared/jsonl-appender.js +25 -13
- package/dist/shared/with-timeout.d.ts +14 -0
- package/dist/shared/with-timeout.js +38 -0
- package/dist/subagents/detached-discovery.d.ts +13 -0
- package/dist/subagents/detached-discovery.js +17 -0
- package/dist/subagents/external/run.d.ts +10 -0
- package/dist/subagents/external/run.js +47 -1
- package/dist/subagents/format.d.ts +12 -0
- package/dist/subagents/format.js +24 -0
- package/dist/subagents/runs.d.ts +38 -0
- package/dist/subagents/runs.js +171 -24
- package/dist/subagents/tool.d.ts +18 -0
- package/dist/subagents/tool.js +147 -89
- package/dist/tasks/control.d.ts +12 -0
- package/dist/tasks/control.js +20 -0
- package/dist/tasks/store.d.ts +21 -0
- package/dist/tasks/store.js +80 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/subagent-manage.d.ts +5 -0
- package/dist/tools/subagent-manage.js +68 -51
- package/dist/usage/ledger.d.ts +7 -0
- package/dist/usage/ledger.js +15 -2
- package/dist/usage/render.js +22 -0
- package/examples/sub-agents/README.md +12 -7
- package/examples/sub-agents/documenter.md +3 -3
- package/examples/sub-agents/git-committer.md +1 -1
- package/examples/sub-agents/reviewer.md +12 -6
- package/examples/sub-agents/verifier.md +5 -2
- package/examples/sub-agents/worker.md +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { join } from "path";
|
|
|
3
3
|
import { formatUnknownCommandMessage, isRunnerBuiltInCommand, parseBuiltInCommand, slashCommandName, } from "../agent/commands.js";
|
|
4
4
|
import { channelEffectCount, noteTaskEffects, taskEffectCount } from "../agent/effect-ledger.js";
|
|
5
5
|
import { getOrCreateRunner } from "../agent/index.js";
|
|
6
|
-
import { configureJobRuntime, restoreChannelJobs } from "../agent/job-manager.js";
|
|
6
|
+
import { configureJobRuntime, getChannelJobManager, restoreChannelJobs, } from "../agent/job-manager.js";
|
|
7
7
|
import { loadDetachedMaintenanceContext } from "../agent/maintenance-context.js";
|
|
8
8
|
import { resetRunner } from "../agent/runner-factory.js";
|
|
9
9
|
import { renderStatus } from "../agent/status-render.js";
|
|
@@ -18,9 +18,10 @@ import { PipiclawSettingsManager } from "../settings.js";
|
|
|
18
18
|
import { formatConfigDiagnostic } from "../shared/config-diagnostic.js";
|
|
19
19
|
import { fileStamp } from "../shared/file-stamp.js";
|
|
20
20
|
import { errorMessage } from "../shared/text-utils.js";
|
|
21
|
-
import {
|
|
21
|
+
import { loadDetachedSubAgentDiscovery } from "../subagents/detached-discovery.js";
|
|
22
|
+
import { configureSubAgentRuntime, getSubAgentRunManager, restoreAllSubAgentRuns, } from "../subagents/runs.js";
|
|
22
23
|
import { readActiveTasks } from "../tasks/ledger.js";
|
|
23
|
-
import {
|
|
24
|
+
import { activateWaitingTaskAndClaimAttempt, finishTaskAttempt, finishWakeTaskActivation, rollbackWakeTaskActivation, } from "../tasks/store.js";
|
|
24
25
|
import { getToolsConfigPath, loadToolsConfig, loadToolsConfigWithDiagnostics } from "../tools/config.js";
|
|
25
26
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
26
27
|
import { parseUsageMode, renderUsageReport } from "../usage/render.js";
|
|
@@ -401,6 +402,103 @@ function flushInactiveChannelMemory(channelRunners) {
|
|
|
401
402
|
function isNoRunningTaskQueueError(err) {
|
|
402
403
|
return err instanceof Error && err.message === "No task is currently running.";
|
|
403
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
|
|
407
|
+
* on this channel, has actually finished (a still-`running` job cannot have produced this wake —
|
|
408
|
+
* accepting it anyway would let a message merely mentioning a live job's id activate a task
|
|
409
|
+
* early), and really is the one whose own contract names `taskId` (spec 040, T9). The text itself
|
|
410
|
+
* is never sufficient — it can be typed by any user, or echoed back by an external agent's own
|
|
411
|
+
* untrusted stdout.
|
|
412
|
+
*/
|
|
413
|
+
export function isVerifiedJobWake(jobs, jobId, taskId) {
|
|
414
|
+
const job = jobs.find((candidate) => candidate.id === jobId);
|
|
415
|
+
return job !== undefined && job.status !== "running" && job.taskId === taskId;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Same check as `isVerifiedJobWake`, for a `[SUBAGENT:<runId>] ... belongs to task <taskId>.`
|
|
419
|
+
* delegation wake. `settledAt` (rather than `status !== "running"`) is the terminal marker here
|
|
420
|
+
* because it is the one field `SubAgentRunManager.settle()` sets unconditionally and first, before
|
|
421
|
+
* usage/archive/wake side effects — the same idempotency guard the manager itself relies on.
|
|
422
|
+
*/
|
|
423
|
+
export function isVerifiedDelegationWake(record, taskId) {
|
|
424
|
+
return record !== undefined && record.settledAt !== undefined && record.taskId === taskId;
|
|
425
|
+
}
|
|
426
|
+
/** Plain wake text is untrusted. Only an event carrying the producer-created structured envelope
|
|
427
|
+
* and its exact durable dispatch id may enter task activation; normal DingTalk inbound events do
|
|
428
|
+
* not populate `internalWake`, so copying a real wake's text is insufficient. */
|
|
429
|
+
export function isTrustedInternalWake(event, kind, resourceId, taskId) {
|
|
430
|
+
const wake = event.internalWake;
|
|
431
|
+
return (wake?.kind === kind &&
|
|
432
|
+
wake.resourceId === resourceId &&
|
|
433
|
+
wake.taskId === taskId &&
|
|
434
|
+
typeof event.dispatchId === "string" &&
|
|
435
|
+
wake.dispatchId === event.dispatchId);
|
|
436
|
+
}
|
|
437
|
+
/** Claim and activate a producer-created delegation wake without consuming it yet. Keeping the
|
|
438
|
+
* final marker separate lets transports such as TUI mark it consumed only after they have accepted
|
|
439
|
+
* the corresponding turn; a rejected submit remains replayable in the same or next process. */
|
|
440
|
+
export async function claimVerifiedDelegationWake(event, workspaceDir, hooks) {
|
|
441
|
+
const wake = event.internalWake;
|
|
442
|
+
if (wake?.kind !== "subagent")
|
|
443
|
+
return undefined;
|
|
444
|
+
const runManager = getSubAgentRunManager(event.channelId);
|
|
445
|
+
const record = runManager.get(wake.resourceId);
|
|
446
|
+
if (!isTrustedInternalWake(event, "subagent", wake.resourceId, wake.taskId) ||
|
|
447
|
+
!isVerifiedDelegationWake(record, wake.taskId) ||
|
|
448
|
+
!(await runManager.beginWakeConsumption(wake.resourceId, wake.taskId, event.dispatchId))) {
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
451
|
+
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
452
|
+
const handoff = {
|
|
453
|
+
kind: "subagent",
|
|
454
|
+
resourceId: wake.resourceId,
|
|
455
|
+
dispatchId: event.dispatchId,
|
|
456
|
+
};
|
|
457
|
+
const activated = await activateWaitingTaskAndClaimAttempt(channelDir, wake.taskId, "external-signal", new Date(), hooks, handoff);
|
|
458
|
+
return {
|
|
459
|
+
taskId: wake.taskId,
|
|
460
|
+
generation: activated?.generation,
|
|
461
|
+
activated: activated !== undefined,
|
|
462
|
+
finish: async () => {
|
|
463
|
+
await runManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
464
|
+
await finishWakeTaskActivation(channelDir, wake.taskId, handoff);
|
|
465
|
+
},
|
|
466
|
+
rollback: () => rollbackWakeTaskActivation(channelDir, wake.taskId, handoff),
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* How long `/stop` waits for the turn to actually end before force-releasing it.
|
|
471
|
+
* `requestStop` + `abort` only reach the agent loop; a turn wedged in its
|
|
472
|
+
* epilogue (delivery drain, session-resource reload, memory flush) ignores both
|
|
473
|
+
* and would otherwise keep the channel reporting "已有回合在运行" indefinitely.
|
|
474
|
+
*/
|
|
475
|
+
const STOP_FORCE_END_GRACE_MS = 15_000;
|
|
476
|
+
const STOP_FORCE_END_POLL_MS = 250;
|
|
477
|
+
function sleepUnref(ms) {
|
|
478
|
+
return new Promise((resolve) => {
|
|
479
|
+
const timer = setTimeout(resolve, ms);
|
|
480
|
+
timer.unref?.();
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Watchdog for `/stop`: release the channel if the stopped turn has not ended
|
|
485
|
+
* once the grace window elapses. Returns true when it had to force the release.
|
|
486
|
+
*/
|
|
487
|
+
export async function forceEndStuckTurnAfterStop(input) {
|
|
488
|
+
const graceMs = input.graceMs ?? STOP_FORCE_END_GRACE_MS;
|
|
489
|
+
const pollMs = input.pollMs ?? STOP_FORCE_END_POLL_MS;
|
|
490
|
+
const deadline = Date.now() + graceMs;
|
|
491
|
+
while (input.runner.isBusy() && Date.now() < deadline) {
|
|
492
|
+
await sleepUnref(Math.min(pollMs, Math.max(1, deadline - Date.now())));
|
|
493
|
+
}
|
|
494
|
+
if (!input.runner.forceEndTurn(`/stop did not take effect within ${graceMs}ms`)) {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
await input
|
|
498
|
+
.notify?.(`⚠️ 上一个回合的收尾卡住了,已强制结束以释放会话(后台清理仍在继续)。现在可以正常发消息或使用 \`/new\`、\`/model\`。`)
|
|
499
|
+
.catch(() => undefined);
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
404
502
|
export function createRuntimeContext(options) {
|
|
405
503
|
const startServices = options.startServices ?? true;
|
|
406
504
|
const registerSignalHandlers = options.registerSignalHandlers ?? true;
|
|
@@ -411,6 +509,8 @@ export function createRuntimeContext(options) {
|
|
|
411
509
|
const cliVersion = readCliVersion();
|
|
412
510
|
const channelRunners = new Map();
|
|
413
511
|
const activeTasks = new Set();
|
|
512
|
+
/** Channels with a `/stop` watchdog in flight, so a burst of `/stop` starts only one. */
|
|
513
|
+
const stopWatchdogs = new Set();
|
|
414
514
|
// `workspace/CHANNELS.md`: names every channel id so the workspace, the logs and the agent
|
|
415
515
|
// stop dealing in `group_cid...`. Writes are debounced internally (see channel-index.ts).
|
|
416
516
|
const channelIndex = createChannelIndex({ workspaceDir: options.paths.workspaceDir });
|
|
@@ -495,6 +595,21 @@ export function createRuntimeContext(options) {
|
|
|
495
595
|
log.logWarning(`[${channelId}] Failed to reset durable-dispatch leases on stop`, errorMessage(err));
|
|
496
596
|
});
|
|
497
597
|
log.logInfo(`[${channelId}] Stop requested`);
|
|
598
|
+
if (!stopWatchdogs.has(channelId)) {
|
|
599
|
+
stopWatchdogs.add(channelId);
|
|
600
|
+
void forceEndStuckTurnAfterStop({
|
|
601
|
+
channelId,
|
|
602
|
+
runner,
|
|
603
|
+
graceMs: options.stopForceEndGraceMs,
|
|
604
|
+
notify: (text) => _bot.sendPlain(channelId, text),
|
|
605
|
+
})
|
|
606
|
+
.catch((err) => {
|
|
607
|
+
log.logWarning(`[${channelId}] Stop watchdog failed`, errorMessage(err));
|
|
608
|
+
})
|
|
609
|
+
.finally(() => {
|
|
610
|
+
stopWatchdogs.delete(channelId);
|
|
611
|
+
});
|
|
612
|
+
}
|
|
498
613
|
}
|
|
499
614
|
return { pausedTaskId };
|
|
500
615
|
},
|
|
@@ -553,6 +668,13 @@ export function createRuntimeContext(options) {
|
|
|
553
668
|
args,
|
|
554
669
|
channelId: event.channelId,
|
|
555
670
|
discovery: channelRunners.get(event.channelId)?.getSubAgentDiscoverySnapshot(),
|
|
671
|
+
// `roles` needs a role directory even for a channel that has never spoken this boot —
|
|
672
|
+
// resolved from disk, without spinning up a full ChannelRunner (spec 041).
|
|
673
|
+
getDetachedDiscovery: () => loadDetachedSubAgentDiscovery({
|
|
674
|
+
workspaceDir: options.paths.workspaceDir,
|
|
675
|
+
authConfigPath: options.paths.authConfigPath,
|
|
676
|
+
modelsConfigPath: options.paths.modelsConfigPath,
|
|
677
|
+
}),
|
|
556
678
|
});
|
|
557
679
|
await bot.sendPlain(event.channelId, response);
|
|
558
680
|
},
|
|
@@ -619,6 +741,7 @@ export function createRuntimeContext(options) {
|
|
|
619
741
|
}
|
|
620
742
|
const runner = getRunner(event.channelId);
|
|
621
743
|
await durableDispatch?.markStarted(event.dispatchId);
|
|
744
|
+
let structuredWakeFinalized = event.internalWake === undefined;
|
|
622
745
|
const task = (async () => {
|
|
623
746
|
try {
|
|
624
747
|
await archiveIncomingMessage(event.channelId, {
|
|
@@ -682,33 +805,74 @@ export function createRuntimeContext(options) {
|
|
|
682
805
|
// task-driver turn is measured as a delta (turns on a channel are serialized)
|
|
683
806
|
// and credited to the task it was dispatched for.
|
|
684
807
|
const effectsBefore = channelEffectCount(event.channelId);
|
|
685
|
-
|
|
808
|
+
// Both wake formats below carry an unauthenticated claim in plain text: anything
|
|
809
|
+
// that can put a message on this channel can *write* "[JOB:x] ... belongs to task
|
|
810
|
+
// y." or "[SUBAGENT:x] ... belongs to task y." — including another user, or an
|
|
811
|
+
// external agent's own untrusted stdout (spec 040, D8's threat model explicitly
|
|
812
|
+
// treats external output as untrusted). Activating a waiting task on text pattern
|
|
813
|
+
// alone lets that forged claim advance an unrelated task's attempt generation. The
|
|
814
|
+
// pattern match only extracts a *candidate* id pair now; both paths verify the
|
|
815
|
+
// named run/job actually exists, is done, and really is the one that names this
|
|
816
|
+
// taskId before ever calling `activateWaitingTask` (T9).
|
|
817
|
+
const jobTextMatch = /^\[JOB:([^\]]+)\][\s\S]*?belongs to task ([A-Za-z0-9._-]+)\./.exec(event.text);
|
|
818
|
+
const jobMatch = event.internalWake?.kind === "job"
|
|
819
|
+
? [event.text, event.internalWake.resourceId, event.internalWake.taskId]
|
|
820
|
+
: jobTextMatch;
|
|
686
821
|
let recoveredJobTaskId;
|
|
687
|
-
if (
|
|
688
|
-
const
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
822
|
+
if (jobMatch) {
|
|
823
|
+
const [, jobId, jobTaskId] = jobMatch;
|
|
824
|
+
const jobManager = getChannelJobManager(event.channelId, executor);
|
|
825
|
+
const jobs = await jobManager.list();
|
|
826
|
+
const verified = isTrustedInternalWake(event, "job", jobId, jobTaskId) &&
|
|
827
|
+
isVerifiedJobWake(jobs, jobId, jobTaskId) &&
|
|
828
|
+
(await jobManager.beginWakeConsumption(jobId, jobTaskId, event.dispatchId));
|
|
829
|
+
if (verified) {
|
|
830
|
+
const channelDir = getChannelDir(options.paths.workspaceDir, event.channelId);
|
|
831
|
+
const activated = await activateWaitingTaskAndClaimAttempt(channelDir, jobTaskId, "job", new Date(), options.wakeTransitionHooks?.job);
|
|
832
|
+
if (activated) {
|
|
833
|
+
recoveredJobTaskId = jobTaskId;
|
|
834
|
+
event.taskAttemptGeneration = activated.generation;
|
|
835
|
+
}
|
|
836
|
+
await jobManager.finishWakeConsumption(jobId, event.dispatchId);
|
|
837
|
+
structuredWakeFinalized = true;
|
|
838
|
+
if (event.internalWake?.kind === "job" && !activated)
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
log.logWarning(`[${event.channelId}] Ignored an unverifiable [JOB:${jobId}] wake claiming task ${jobTaskId}`);
|
|
843
|
+
if (event.internalWake?.kind === "job") {
|
|
844
|
+
structuredWakeFinalized = true;
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
696
847
|
}
|
|
697
848
|
}
|
|
698
849
|
// Spec 040, D7: a delegation run's completion wake carries the same "belongs to
|
|
699
850
|
// task" contract as a background job's, and reactivates a task parked with
|
|
700
|
-
// waitingFor="external-signal" the same way.
|
|
701
|
-
const
|
|
851
|
+
// waitingFor="external-signal" the same way — verified the same way (T9).
|
|
852
|
+
const delegationTextMatch = /^\[SUBAGENT:([^\]]+)\][\s\S]*?belongs to task ([A-Za-z0-9._-]+)\./.exec(event.text);
|
|
853
|
+
const delegationMatch = event.internalWake?.kind === "subagent"
|
|
854
|
+
? [event.text, event.internalWake.resourceId, event.internalWake.taskId]
|
|
855
|
+
: delegationTextMatch;
|
|
702
856
|
let recoveredDelegationTaskId;
|
|
703
|
-
if (
|
|
704
|
-
const
|
|
705
|
-
const
|
|
706
|
-
if (
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
857
|
+
if (delegationMatch) {
|
|
858
|
+
const [, runId, delegationTaskId] = delegationMatch;
|
|
859
|
+
const claimed = await claimVerifiedDelegationWake(event, options.paths.workspaceDir, options.wakeTransitionHooks?.subagent);
|
|
860
|
+
if (claimed) {
|
|
861
|
+
if (claimed.activated)
|
|
862
|
+
recoveredDelegationTaskId = claimed.taskId;
|
|
863
|
+
if (claimed.generation !== undefined)
|
|
864
|
+
event.taskAttemptGeneration = claimed.generation;
|
|
865
|
+
await claimed.finish();
|
|
866
|
+
structuredWakeFinalized = true;
|
|
867
|
+
if (event.internalWake?.kind === "subagent" && !claimed.activated)
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
log.logWarning(`[${event.channelId}] Ignored an unverifiable [SUBAGENT:${runId}] wake claiming task ${delegationTaskId}`);
|
|
872
|
+
if (event.internalWake?.kind === "subagent") {
|
|
873
|
+
structuredWakeFinalized = true;
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
712
876
|
}
|
|
713
877
|
}
|
|
714
878
|
const result = await runner.run(ctx, store);
|
|
@@ -746,7 +910,10 @@ export function createRuntimeContext(options) {
|
|
|
746
910
|
});
|
|
747
911
|
}
|
|
748
912
|
finally {
|
|
749
|
-
|
|
913
|
+
if (structuredWakeFinalized)
|
|
914
|
+
await durableDispatch?.markCompleted(event.dispatchId);
|
|
915
|
+
else
|
|
916
|
+
await durableDispatch?.markRetryable(event.dispatchId);
|
|
750
917
|
runner.endTurn();
|
|
751
918
|
// A finished turn may have written task files (progress/complete/set); rescan
|
|
752
919
|
// now so a continuing task chain advances immediately instead of after a full sleep.
|
package/dist/runtime/delivery.js
CHANGED
|
@@ -123,11 +123,11 @@ class ChannelDeliveryController {
|
|
|
123
123
|
if (this.progressStartedAt === 0) {
|
|
124
124
|
this.progressStartedAt = Date.now();
|
|
125
125
|
}
|
|
126
|
-
if (text.startsWith("
|
|
126
|
+
if (text.startsWith("▶ ")) {
|
|
127
127
|
this.toolCallCount++;
|
|
128
128
|
}
|
|
129
129
|
if (this.progressSegments.length > 0) {
|
|
130
|
-
this.progressSegments.push("\n
|
|
130
|
+
this.progressSegments.push("\n");
|
|
131
131
|
}
|
|
132
132
|
this.progressSegments.push(text);
|
|
133
133
|
this.progressTextDirty = true;
|
|
@@ -390,7 +390,7 @@ class ChannelDeliveryController {
|
|
|
390
390
|
trimToRecentEntries(maxEntries) {
|
|
391
391
|
let entryCount = 0;
|
|
392
392
|
for (const segment of this.progressSegments) {
|
|
393
|
-
if (segment !== "\n
|
|
393
|
+
if (segment !== "\n") {
|
|
394
394
|
entryCount++;
|
|
395
395
|
}
|
|
396
396
|
}
|
|
@@ -401,11 +401,11 @@ class ChannelDeliveryController {
|
|
|
401
401
|
let removedEntries = 0;
|
|
402
402
|
while (removedEntries < entriesToRemove && this.progressSegments.length > 0) {
|
|
403
403
|
const segment = this.progressSegments.shift();
|
|
404
|
-
if (segment !== "\n
|
|
404
|
+
if (segment !== "\n") {
|
|
405
405
|
removedEntries++;
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
while (this.progressSegments[0] === "\n
|
|
408
|
+
while (this.progressSegments[0] === "\n") {
|
|
409
409
|
this.progressSegments.shift();
|
|
410
410
|
}
|
|
411
411
|
this.progressTextDirty = true;
|
|
@@ -37,6 +37,14 @@ export interface DingTalkEvent {
|
|
|
37
37
|
channelName?: string;
|
|
38
38
|
/** Runtime-owned durable-dispatch record, absent for normal inbound messages. */
|
|
39
39
|
dispatchId?: string;
|
|
40
|
+
/** Structured wake provenance created only by in-process producers. DingTalk inbound parsing
|
|
41
|
+
* never copies arbitrary payload fields into this event, so user text cannot manufacture it. */
|
|
42
|
+
internalWake?: {
|
|
43
|
+
kind: "job" | "subagent";
|
|
44
|
+
resourceId: string;
|
|
45
|
+
taskId: string;
|
|
46
|
+
dispatchId: string;
|
|
47
|
+
};
|
|
40
48
|
/**
|
|
41
49
|
* The `attemptGeneration` this event's claim recorded, for `[TASK_DRIVER:id]` events only.
|
|
42
50
|
* Carried through durable dispatch so `finishTaskAttempt` can tell a stale, superseded claim's
|
|
@@ -34,6 +34,10 @@ export declare class DurableDispatchService {
|
|
|
34
34
|
cancelChannel(channelId: string): Promise<number>;
|
|
35
35
|
markStarted(id: string | undefined): Promise<void>;
|
|
36
36
|
markCompleted(id: string | undefined): Promise<void>;
|
|
37
|
+
/** Release a failed handler's in-process claim without deleting its durable record. Structured
|
|
38
|
+
* wake activation uses this for transient task/job/run persistence failures so the next drain
|
|
39
|
+
* can retry the same dispatch id instead of losing the only completion signal. */
|
|
40
|
+
markRetryable(id: string | undefined): Promise<void>;
|
|
37
41
|
drainOnce(now?: number): Promise<void>;
|
|
38
42
|
private read;
|
|
39
43
|
private write;
|
|
@@ -160,6 +160,22 @@ export class DurableDispatchService {
|
|
|
160
160
|
await unlink(recordPath(this.options.stateDir, id)).catch(() => undefined);
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
+
/** Release a failed handler's in-process claim without deleting its durable record. Structured
|
|
164
|
+
* wake activation uses this for transient task/job/run persistence failures so the next drain
|
|
165
|
+
* can retry the same dispatch id instead of losing the only completion signal. */
|
|
166
|
+
async markRetryable(id) {
|
|
167
|
+
if (!id)
|
|
168
|
+
return;
|
|
169
|
+
this.running.delete(id);
|
|
170
|
+
await this.queue.run(id, async () => {
|
|
171
|
+
const record = await this.read(id);
|
|
172
|
+
if (!record)
|
|
173
|
+
return;
|
|
174
|
+
record.status = "pending";
|
|
175
|
+
record.leaseExpiresAt = undefined;
|
|
176
|
+
await this.write(record);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
163
179
|
async drainOnce(now = Date.now()) {
|
|
164
180
|
let filenames;
|
|
165
181
|
try {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
2
2
|
/**
|
|
3
|
-
* `/subagents` — the human control path that does not depend on the model (spec 040,
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* functions returning markdown, no bot/event coupling.
|
|
3
|
+
* `/subagents` — the human control path that does not depend on the model (spec 040 D6, polished
|
|
4
|
+
* by spec 041). Mirrors `task-commands.ts`'s shape: pure functions returning markdown, no
|
|
5
|
+
* bot/event coupling.
|
|
7
6
|
*/
|
|
8
7
|
export interface HandleSubagentsCommandOptions {
|
|
9
8
|
args: string;
|
|
10
9
|
channelId: string;
|
|
11
|
-
/** Best-effort role-directory snapshot for
|
|
12
|
-
* currently active for this channel (mirrors how `/status` degrades without a live runner). */
|
|
10
|
+
/** Best-effort role-directory snapshot for `roles` / the overview tail; omitted when no runner
|
|
11
|
+
* is currently active for this channel (mirrors how `/status` degrades without a live runner). */
|
|
13
12
|
discovery?: SubAgentDiscoveryResult;
|
|
13
|
+
/** Fallback used only when `discovery` is absent: resolves the role directory from disk without
|
|
14
|
+
* a live `ChannelRunner` (spec 041). Lazy — never called unless a `roles` view is actually rendered. */
|
|
15
|
+
getDetachedDiscovery?: () => Promise<SubAgentDiscoveryResult>;
|
|
14
16
|
}
|
|
15
17
|
export declare function handleSubagentsCommand(options: HandleSubagentsCommandOptions): Promise<string>;
|