@oyasmi/pipiclaw 0.9.2 → 0.9.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +250 -0
- package/README.md +3 -1
- package/dist/agent/channel-runner.d.ts +59 -2
- package/dist/agent/channel-runner.js +177 -76
- package/dist/agent/job-manager.d.ts +76 -21
- package/dist/agent/job-manager.js +447 -63
- package/dist/agent/maintenance-context.js +4 -5
- package/dist/agent/prompt/manifest.d.ts +0 -2
- package/dist/agent/prompt/manifest.js +2 -3
- package/dist/agent/prompt/sections.js +3 -3
- package/dist/agent/session-events.js +4 -8
- package/dist/agent/turn-prompt.d.ts +7 -7
- package/dist/agent/turn-prompt.js +6 -9
- package/dist/agent/types.d.ts +12 -0
- package/dist/agent/types.js +1 -0
- package/dist/channel/channel-context.d.ts +13 -0
- package/dist/channel/channel-context.js +21 -1
- package/dist/commands/catalog.js +47 -20
- package/dist/memory/commands.d.ts +8 -0
- package/dist/memory/commands.js +113 -148
- package/dist/memory/index-budget.d.ts +27 -0
- package/dist/memory/index-budget.js +99 -0
- package/dist/memory/journal.d.ts +20 -0
- package/dist/memory/journal.js +78 -0
- package/dist/memory/lifecycle.d.ts +9 -15
- package/dist/memory/lifecycle.js +55 -145
- package/dist/memory/maintenance-gates.d.ts +13 -47
- package/dist/memory/maintenance-gates.js +13 -92
- package/dist/memory/maintenance-state.d.ts +10 -16
- package/dist/memory/maintenance-state.js +12 -59
- package/dist/memory/maintenance-tuning.d.ts +7 -27
- package/dist/memory/maintenance-tuning.js +11 -28
- package/dist/memory/migrate.d.ts +15 -0
- package/dist/memory/migrate.js +364 -0
- package/dist/memory/reflect-job.d.ts +43 -0
- package/dist/memory/reflect-job.js +117 -0
- package/dist/memory/reflect.d.ts +52 -0
- package/dist/memory/reflect.js +313 -0
- package/dist/memory/render.d.ts +19 -0
- package/dist/memory/render.js +35 -0
- package/dist/memory/review-log.d.ts +2 -1
- package/dist/memory/scheduler.d.ts +2 -3
- package/dist/memory/scheduler.js +14 -49
- package/dist/memory/search.d.ts +35 -0
- package/dist/memory/search.js +297 -0
- package/dist/memory/session-search.js +1 -1
- package/dist/memory/store.d.ts +108 -0
- package/dist/memory/store.js +418 -0
- package/dist/memory/task-digest.d.ts +2 -2
- package/dist/memory/task-digest.js +29 -36
- package/dist/memory/tombstones.d.ts +0 -11
- package/dist/memory/tombstones.js +6 -37
- package/dist/memory/transcript.js +12 -5
- package/dist/playbooks/agent-delegation.md +37 -9
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/event-scheduling.md +6 -2
- package/dist/playbooks/memory-and-learning.md +36 -12
- package/dist/playbooks/outbound-media.md +1 -1
- package/dist/playbooks/runtime-orientation.md +9 -8
- package/dist/playbooks/task-loop.md +110 -0
- package/dist/runtime/bootstrap.d.ts +3 -3
- package/dist/runtime/bootstrap.js +66 -41
- package/dist/runtime/events.d.ts +9 -0
- package/dist/runtime/events.js +43 -4
- package/dist/runtime/task-commands.d.ts +14 -15
- package/dist/runtime/task-commands.js +249 -485
- package/dist/runtime/task-driver.d.ts +41 -29
- package/dist/runtime/task-driver.js +170 -317
- package/dist/runtime/task-migration.d.ts +34 -30
- package/dist/runtime/task-migration.js +229 -183
- package/dist/runtime/task-wake.d.ts +6 -3
- package/dist/runtime/task-wake.js +26 -19
- package/dist/settings.d.ts +0 -29
- package/dist/settings.js +12 -35
- package/dist/shared/markdown-sections.d.ts +0 -1
- package/dist/shared/markdown-sections.js +0 -3
- package/dist/subagents/discovery.d.ts +2 -2
- package/dist/subagents/discovery.js +21 -10
- package/dist/subagents/external/progress-tail.js +6 -1
- package/dist/subagents/external/run.js +1 -0
- package/dist/subagents/runs.d.ts +19 -2
- package/dist/subagents/runs.js +73 -4
- package/dist/subagents/tool.d.ts +10 -8
- package/dist/subagents/tool.js +55 -94
- package/dist/tasks/brief.d.ts +17 -0
- package/dist/tasks/brief.js +57 -0
- package/dist/tasks/budget.d.ts +26 -0
- package/dist/tasks/budget.js +59 -0
- package/dist/tasks/cycle.d.ts +48 -0
- package/dist/tasks/cycle.js +94 -0
- package/dist/tasks/frontmatter.d.ts +73 -0
- package/dist/tasks/frontmatter.js +175 -0
- package/dist/tasks/ledger.d.ts +66 -106
- package/dist/tasks/ledger.js +90 -546
- package/dist/tasks/log.d.ts +88 -0
- package/dist/tasks/log.js +97 -0
- package/dist/tasks/rounds.d.ts +41 -0
- package/dist/tasks/rounds.js +53 -0
- package/dist/tasks/session-path.d.ts +9 -0
- package/dist/tasks/session-path.js +16 -0
- package/dist/tasks/steer.d.ts +8 -0
- package/dist/tasks/steer.js +79 -0
- package/dist/tasks/store.d.ts +60 -35
- package/dist/tasks/store.js +166 -107
- package/dist/tasks/ticket.d.ts +102 -0
- package/dist/tasks/ticket.js +209 -0
- package/dist/tasks/verification.d.ts +47 -0
- package/dist/tasks/verification.js +60 -1
- package/dist/tools/index.d.ts +13 -4
- package/dist/tools/index.js +5 -10
- package/dist/tools/memory-manage.d.ts +6 -16
- package/dist/tools/memory-manage.js +108 -129
- package/dist/tools/presentation.js +2 -1
- package/dist/tools/registry.d.ts +11 -2
- package/dist/tools/registry.js +17 -6
- package/dist/tools/subagent-manage.d.ts +0 -9
- package/dist/tools/subagent-manage.js +8 -17
- package/dist/tools/task-manage/create.js +2 -2
- package/dist/tools/task-manage/lifecycle.d.ts +9 -4
- package/dist/tools/task-manage/lifecycle.js +136 -188
- package/dist/tools/task-manage/log-view.d.ts +8 -0
- package/dist/tools/task-manage/log-view.js +24 -0
- package/dist/tools/task-manage/schema.d.ts +38 -14
- package/dist/tools/task-manage/schema.js +46 -27
- package/dist/tools/task-manage/shared.d.ts +35 -31
- package/dist/tools/task-manage/shared.js +130 -141
- package/dist/tools/task-manage/step-end.d.ts +11 -0
- package/dist/tools/task-manage/step-end.js +134 -0
- package/dist/tools/task-manage/types.d.ts +23 -32
- package/dist/tools/task-manage.d.ts +4 -3
- package/dist/tools/task-manage.js +30 -15
- package/dist/tools/tool-details.d.ts +1 -1
- package/dist/tui/app.js +0 -2
- package/examples/sub-agents/README.md +54 -38
- package/examples/sub-agents/builder-hard.md +21 -12
- package/examples/sub-agents/builder.md +24 -16
- package/examples/sub-agents/explorer.md +17 -15
- package/examples/sub-agents/git-committer.md +8 -6
- package/examples/sub-agents/planner.md +17 -16
- package/examples/sub-agents/reviewer.md +11 -9
- package/examples/sub-agents/verifier.md +22 -16
- package/examples/sub-agents/worker.md +22 -6
- package/package.json +1 -1
- package/dist/agent/effect-ledger.d.ts +0 -32
- package/dist/agent/effect-ledger.js +0 -89
- package/dist/memory/bootstrap.d.ts +0 -17
- package/dist/memory/bootstrap.js +0 -120
- package/dist/memory/candidates.d.ts +0 -26
- package/dist/memory/candidates.js +0 -202
- package/dist/memory/consolidation.d.ts +0 -54
- package/dist/memory/consolidation.js +0 -292
- package/dist/memory/extraction.d.ts +0 -54
- package/dist/memory/extraction.js +0 -240
- package/dist/memory/files.d.ts +0 -71
- package/dist/memory/files.js +0 -419
- package/dist/memory/maintenance-jobs.d.ts +0 -41
- package/dist/memory/maintenance-jobs.js +0 -265
- package/dist/memory/metadata.d.ts +0 -57
- package/dist/memory/metadata.js +0 -142
- package/dist/memory/probation.d.ts +0 -17
- package/dist/memory/probation.js +0 -44
- package/dist/memory/promotion.d.ts +0 -38
- package/dist/memory/promotion.js +0 -36
- package/dist/memory/recall.d.ts +0 -59
- package/dist/memory/recall.js +0 -746
- package/dist/memory/session.d.ts +0 -24
- package/dist/memory/session.js +0 -273
- package/dist/playbooks/task-driving.md +0 -92
- package/dist/playbooks/task-planning.md +0 -58
- package/dist/tasks/control.d.ts +0 -56
- package/dist/tasks/control.js +0 -169
- package/dist/tasks/transitions.d.ts +0 -16
- package/dist/tasks/transitions.js +0 -48
- package/dist/tools/task-manage/verification.d.ts +0 -19
- package/dist/tools/task-manage/verification.js +0 -91
- package/examples/sub-agents/documenter.md +0 -50
- package/examples/sub-agents/log-sifter.md +0 -47
- package/examples/sub-agents/scout.md +0 -34
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "fs/promises";
|
|
2
2
|
import { join, relative } from "path";
|
|
3
|
-
import { channelEffectCount, noteTaskEffects, taskEffectCount } from "../agent/effect-ledger.js";
|
|
4
3
|
import { channelRunningJobLines, configureJobRuntime, restoreChannelJobs } from "../agent/job-manager.js";
|
|
5
4
|
import { loadDetachedMaintenanceContext } from "../agent/maintenance-context.js";
|
|
6
5
|
import { createRunner } from "../agent/runner-factory.js";
|
|
7
6
|
import { renderStatus } from "../agent/status-render.js";
|
|
8
7
|
import { scanWorkspaceForInterruptedTurns } from "../agent/turn-recovery.js";
|
|
9
8
|
import { createFreshActiveSession } from "../channel/active-session-store.js";
|
|
9
|
+
import { muteChannelContext } from "../channel/channel-context.js";
|
|
10
10
|
import { createChannelIndex } from "../channel/channel-index.js";
|
|
11
11
|
import { ensureChannelDir, getChannelDir } from "../channel/channel-paths.js";
|
|
12
12
|
import { resolveProjectScope } from "../channel/project-scope-store.js";
|
|
@@ -14,7 +14,6 @@ import { ChannelStore } from "../channel/store.js";
|
|
|
14
14
|
import { BUILT_IN_COMMANDS, formatUnknownCommandMessage, isRunnerBuiltInCommand, parseBuiltInCommand, slashCommandName, } from "../commands/catalog.js";
|
|
15
15
|
import { createExecutor } from "../executor.js";
|
|
16
16
|
import * as log from "../log.js";
|
|
17
|
-
import { ensureChannelMemoryFilesSync } from "../memory/files.js";
|
|
18
17
|
import { MemoryMaintenanceScheduler } from "../memory/scheduler.js";
|
|
19
18
|
import { defaultModel } from "../models/utils.js";
|
|
20
19
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
@@ -28,7 +27,10 @@ import { errorMessage } from "../shared/text-utils.js";
|
|
|
28
27
|
import { sleepUnref } from "../shared/with-timeout.js";
|
|
29
28
|
import { loadDetachedSubAgentDiscovery } from "../subagents/detached-discovery.js";
|
|
30
29
|
import { configureSubAgentRuntime, getSubAgentRunManager, restoreAllSubAgentRuns, stopSubAgentGarbageCollector, } from "../subagents/runs.js";
|
|
30
|
+
import { buildTaskStepBrief } from "../tasks/brief.js";
|
|
31
31
|
import { readActiveTasks } from "../tasks/ledger.js";
|
|
32
|
+
import { consumeTaskNotice } from "../tasks/steer.js";
|
|
33
|
+
import { readStoredTask } from "../tasks/store.js";
|
|
32
34
|
import { getToolsConfigPath, loadToolsConfig, loadToolsConfigWithDiagnostics } from "../tools/config.js";
|
|
33
35
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
34
36
|
import { parseUsageMode, renderUsageReport } from "../usage/render.js";
|
|
@@ -45,7 +47,7 @@ import { handleSkillsCommand as runSkillsCommand } from "./skill-commands.js";
|
|
|
45
47
|
import { renderRunNotice, handleSubagentsCommand as runSubagentsCommand } from "./subagent-commands.js";
|
|
46
48
|
import { pauseTask, handleTasksCommand as runTasksCommand } from "./task-commands.js";
|
|
47
49
|
import { createTaskDriverEvent, TaskDriver } from "./task-driver.js";
|
|
48
|
-
import {
|
|
50
|
+
import { migrateTasksToV4 } from "./task-migration.js";
|
|
49
51
|
import { claimVerifiedDelegationWake, claimVerifiedJobWake } from "./task-wake.js";
|
|
50
52
|
const SHUTDOWN_WAIT_MS = 15000;
|
|
51
53
|
const SHUTDOWN_FLUSH_WAIT_MS = 45000;
|
|
@@ -148,6 +150,48 @@ export async function forceEndStuckTurnAfterStop(input) {
|
|
|
148
150
|
}
|
|
149
151
|
function createDingTalkHandler(deps) {
|
|
150
152
|
const { options, store, channelRunners, sessionResetChains, activeTasks, stopWatchdogs, channelIndex, archiveIncomingMessage, getRunner, cliVersion, startedAt, isShuttingDown, getDurableDispatch, getExecutor, getTaskDriver, } = deps;
|
|
153
|
+
/**
|
|
154
|
+
* Turn a `[TASK_DRIVER:<id>]` dispatch into a task loop step: bind the runner to the task
|
|
155
|
+
* cycle's own session and replace the wake text with the step brief. Returns `undefined` for
|
|
156
|
+
* every other event, which then follows the unchanged chat path.
|
|
157
|
+
*
|
|
158
|
+
* Binding failures fall back to the chat path rather than dropping the wake — a task that
|
|
159
|
+
* cannot open its session should still be visible, not silently skipped.
|
|
160
|
+
*/
|
|
161
|
+
const prepareTaskStep = async (event, runner) => {
|
|
162
|
+
const match = /^\[TASK_DRIVER:([A-Za-z0-9._-]+)\]/.exec(event.text);
|
|
163
|
+
if (!match?.[1] || !runner.bindTaskSession)
|
|
164
|
+
return undefined;
|
|
165
|
+
const taskId = match[1];
|
|
166
|
+
const channelDir = ensureChannelDir(options.paths.workspaceDir, event.channelId);
|
|
167
|
+
try {
|
|
168
|
+
const document = await readStoredTask(channelDir, taskId);
|
|
169
|
+
if (!document)
|
|
170
|
+
return undefined;
|
|
171
|
+
const brief = await buildTaskStepBrief({ channelDir, taskId });
|
|
172
|
+
if (!brief)
|
|
173
|
+
return undefined;
|
|
174
|
+
await runner.bindTaskSession(taskId, document.fields.cycle?.id ?? "c-adhoc");
|
|
175
|
+
return { taskId, brief };
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
log.logWarning(`[${event.channelId}] Could not start task step for ${taskId}`, errorMessage(error));
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
/** Deliver whatever the step asked to say, then hand the runner back to the chat session. */
|
|
183
|
+
const finishTaskStep = async (channelId, taskId, ctx) => {
|
|
184
|
+
const channelDir = ensureChannelDir(options.paths.workspaceDir, channelId);
|
|
185
|
+
try {
|
|
186
|
+
const notice = await consumeTaskNotice(channelDir, taskId);
|
|
187
|
+
if (notice)
|
|
188
|
+
await ctx.respond(notice, true);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
log.logWarning(`[${channelId}] Could not deliver task notice for ${taskId}`, errorMessage(error));
|
|
192
|
+
}
|
|
193
|
+
await getRunner(channelId).bindChatSession?.();
|
|
194
|
+
};
|
|
151
195
|
const handler = {
|
|
152
196
|
isRunning(channelId) {
|
|
153
197
|
return channelRunners.get(channelId)?.isBusy() ?? false;
|
|
@@ -218,7 +262,6 @@ function createDingTalkHandler(deps) {
|
|
|
218
262
|
.then(async () => {
|
|
219
263
|
try {
|
|
220
264
|
const channelDir = ensureChannelDir(options.paths.workspaceDir, event.channelId);
|
|
221
|
-
ensureChannelMemoryFilesSync(channelDir);
|
|
222
265
|
const access = resolveProjectAccessPolicy(loadSecurityConfigWithDiagnostics(options.paths.appHomeDir).config, process.cwd());
|
|
223
266
|
const scope = resolveProjectScope(channelDir, access);
|
|
224
267
|
if (scope.kind === "blocked") {
|
|
@@ -452,7 +495,8 @@ function createDingTalkHandler(deps) {
|
|
|
452
495
|
// handler, making the busy state observable to another message in the same tick.
|
|
453
496
|
getRunner(event.channelId).beginTurn(event.text);
|
|
454
497
|
},
|
|
455
|
-
async handleEvent(
|
|
498
|
+
async handleEvent(inboundEvent, bot, _isEvent) {
|
|
499
|
+
let event = inboundEvent;
|
|
456
500
|
if (isShuttingDown()) {
|
|
457
501
|
log.logInfo(`[${event.channelId}] Ignoring event during shutdown`);
|
|
458
502
|
return;
|
|
@@ -481,7 +525,15 @@ function createDingTalkHandler(deps) {
|
|
|
481
525
|
// wake (a delegation or job finishing) is the opposite — a human is actually waiting
|
|
482
526
|
// on it — so it renders progress the same way a normal message does (P0-2).
|
|
483
527
|
const backgroundOnly = Boolean(_isEvent) && event.presentation !== "awaited";
|
|
484
|
-
const
|
|
528
|
+
const baseCtx = createDingTalkContext(event, bot, store, backgroundOnly ? "none" : undefined);
|
|
529
|
+
// Spec 051, D3: a task-driver dispatch runs as a *task step* — in the task cycle's
|
|
530
|
+
// own session, with a brief instead of the wake text, and silent unless the step
|
|
531
|
+
// asked for a notify. Everything below (busy state, /stop, delivery) is unchanged;
|
|
532
|
+
// only which session the turn is bound to, and what reaches the channel, differ.
|
|
533
|
+
const taskStep = await prepareTaskStep(event, runner);
|
|
534
|
+
const ctx = taskStep ? muteChannelContext(baseCtx) : baseCtx;
|
|
535
|
+
if (taskStep)
|
|
536
|
+
event = { ...event, text: taskStep.brief };
|
|
485
537
|
if (builtInCommand) {
|
|
486
538
|
const commandStartedAt = Date.now();
|
|
487
539
|
const logCtx = { channelId: event.channelId, userName: event.userName };
|
|
@@ -536,10 +588,6 @@ function createDingTalkHandler(deps) {
|
|
|
536
588
|
if (!backgroundOnly) {
|
|
537
589
|
ctx.primeCard(350);
|
|
538
590
|
}
|
|
539
|
-
// Effects are tallied per channel; the governor needs them per task, so one
|
|
540
|
-
// task-driver turn is measured as a delta (turns on a channel are serialized)
|
|
541
|
-
// and credited to the task it was dispatched for.
|
|
542
|
-
const effectsBefore = channelEffectCount(event.channelId);
|
|
543
591
|
// Both wake formats below carry an unauthenticated claim in plain text: anything
|
|
544
592
|
// that can put a message on this channel can *write* "[JOB:x] ... belongs to task
|
|
545
593
|
// y." or "[SUBAGENT:x] ... belongs to task y." — including another user, or an
|
|
@@ -553,13 +601,10 @@ function createDingTalkHandler(deps) {
|
|
|
553
601
|
const jobMatch = event.internalWake?.kind === "job"
|
|
554
602
|
? [event.text, event.internalWake.resourceId, event.internalWake.taskId]
|
|
555
603
|
: jobTextMatch;
|
|
556
|
-
let recoveredJobTaskId;
|
|
557
604
|
if (jobMatch) {
|
|
558
605
|
const [, jobId, jobTaskId] = jobMatch;
|
|
559
606
|
const claimed = await claimVerifiedJobWake(event, options.paths.workspaceDir, getExecutor(), options.wakeTransitionHooks?.job);
|
|
560
607
|
if (claimed) {
|
|
561
|
-
if (claimed.activated)
|
|
562
|
-
recoveredJobTaskId = claimed.taskId;
|
|
563
608
|
await claimed.finish();
|
|
564
609
|
structuredWakeFinalized = true;
|
|
565
610
|
// Drop without a turn only when something else is still driving this task (a
|
|
@@ -584,13 +629,10 @@ function createDingTalkHandler(deps) {
|
|
|
584
629
|
const delegationMatch = event.internalWake?.kind === "subagent"
|
|
585
630
|
? [event.text, event.internalWake.resourceId, event.internalWake.taskId]
|
|
586
631
|
: delegationTextMatch;
|
|
587
|
-
let recoveredDelegationTaskId;
|
|
588
632
|
if (delegationMatch) {
|
|
589
633
|
const [, runId, delegationTaskId] = delegationMatch;
|
|
590
634
|
const claimed = await claimVerifiedDelegationWake(event, options.paths.workspaceDir, options.wakeTransitionHooks?.subagent);
|
|
591
635
|
if (claimed) {
|
|
592
|
-
if (claimed.activated)
|
|
593
|
-
recoveredDelegationTaskId = claimed.taskId;
|
|
594
636
|
await claimed.finish();
|
|
595
637
|
structuredWakeFinalized = true;
|
|
596
638
|
// See the JOB branch above (P3-1): only skip the turn when the task is still
|
|
@@ -607,14 +649,8 @@ function createDingTalkHandler(deps) {
|
|
|
607
649
|
}
|
|
608
650
|
}
|
|
609
651
|
const result = await runner.run(ctx, store);
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
// The three sources above are mutually exclusive (each regex is anchored at the
|
|
613
|
-
// start of a distinct prefix), so crediting effects to whichever one matched is
|
|
614
|
-
// equivalent to checking all three separately.
|
|
615
|
-
if (taskAttemptId) {
|
|
616
|
-
noteTaskEffects(event.channelId, taskAttemptId, channelEffectCount(event.channelId) - effectsBefore);
|
|
617
|
-
}
|
|
652
|
+
if (taskStep)
|
|
653
|
+
await finishTaskStep(event.channelId, taskStep.taskId, baseCtx);
|
|
618
654
|
if (result.stopReason === "aborted" && runner.getTurnStatus().stopRequested) {
|
|
619
655
|
log.logInfo(`[${event.channelId}] Stopped`);
|
|
620
656
|
}
|
|
@@ -631,8 +667,8 @@ function createDingTalkHandler(deps) {
|
|
|
631
667
|
else
|
|
632
668
|
await getDurableDispatch()?.markRetryable(event.dispatchId);
|
|
633
669
|
runner.endTurn();
|
|
634
|
-
// A finished turn may have written task files
|
|
635
|
-
//
|
|
670
|
+
// A finished turn may have written task files; rescan now so `outcome: continue`
|
|
671
|
+
// queues the next step immediately instead of waiting out the current sleep.
|
|
636
672
|
getTaskDriver().nudge?.();
|
|
637
673
|
}
|
|
638
674
|
})();
|
|
@@ -684,7 +720,6 @@ export async function createRuntimeContext(options) {
|
|
|
684
720
|
return existing;
|
|
685
721
|
}
|
|
686
722
|
const channelDir = ensureChannelDir(options.paths.workspaceDir, channelId);
|
|
687
|
-
ensureChannelMemoryFilesSync(channelDir);
|
|
688
723
|
const runner = createRunner(channelId, channelDir, {
|
|
689
724
|
appHomeDir: options.paths.appHomeDir,
|
|
690
725
|
authConfigPath: options.paths.authConfigPath,
|
|
@@ -825,10 +860,7 @@ export async function createRuntimeContext(options) {
|
|
|
825
860
|
isChannelActive: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
826
861
|
getSettings: () => {
|
|
827
862
|
runtimeSettingsManager.reload();
|
|
828
|
-
return {
|
|
829
|
-
memoryMaintenance: runtimeSettingsManager.getMemoryMaintenanceSettings(),
|
|
830
|
-
sessionMemory: runtimeSettingsManager.getSessionMemorySettings(),
|
|
831
|
-
};
|
|
863
|
+
return { memoryMaintenance: runtimeSettingsManager.getMemoryMaintenanceSettings() };
|
|
832
864
|
},
|
|
833
865
|
intervalMs: options.memoryMaintenanceSchedulerIntervalMs,
|
|
834
866
|
});
|
|
@@ -853,7 +885,6 @@ export async function createRuntimeContext(options) {
|
|
|
853
885
|
isChannelActive: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
854
886
|
dispatch: (event) => durableDispatch?.dispatch(event) ?? false,
|
|
855
887
|
onDispatch: options.onTaskDriverDispatch,
|
|
856
|
-
getEffectCount: taskEffectCount,
|
|
857
888
|
notify: (receipt) => bot.sendPlain(receipt.channelId, receipt.text),
|
|
858
889
|
getSettings: () => {
|
|
859
890
|
runtimeSettingsManager.reload();
|
|
@@ -948,15 +979,9 @@ export async function createRuntimeContext(options) {
|
|
|
948
979
|
});
|
|
949
980
|
}
|
|
950
981
|
if (startServices) {
|
|
951
|
-
//
|
|
952
|
-
//
|
|
953
|
-
|
|
954
|
-
// phase 5): each file is judged by what it actually contains, so this is safe and cheap to run
|
|
955
|
-
// on every startup — a hand-edited or freshly-restored legacy file self-heals on the next boot.
|
|
956
|
-
void Promise.all([
|
|
957
|
-
migrateLegacyTaskScheduleEvents(options.paths.workspaceDir),
|
|
958
|
-
migrateLegacyTaskState(options.paths.workspaceDir),
|
|
959
|
-
]);
|
|
982
|
+
// Upgrade every v3 task file to the v4 contract before the driver relies on it (spec 051, D14). Marker-gated: the pass rewrites
|
|
983
|
+
// bodies and imports history into the loop log, so it must run exactly once per install.
|
|
984
|
+
void migrateTasksToV4(options.paths.workspaceDir, join(options.paths.appHomeDir, "state"));
|
|
960
985
|
eventsWatcher.start();
|
|
961
986
|
memoryMaintenanceScheduler.start();
|
|
962
987
|
taskDriver.start();
|
package/dist/runtime/events.d.ts
CHANGED
|
@@ -115,6 +115,15 @@ export declare class EventsWatcher {
|
|
|
115
115
|
* split that would cut a dotted task id short.
|
|
116
116
|
*/
|
|
117
117
|
private orphanedOwnerReason;
|
|
118
|
+
/**
|
|
119
|
+
* Redeem the owning task's `signal` ticket, if this is a task-owned event and that task is
|
|
120
|
+
* parked on a ticket naming exactly this event. Returns whether the ticket was redeemed.
|
|
121
|
+
*
|
|
122
|
+
* The name match is strict (INV-7): a ticket only accepts the event it names, so an unrelated
|
|
123
|
+
* task-owned event can never resume a task, and a task parked on anything else still gets its
|
|
124
|
+
* ordinary chat wake.
|
|
125
|
+
*/
|
|
126
|
+
private redeemTaskSignal;
|
|
118
127
|
private execute;
|
|
119
128
|
private runPreAction;
|
|
120
129
|
private deleteFile;
|
package/dist/runtime/events.js
CHANGED
|
@@ -10,7 +10,8 @@ import { createJsonlAppender } from "../shared/jsonl-appender.js";
|
|
|
10
10
|
import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
|
|
11
11
|
import { clipText, errorMessage, eventNameFromFilename } from "../shared/text-utils.js";
|
|
12
12
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
13
|
-
import {
|
|
13
|
+
import { parseTaskFrontmatterV4 } from "../tasks/frontmatter.js";
|
|
14
|
+
import { redeemTicket } from "../tasks/store.js";
|
|
14
15
|
import { parseTaskEventName } from "../tasks/task-events.js";
|
|
15
16
|
import { MAX_EVENT_FILES, MAX_ONE_SHOT_DELAY_MS, validateScheduledEvent } from "./event-validation.js";
|
|
16
17
|
// ============================================================================
|
|
@@ -505,11 +506,37 @@ export class EventsWatcher {
|
|
|
505
506
|
catch {
|
|
506
507
|
return `owning task ${taskId} no longer exists`;
|
|
507
508
|
}
|
|
508
|
-
const frontmatter =
|
|
509
|
-
return frontmatter.
|
|
510
|
-
? `owning task ${taskId} is archived (${frontmatter.
|
|
509
|
+
const frontmatter = parseTaskFrontmatterV4(content);
|
|
510
|
+
return frontmatter.fields.outcome
|
|
511
|
+
? `owning task ${taskId} is archived (${frontmatter.fields.outcome})`
|
|
511
512
|
: undefined;
|
|
512
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Redeem the owning task's `signal` ticket, if this is a task-owned event and that task is
|
|
516
|
+
* parked on a ticket naming exactly this event. Returns whether the ticket was redeemed.
|
|
517
|
+
*
|
|
518
|
+
* The name match is strict (INV-7): a ticket only accepts the event it names, so an unrelated
|
|
519
|
+
* task-owned event can never resume a task, and a task parked on anything else still gets its
|
|
520
|
+
* ordinary chat wake.
|
|
521
|
+
*/
|
|
522
|
+
async redeemTaskSignal(filename, event) {
|
|
523
|
+
const name = eventNameFromFilename(filename);
|
|
524
|
+
const parsed = parseTaskEventName(name, event.channelId);
|
|
525
|
+
if (!parsed)
|
|
526
|
+
return false;
|
|
527
|
+
const channelDir = getChannelDir(dirname(this.eventsDir), event.channelId);
|
|
528
|
+
try {
|
|
529
|
+
const redeemed = await redeemTicket(channelDir, parsed.id, (ticket) => ticket.kind === "signal" && ticket.event === name);
|
|
530
|
+
if (!redeemed)
|
|
531
|
+
return false;
|
|
532
|
+
log.logInfo(`Event ${name} redeemed the signal ticket for task ${parsed.id}`);
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
catch (error) {
|
|
536
|
+
log.logWarning(`Could not redeem signal ticket for task ${parsed.id}`, errorMessage(error));
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
513
540
|
async execute(filename, event, deleteAfter = true, occurrence = new Date()) {
|
|
514
541
|
const orphaned = await this.orphanedOwnerReason(filename, event);
|
|
515
542
|
if (orphaned) {
|
|
@@ -559,6 +586,18 @@ export class EventsWatcher {
|
|
|
559
586
|
return;
|
|
560
587
|
}
|
|
561
588
|
}
|
|
589
|
+
// Spec 051, D8: the *only* touchpoint between the events subsystem and the task loop. When a
|
|
590
|
+
// task-owned sensor fires and the owning task is parked on a `signal` ticket naming this very
|
|
591
|
+
// event, redeem the ticket and stop — the task's own loop takes it from here, and delivering
|
|
592
|
+
// a chat wake as well would both duplicate the work and route it into the wrong session.
|
|
593
|
+
// Anything else (an ordinary event, or a task that is not waiting on this signal) falls
|
|
594
|
+
// through to the unchanged delivery path below.
|
|
595
|
+
if (await this.redeemTaskSignal(filename, event)) {
|
|
596
|
+
this.appendEventHistory(filename, event, "triggered", "ok", { reason: "redeemed task signal ticket" });
|
|
597
|
+
if (deleteAfter)
|
|
598
|
+
this.deleteFile(filename);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
562
601
|
let scheduleInfo;
|
|
563
602
|
switch (event.type) {
|
|
564
603
|
case "one-shot":
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
+
import type { TaskBudget } from "../tasks/frontmatter.js";
|
|
1
2
|
export interface HandleTasksCommandOptions {
|
|
2
3
|
args: string;
|
|
3
4
|
/** The channel directory; tasks live in `<channelDir>/tasks/`. */
|
|
4
5
|
channelDir: string;
|
|
5
|
-
/** Workspace directory;
|
|
6
|
+
/** Workspace directory; kept for callers that still pass it (doctor reads task-owned events). */
|
|
6
7
|
workspaceDir?: string;
|
|
7
8
|
channelId?: string;
|
|
8
9
|
/** Optional immediate task wake, available in the long-lived DingTalk runtime. */
|
|
9
10
|
dispatchTask?: (id: string) => Promise<boolean>;
|
|
10
11
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Fields `/tasks set` can edit directly.
|
|
13
|
-
*
|
|
14
|
-
* Deliberately a small, flat set: the ones a user already knows they want to change (when it
|
|
15
|
-
* should wake, what it should do next, how much rope it has). Everything structural — status
|
|
16
|
-
* transitions and verification — stays with `task_update`/`task_close`/`task_verify`, whose state
|
|
17
|
-
* machine those fields belong to. The value is the rest of the line, so it may contain spaces.
|
|
18
|
-
*/
|
|
19
|
-
declare const SETTABLE_TASK_FIELDS: readonly ["wake", "next", "deadline"];
|
|
20
|
-
type SettableTaskField = (typeof SETTABLE_TASK_FIELDS)[number];
|
|
21
12
|
type TasksCommand = {
|
|
22
13
|
action: "list";
|
|
23
14
|
} | {
|
|
24
15
|
action: "show";
|
|
25
16
|
id: string;
|
|
17
|
+
} | {
|
|
18
|
+
action: "log";
|
|
19
|
+
id: string;
|
|
20
|
+
cycle?: string;
|
|
26
21
|
} | {
|
|
27
22
|
action: "archive";
|
|
28
23
|
} | {
|
|
@@ -33,18 +28,22 @@ type TasksCommand = {
|
|
|
33
28
|
} | {
|
|
34
29
|
action: "resume";
|
|
35
30
|
id: string;
|
|
31
|
+
grants: Partial<TaskBudget>;
|
|
36
32
|
} | {
|
|
37
33
|
action: "run";
|
|
38
34
|
id: string;
|
|
39
35
|
} | {
|
|
40
|
-
action: "
|
|
36
|
+
action: "steer";
|
|
37
|
+
id: string;
|
|
38
|
+
text: string;
|
|
39
|
+
} | {
|
|
40
|
+
action: "reply";
|
|
41
41
|
id: string;
|
|
42
|
-
|
|
43
|
-
value: string;
|
|
42
|
+
text: string;
|
|
44
43
|
};
|
|
45
44
|
/** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
|
|
46
45
|
export declare function parseTasksCommand(args: string): TasksCommand;
|
|
47
46
|
export declare function pauseTask(options: HandleTasksCommandOptions, idInput: string): Promise<string>;
|
|
48
|
-
export declare function resumeTask(options: HandleTasksCommandOptions, idInput: string): Promise<string>;
|
|
47
|
+
export declare function resumeTask(options: HandleTasksCommandOptions, idInput: string, grants?: Partial<TaskBudget>): Promise<string>;
|
|
49
48
|
export declare function handleTasksCommand(options: HandleTasksCommandOptions): Promise<string>;
|
|
50
49
|
export {};
|