@zq-silk/yui 0.11.3 → 0.12.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/ARCHITECTURE.md +23 -4
- package/README.md +36 -13
- package/dist/cli/commandCatalog.js +2 -4
- package/dist/cli.js +105 -43
- package/dist/commands/configCommands.js +12 -45
- package/dist/commands/executionAuditCommands.js +1 -1
- package/dist/commands/jobCommands.js +4 -10
- package/dist/commands/taskCommands.js +154 -171
- package/dist/commands/taskCompletionGate.js +29 -54
- package/dist/commands/taskContextCommand.js +55 -11
- package/dist/commands/taskInputCommands.js +8 -5
- package/dist/commands/taskNextActionCommand.js +56 -6
- package/dist/commands/taskOverviewCommand.js +17 -31
- package/dist/commands/taskRoleRuntimeStatus.js +24 -0
- package/dist/commands/taskWorkspaceCommands.js +5 -2
- package/dist/config/configCatalog.js +2 -2
- package/dist/config/yuiConfig.js +3 -7
- package/dist/context/wakeNotification.js +20 -5
- package/dist/controller/agentRuntimeObserver.js +247 -51
- package/dist/controller/clientRuntime.js +1 -1
- package/dist/controller/controller.js +8 -12
- package/dist/controller/fileSchedulerStoreAdapter.js +146 -198
- package/dist/controller/runtime.js +3 -3
- package/dist/controller/runtimeEventInbox.js +17 -7
- package/dist/controller/runtimeEventProcessor.js +12 -19
- package/dist/controller/runtimeObservationHook.js +45 -0
- package/dist/execution/resourceBroker.js +5 -4
- package/dist/executor/agentExecutor.js +4 -4
- package/dist/executor/effectiveLaunch.js +8 -48
- package/dist/executor/fileRoleLaunchPlanner.js +36 -16
- package/dist/executor/workspacePreflightClassification.js +23 -2
- package/dist/interaction/operatorPresentation.js +33 -89
- package/dist/lifecycle/exactRunTerminalization.js +1 -2
- package/dist/lifecycle/taskRoleSessionReset.js +5 -13
- package/dist/observability/orchestrationMetrics.js +8 -3
- package/dist/profile/agentProfile.js +1 -1
- package/dist/release/cliHomeReleaseFence.js +123 -0
- package/dist/repository/taskWorkspacePreparer.js +176 -60
- package/dist/resources/sqliteResourceRegistry.js +1 -1
- package/dist/review/deltaRecheck.js +12 -51
- package/dist/review/reviewAcceptance.js +26 -0
- package/dist/review/reviewConfig.js +0 -31
- package/dist/review/reviewDecision.js +113 -0
- package/dist/review/reviewOutcomeClassifier.js +1 -1
- package/dist/review/reviewRound.js +1 -1
- package/dist/review/reviewerAvailability.js +69 -0
- package/dist/runtime/agentDriverObservation.js +24 -10
- package/dist/runtime/builtinAgentDrivers.js +4 -3
- package/dist/runtime/builtinTranscriptObserver.js +301 -64
- package/dist/runtime/builtinTranscriptUsage.js +9 -7
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/runtimeObservation.js +13 -0
- package/dist/runtime/runtimeProjection.js +16 -25
- package/dist/runtime/sessionTokenMetrics.js +181 -0
- package/dist/runtime/structuredProviderHost.js +7 -1
- package/dist/scheduler/activeRoleRunDelivery.js +4 -4
- package/dist/scheduler/activeTaskProgress.js +7 -6
- package/dist/scheduler/leaderWakeupProcessor.js +3 -5
- package/dist/scheduler/operatorEvent.js +34 -0
- package/dist/scheduler/operatorInputNotificationProcessor.js +54 -94
- package/dist/scheduler/roleRunStall.js +0 -14
- package/dist/scheduler/taskExecutionProjection.js +97 -76
- package/dist/scheduler/taskObservabilityProjection.js +10 -11
- package/dist/storage/migration/productionRegistry.js +379 -0
- package/dist/storage/sqliteSchema.js +18 -8
- package/dist/storage/sqliteStore.js +24 -20
- package/dist/storage/storeRpc.js +0 -1
- package/dist/storage/taskStore.js +15 -30
- package/dist/storage/upgrade/recordVersions.js +3 -2
- package/dist/storage/upgrade/sqliteMigrationTarget.js +30 -8
- package/dist/storage/upgrade/sqliteRecordMigrationTarget.js +23 -11
- package/dist/storage/upgrade/sqliteStateMigration.js +66 -8
- package/dist/task/completionReadiness.js +10 -6
- package/dist/task/nextAction.js +82 -24
- package/dist/telemetry/sqliteTelemetryStore.js +1 -1
- package/dist/web/assets/client/components.js +13 -3
- package/dist/web/assets/client/i18n.js +6 -2
- package/dist/web/webSnapshot.js +4 -0
- package/i18n/README.zh-CN.md +2 -2
- package/package.json +1 -1
- package/skills/yui-leader/SKILL.md +53 -16
- package/skills/yui-operator/SKILL.md +9 -0
- package/skills/yui-reviewer/SKILL.md +28 -7
- package/dist/context/sessionContextBudget.js +0 -71
- package/dist/lifecycle/contextBudgetRollover.js +0 -81
- package/dist/scheduler/operatorNotification.js +0 -59
package/i18n/README.zh-CN.md
CHANGED
|
@@ -308,7 +308,7 @@ yui task work group resolve <task-id>/<work-item-id> \
|
|
|
308
308
|
|
|
309
309
|
每个新阶段还会冻结一份 Resource Broker 契约:token、工具调用和墙钟预算,
|
|
310
310
|
quorum 与 deadline,straggler 窗口,以及继续增加 Lane 所需的最低边际价值。
|
|
311
|
-
|
|
311
|
+
省略这些参数时使用独立的执行成本默认值与 runtime-health 时间窗;同一阶段的 retry
|
|
312
312
|
累计原有花费并共享绝对 deadline。执行、Lane retry 和 Reviewer panel 准入统一核算
|
|
313
313
|
Home、Task、WorkItem、Group、Provider、Agent 和模型层级的活动 Lane;容量不足的
|
|
314
314
|
Lane 会耐久保留为 pending,不会把整个 Group 判失败。容量释放或 deadline 到达会沿
|
|
@@ -484,7 +484,7 @@ yui task input request <task-id> --question "默认使用哪种格式?" \
|
|
|
484
484
|
|
|
485
485
|
推荐项会明确展示给用户;如果截止时间前没有回答,独立的最近 deadline timer 会唤醒 Controller,原子采用这个确定选项,并排队恢复固定的 Leader session。自由文本和必须由用户回答的请求永远不会自动解决。
|
|
486
486
|
|
|
487
|
-
`task input list` 是权威的全局开放输入 Inbox;可附加 Task ID 限定范围,或使用 `--all` 查看已回答和已取消的请求。Controller
|
|
487
|
+
`task input list` 是权威的全局开放输入 Inbox;可附加 Task ID 限定范围,或使用 `--all` 查看已回答和已取消的请求。Task 完成、退役、Leader attention、stall 和开放输入只以不可变 TaskEvent 或 InputRequest 引用进入全局 Operator mailbox。Controller 把一个待处理 batch 合并成一条带回执的 `[Yui updates]` user message,仅投递给已有且 ready 的 Operator;Operator 再通过 CLI 读取引用记录,判断哪些信息值得呈现。Operator 正在运行或不可用时,Yui 不启动也不打断它,整批引用保持持久化,并在原生 turn 完成或后续 Controller 处理中重试。该路径是 user message,不是 tool call,也不会读取或分类 Agent 终端文本。用户和 Operator 都可回答。存在开放请求时,无关的 pending wake 不会绕过等待,Task 也不能 complete 或 archive。原 Leader 也可执行 `yui task input cancel <task-id> <input-id> --reason "..."`,取消会排队恢复该固定 Leader session。
|
|
488
488
|
|
|
489
489
|
```sh
|
|
490
490
|
yui task context <task-id>
|
package/package.json
CHANGED
|
@@ -323,12 +323,14 @@ Choose before creating the WorkItem:
|
|
|
323
323
|
Keep review execution separate from implementation. No global Reviewer is
|
|
324
324
|
required: when review is disabled, inspect and decide directly or delegate a
|
|
325
325
|
bounded review to a native subagent or ordinary Worker. When a managed
|
|
326
|
-
ReviewRound is explicitly
|
|
327
|
-
write-capable `reviewer` Profile
|
|
328
|
-
|
|
326
|
+
ReviewRound is explicitly requested, its reviewer uses the single built-in
|
|
327
|
+
write-capable `reviewer` Profile. Each Task Reviewer Role keeps one stable,
|
|
328
|
+
isolated Session and physical workspace slot; every ReviewRound updates that
|
|
329
|
+
slot to its exact frozen scope and records a new immutable ownership snapshot:
|
|
329
330
|
the assigned WorkItem Candidate or the committed Integration heads of a
|
|
330
331
|
Task-final Review. Never reuse the Candidate/Worker workspace or its
|
|
331
|
-
implementation Role Session.
|
|
332
|
+
implementation Role Session. Multiple Reviewer Roles use independent slots
|
|
333
|
+
and may run in parallel. Codex and Claude may use their normal configured
|
|
332
334
|
full capability in that isolated worktree; the behavioral boundary forbids
|
|
333
335
|
push, Integration, Task mutation, other workspaces, stable checkouts, and the
|
|
334
336
|
real Yui control-plane home. When
|
|
@@ -526,8 +528,8 @@ authorized expansions.
|
|
|
526
528
|
bounded evidence-gathering review to a native subagent or ordinary Worker,
|
|
527
529
|
then make the Leader-owned accept/reject decision. Do not create a Reviewer
|
|
528
530
|
Role merely to satisfy an old setup convention.
|
|
529
|
-
- `always`:
|
|
530
|
-
terminal.
|
|
531
|
+
- `always`: keep the Candidate decision pending until its required ReviewRound
|
|
532
|
+
is terminal. The Review does not globally pause unrelated Leader work.
|
|
531
533
|
- `leader`: decide whether the existing evidence is sufficient. Request Agent
|
|
532
534
|
review with `yui task work review <work-id>` when it adds useful evidence.
|
|
533
535
|
- `final`: keep WorkItem acceptance and integration independent. After all
|
|
@@ -535,10 +537,39 @@ authorized expansions.
|
|
|
535
537
|
Task-final ReviewRound over the frozen Task candidate. A Task contract may
|
|
536
538
|
require it. The final Reviewer evaluates the complete result across bound
|
|
537
539
|
Projects; it is not a second per-WorkItem approval protocol.
|
|
538
|
-
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
540
|
+
- Before choosing a Task-final Review action, read `task context` or
|
|
541
|
+
`task next-action` and inspect every active AgentRun's purpose and exact
|
|
542
|
+
WorkItem/ReviewRound binding, the current durable heads, active Reviews,
|
|
543
|
+
each Reviewer's availability, the latest accepted baseline, candidate
|
|
544
|
+
relation, and Delta facts. These are decision support, not an autopilot;
|
|
545
|
+
a Review Run is evidence in progress, not a global Task lock.
|
|
546
|
+
- A changed Task head may justify a new semantic Task-final Round. Reuse the
|
|
547
|
+
same Reviewer Role Session and stable workspace; Round id, full versus Delta
|
|
548
|
+
mode, desired revision, and frozen commit do not require a replacement
|
|
549
|
+
Session. Round identity still binds each Run to the exact frozen head.
|
|
550
|
+
- An active Task-final Review freezes candidate A only. Continue handling new
|
|
551
|
+
user input and, when appropriate, advance candidate B. Always consume A's
|
|
552
|
+
result, then route it as exact evidence for A, a baseline for descendant B,
|
|
553
|
+
or historical evidence for a diverged candidate. Do not cancel or discard A
|
|
554
|
+
merely because Task main moved.
|
|
555
|
+
- Read active Review facts directly from its ReviewRound: frozen Project
|
|
556
|
+
commits define that Review's evidence boundary; current candidate relation,
|
|
557
|
+
active Run, and workspace references describe current execution. Do not infer
|
|
558
|
+
a Task lock or wait for a synthetic freeze lifecycle before advancing Task
|
|
559
|
+
main.
|
|
560
|
+
- If Yui reports a Reviewer `busy`, wait for the suggested interval, select a
|
|
561
|
+
different Reviewer, review directly, or continue other work. Busy is a
|
|
562
|
+
scheduling fact, not a failed Review and not a reason to reset the Session.
|
|
563
|
+
- Prefer Delta Recheck for a technically available, contiguous change over an
|
|
564
|
+
accepted baseline when the semantic risk is bounded. Use the exact changed
|
|
565
|
+
files, line counts, diff, previous evidence, Task intent, and Project Policy
|
|
566
|
+
to choose full Review, Delta, direct Review, another Reviewer, or no Review;
|
|
567
|
+
Yui does not choose the mode from generic thresholds.
|
|
568
|
+
- Delta `requires-full-review` returns control to the Leader. Decide whether a
|
|
569
|
+
full Review, another Reviewer, direct inspection, or more development is
|
|
570
|
+
useful; Yui must not auto-create the next Round. `repeated-full-review` is a
|
|
571
|
+
cost advisory for an unchanged candidate/Reviewer intent, never an exhausted
|
|
572
|
+
budget or a prohibition on new evidence.
|
|
542
573
|
- A completed review is advice. Decide whether to accept, reject, review again,
|
|
543
574
|
or ask the user.
|
|
544
575
|
- Route a reachable final-Review finding to the original Worker while that
|
|
@@ -563,11 +594,16 @@ authorized expansions.
|
|
|
563
594
|
full Round over the identical frozen heads. It fails closed for every
|
|
564
595
|
semantic or ambiguous prior result; target the new failed Round explicitly
|
|
565
596
|
if another non-semantic failure occurs.
|
|
597
|
+
- For `review.failed-to-start`, open the referenced ReviewRound and inspect its
|
|
598
|
+
exact reason, frozen candidate, and workspace when present. Decide whether to
|
|
599
|
+
retry, explicitly clean a conflicting workspace, select another Reviewer, or
|
|
600
|
+
continue other work. Preserve the failed Round as request history and do not
|
|
601
|
+
turn these choices into an automatic retry or cleanup loop.
|
|
566
602
|
- Use `task next-action`'s derived Review outcome literally: non-semantic means
|
|
567
603
|
recover the same frozen head with `force-fresh`; ambiguous means diagnose the
|
|
568
604
|
inconsistent evidence without creating a Repair WorkItem; only semantic
|
|
569
|
-
negative evidence may create a repair wave.
|
|
570
|
-
|
|
605
|
+
negative evidence may create a repair wave. There is no semantic Review
|
|
606
|
+
budget; exact candidate/Reviewer/intent retries reuse existing evidence.
|
|
571
607
|
- If the same non-resource user choice or unavailable external fact repeats,
|
|
572
608
|
persist context and create an InputRequest instead of looping. Never use an
|
|
573
609
|
InputRequest to solicit authorization for an unrequested real-resource test;
|
|
@@ -612,10 +648,11 @@ accept an isolated result while any writable Project's latest ChangeSet is
|
|
|
612
648
|
unintegrated.
|
|
613
649
|
|
|
614
650
|
Workspace ownership is not Role ownership. The WorkItem owns its Develop
|
|
615
|
-
workspace even when a Task Role executes there;
|
|
616
|
-
|
|
617
|
-
its
|
|
618
|
-
|
|
651
|
+
workspace even when a Task Role executes there; a Task Reviewer Role keeps one
|
|
652
|
+
stable physical workspace while each ReviewRound owns the exact frozen
|
|
653
|
+
workspace evidence for its Run, and each IntegrationAttempt owns its candidate
|
|
654
|
+
worktree. Dispatch attaches snapshots only. Review workspace cleanup is
|
|
655
|
+
explicit, and review edits can never feed WorkItem ChangeSet capture.
|
|
619
656
|
|
|
620
657
|
Yui validates a candidate and advances the target with compare-and-swap. A
|
|
621
658
|
failed candidate does not advance the target. Inspect and resolve semantic
|
|
@@ -46,6 +46,15 @@ mind and avoid imposing a fixed heading, field, section, or character
|
|
|
46
46
|
template; one semantic event should have one concise summary unless a later
|
|
47
47
|
role adds a genuinely new decision or impact.
|
|
48
48
|
|
|
49
|
+
A `[Yui updates]` user message is only a wake envelope containing durable
|
|
50
|
+
InputRequest or TaskEvent references. Read those exact records through `yui`
|
|
51
|
+
before responding, merge related references into one user-level update, and
|
|
52
|
+
then end the turn normally. Never create or keep a Codex Goal, automatic
|
|
53
|
+
self-continuation, polling loop, or private follow-up task merely to monitor
|
|
54
|
+
Yui work. Future durable updates will wake the Operator with another user
|
|
55
|
+
message after the current Operator turn is ready; unchanged state needs no
|
|
56
|
+
response.
|
|
57
|
+
|
|
49
58
|
## Configure Yui through conversation
|
|
50
59
|
|
|
51
60
|
Treat configuration as an Operator-owned conversation, not a list of commands
|
|
@@ -18,13 +18,18 @@ reinterpret its scope:
|
|
|
18
18
|
anchor.
|
|
19
19
|
|
|
20
20
|
A Role is an executor, not a workspace owner: each ReviewRound owns an exact
|
|
21
|
-
workspace record. Consecutive Task-final Rounds for the same Reviewer
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
when the conversation continues; never reuse an earlier
|
|
25
|
-
are confined to that workspace, never modify the
|
|
21
|
+
workspace record. Consecutive Task-final Rounds for the same Reviewer reuse one
|
|
22
|
+
clean physical workspace and native Session while Yui updates the checkout and
|
|
23
|
+
records the new Round snapshot. Treat the new Run Context Pack and frozen head
|
|
24
|
+
as the authority even when the conversation continues; never reuse an earlier
|
|
25
|
+
verdict. Review edits are confined to that workspace, never modify the
|
|
26
26
|
WorkItem Develop workspace, and never become a ChangeSet source.
|
|
27
27
|
|
|
28
|
+
For a dispatched Review, the Run Context Pack identifies the ReviewRound,
|
|
29
|
+
frozen Project commits, and assigned workspace. Inspect those exact commits.
|
|
30
|
+
The current mutable Task-main checkout is context only and must never replace,
|
|
31
|
+
widen, or silently update the assigned Review scope.
|
|
32
|
+
|
|
28
33
|
## Separate infrastructure failure from review judgment
|
|
29
34
|
|
|
30
35
|
Verify the exact Run identity, Context Pack, frozen head, and ReviewRound-owned
|
|
@@ -44,10 +49,26 @@ binding fails before review begins:
|
|
|
44
49
|
|
|
45
50
|
Yui derives `semantic`, `non-semantic`, or `ambiguous` from the immutable
|
|
46
51
|
Round, Run receipt, completion Event, and finding evidence. Never write or
|
|
47
|
-
simulate a classification field. A non-semantic attempt
|
|
48
|
-
|
|
52
|
+
simulate a classification field. A non-semantic attempt cannot satisfy
|
|
53
|
+
acceptance; an ambiguous attempt requires
|
|
49
54
|
Leader diagnosis before another review or repair decision.
|
|
50
55
|
|
|
56
|
+
The Review scope remains the current Run's frozen candidate even if the Leader
|
|
57
|
+
handles new user input or advances Task main while this Review is running. Do
|
|
58
|
+
not switch to the newer head, cancel the current inspection, or claim the
|
|
59
|
+
result covers anything beyond the frozen candidate.
|
|
60
|
+
|
|
61
|
+
For a Delta Recheck, judge only the verified baseline plus the exact supplied
|
|
62
|
+
diff. Return exactly one explicit disposition with reasoning:
|
|
63
|
+
|
|
64
|
+
- `equivalent-and-accepted` when the new candidate preserves the accepted
|
|
65
|
+
semantics and evidence;
|
|
66
|
+
- `finding` for a reachable material defect;
|
|
67
|
+
- `requires-full-review` when equivalence cannot be established.
|
|
68
|
+
|
|
69
|
+
Never create or request a follow-up Round yourself: `requires-full-review`, a
|
|
70
|
+
finding, and every uncertainty return to the Leader for routing.
|
|
71
|
+
|
|
51
72
|
Keep the context layers distinct. Yui Core owns ReviewRound identity,
|
|
52
73
|
lifecycle, access, workspace, and exact-yield safety; this generic Skill owns
|
|
53
74
|
portable review behavior; Agent-native Project Skills and Project Policy and
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { resolveContextBudget } from "../config/yuiConfig.js";
|
|
2
|
-
import { runtimeObservationFromTaskEvent } from "../runtime/runtimeObservation.js";
|
|
3
|
-
export function evaluateSessionContextBudget(events, session, configured) {
|
|
4
|
-
const budget = resolveContextBudget(configured);
|
|
5
|
-
const peak = observedPeakInputTokens(events, session);
|
|
6
|
-
const state = peak >= budget.hardTokens
|
|
7
|
-
? "hard"
|
|
8
|
-
: peak >= budget.softTokens
|
|
9
|
-
? "soft"
|
|
10
|
-
: "within";
|
|
11
|
-
return Object.freeze({ state, peakTokens: peak, budget });
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Largest per-request input peak observed for one Session generation. Usage
|
|
15
|
-
* observations carry cumulative session totals; consecutive deltas bound the
|
|
16
|
-
* per-request input of the window between them. The first observation for a
|
|
17
|
-
* generation is treated as one full request so a long-lived resumed Session
|
|
18
|
-
* that was only sampled late still counts its inherited context.
|
|
19
|
-
*/
|
|
20
|
-
export function observedPeakInputTokens(events, session) {
|
|
21
|
-
let previous = 0;
|
|
22
|
-
let peak = 0;
|
|
23
|
-
for (const event of events) {
|
|
24
|
-
const observation = runtimeObservationFromTaskEvent(event);
|
|
25
|
-
if (observation === null)
|
|
26
|
-
continue;
|
|
27
|
-
if (!matchesSession(observation.fence, session))
|
|
28
|
-
continue;
|
|
29
|
-
const usage = usageTotal(observation.payload.usage);
|
|
30
|
-
if (usage === null)
|
|
31
|
-
continue;
|
|
32
|
-
const delta = Math.max(0, usage - previous);
|
|
33
|
-
if (delta > peak)
|
|
34
|
-
peak = delta;
|
|
35
|
-
previous = usage;
|
|
36
|
-
}
|
|
37
|
-
return peak;
|
|
38
|
-
}
|
|
39
|
-
function matchesSession(fence, session) {
|
|
40
|
-
if (fence.taskId !== undefined && fence.taskId !== session.taskId)
|
|
41
|
-
return false;
|
|
42
|
-
if (fence.roleName !== session.roleName)
|
|
43
|
-
return false;
|
|
44
|
-
if (session.nativeSessionId !== undefined
|
|
45
|
-
&& fence.nativeSessionId !== undefined
|
|
46
|
-
&& fence.nativeSessionId !== session.nativeSessionId) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
if (session.launchId !== undefined
|
|
50
|
-
&& fence.launchId !== undefined
|
|
51
|
-
&& fence.launchId !== session.launchId) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
function usageTotal(usage) {
|
|
57
|
-
if (typeof usage !== "object" || usage === null || Array.isArray(usage))
|
|
58
|
-
return null;
|
|
59
|
-
const record = usage;
|
|
60
|
-
const inputTokens = integer(record.inputTokens);
|
|
61
|
-
if (inputTokens === null)
|
|
62
|
-
return null;
|
|
63
|
-
// RuntimeUsageSnapshot.inputTokens is the normalized processed input total.
|
|
64
|
-
// cachedInputTokens is an informational breakdown of that total, matching
|
|
65
|
-
// runtimeProjection and the Driver documentation; adding it again would
|
|
66
|
-
// fabricate context pressure and trigger premature Session rollover.
|
|
67
|
-
return inputTokens;
|
|
68
|
-
}
|
|
69
|
-
function integer(value) {
|
|
70
|
-
return Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
71
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { enqueueWork } from "../coordination/workMailboxQueue.js";
|
|
2
|
-
import { validateRoleSessionSet } from "../executor/agentExecutor.js";
|
|
3
|
-
import { createTaskEvent } from "../event/taskEvent.js";
|
|
4
|
-
import { RUNTIME_CLEANUP_REQUIRED_REASON, runtimeLifecycleTarget } from "../runtime/lifecycleReservation.js";
|
|
5
|
-
/**
|
|
6
|
-
* Issue 04 (context token budget): retires one native Session generation that
|
|
7
|
-
* crossed the hard context budget so the next Leader wake starts a fresh
|
|
8
|
-
* generation. This is a controlled rollover, not a failure: the durable Task
|
|
9
|
-
* records are the checkpoint, the bounded context snapshot re-establishes
|
|
10
|
-
* working context for the new generation, and the retired Session is kept in
|
|
11
|
-
* history as `stopped` with an auditable event. The Controller separately
|
|
12
|
-
* owns verified process cleanup through the runtime cleanup lane.
|
|
13
|
-
*/
|
|
14
|
-
export const CONTEXT_BUDGET_ROLLOVER_REASON = "context-budget-hard-limit";
|
|
15
|
-
export function rolloverTaskRoleSessionForContextBudget(store, taskId, roleName, evidence, now) {
|
|
16
|
-
const task = store.getTask(taskId);
|
|
17
|
-
if (task === null)
|
|
18
|
-
throw new Error(`Task not found: ${taskId}.`);
|
|
19
|
-
if (task.status !== "active") {
|
|
20
|
-
throw new Error(`Task is not active: ${task.id}/${task.status}.`);
|
|
21
|
-
}
|
|
22
|
-
const role = store.getRole(task.id, roleName);
|
|
23
|
-
if (role === null)
|
|
24
|
-
throw new Error(`Role not found: ${task.id}/${roleName}.`);
|
|
25
|
-
const set = store.getTaskRoleSessionSet(task.id, role.name);
|
|
26
|
-
const current = set?.sessions[set.activeAgentId];
|
|
27
|
-
if (set === null || set === undefined || current === undefined) {
|
|
28
|
-
// No live generation to retire; the caller can launch fresh directly.
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const timestamp = now.toISOString();
|
|
32
|
-
const reason = `${CONTEXT_BUDGET_ROLLOVER_REASON} (peak ${evidence.peakTokens} >= hard ${evidence.hardTokens} tokens)`;
|
|
33
|
-
enqueueWork(store, runtimeLifecycleTarget({ scope: "task", taskId: task.id, roleName: role.name }), RUNTIME_CLEANUP_REQUIRED_REASON, now, [{ type: "task", id: task.id }]);
|
|
34
|
-
const retired = retireStoppedTaskRoleSession(set, timestamp);
|
|
35
|
-
store.saveTaskRoleSessionSet(retired);
|
|
36
|
-
const eventId = store.nextEventId(task.id);
|
|
37
|
-
store.saveEvent(task.id, createTaskEvent(eventId, task.id, "runtime.role-session-reset", {
|
|
38
|
-
roleName: role.name,
|
|
39
|
-
reason,
|
|
40
|
-
peakTokens: String(evidence.peakTokens),
|
|
41
|
-
hardTokens: String(evidence.hardTokens),
|
|
42
|
-
...(current.nativeSessionId === undefined
|
|
43
|
-
? {}
|
|
44
|
-
: { nativeSessionId: current.nativeSessionId }),
|
|
45
|
-
...(current.launchId === undefined ? {} : { launchId: current.launchId })
|
|
46
|
-
}, now));
|
|
47
|
-
return Object.freeze({
|
|
48
|
-
taskId: task.id,
|
|
49
|
-
roleName: role.name,
|
|
50
|
-
eventId,
|
|
51
|
-
...(current.nativeSessionId === undefined
|
|
52
|
-
? {}
|
|
53
|
-
: { retiredNativeSessionId: current.nativeSessionId }),
|
|
54
|
-
...(current.launchId === undefined ? {} : { retiredLaunchId: current.launchId })
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Retires the current generation to history as `stopped` (not `broken`:
|
|
59
|
-
* a budget rollover is not a Session failure) and clears the Turn fence so
|
|
60
|
-
* the next launch is a fresh generation.
|
|
61
|
-
*/
|
|
62
|
-
function retireStoppedTaskRoleSession(set, timestamp) {
|
|
63
|
-
validateRoleSessionSet(set);
|
|
64
|
-
const current = set.sessions[set.activeAgentId];
|
|
65
|
-
const sessions = { ...set.sessions };
|
|
66
|
-
delete sessions[set.activeAgentId];
|
|
67
|
-
const history = current === undefined
|
|
68
|
-
? set.history
|
|
69
|
-
: [
|
|
70
|
-
...(set.history ?? []),
|
|
71
|
-
{ ...current, status: "stopped", updatedAt: timestamp }
|
|
72
|
-
];
|
|
73
|
-
return validateRoleSessionSet({
|
|
74
|
-
...set,
|
|
75
|
-
sessions,
|
|
76
|
-
...(history === undefined ? {} : { history }),
|
|
77
|
-
inFlight: null,
|
|
78
|
-
providerBinding: null,
|
|
79
|
-
updatedAt: timestamp
|
|
80
|
-
});
|
|
81
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export const CURRENT_OPERATOR_NOTIFICATION_SCHEMA_VERSION = 1;
|
|
2
|
-
export function createLeaderRecoveryNotification(taskId, message, now, existing) {
|
|
3
|
-
const timestamp = now.toISOString();
|
|
4
|
-
return {
|
|
5
|
-
schemaVersion: CURRENT_OPERATOR_NOTIFICATION_SCHEMA_VERSION,
|
|
6
|
-
taskId: requiredText(taskId, "Task id"),
|
|
7
|
-
type: "leader-recovery-failed",
|
|
8
|
-
message: requiredText(message, "Operator notification message"),
|
|
9
|
-
createdAt: existing?.type === "leader-recovery-failed"
|
|
10
|
-
? existing.createdAt
|
|
11
|
-
: timestamp,
|
|
12
|
-
updatedAt: timestamp
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function createTaskTerminalNotification(taskId, status, by, summary, now) {
|
|
16
|
-
const timestamp = now.toISOString();
|
|
17
|
-
return {
|
|
18
|
-
schemaVersion: CURRENT_OPERATOR_NOTIFICATION_SCHEMA_VERSION,
|
|
19
|
-
taskId: requiredText(taskId, "Task id"),
|
|
20
|
-
type: "task-terminal",
|
|
21
|
-
status,
|
|
22
|
-
by,
|
|
23
|
-
summary: requiredText(summary, "Task terminal summary"),
|
|
24
|
-
createdAt: timestamp,
|
|
25
|
-
updatedAt: timestamp
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export function createLeaderStallNotification(taskId, runId, progressAt, evidenceKey, now, existing) {
|
|
29
|
-
const timestamp = now.toISOString();
|
|
30
|
-
const previous = existing?.type === "leader-stalled"
|
|
31
|
-
&& existing.runId === runId
|
|
32
|
-
&& existing.progressAt === progressAt
|
|
33
|
-
? existing
|
|
34
|
-
: undefined;
|
|
35
|
-
return {
|
|
36
|
-
schemaVersion: CURRENT_OPERATOR_NOTIFICATION_SCHEMA_VERSION,
|
|
37
|
-
taskId: requiredText(taskId, "Task id"),
|
|
38
|
-
type: "leader-stalled",
|
|
39
|
-
message: requiredText([
|
|
40
|
-
`Leader Run ${runId} is truly stalled for Task ${taskId}.`,
|
|
41
|
-
`lastProgressAt=${progressAt}`,
|
|
42
|
-
`classification=truly-stalled`,
|
|
43
|
-
`evidence=${evidenceKey}`,
|
|
44
|
-
"Inspect the Task context and decide whether to continue, reset, retry, change Agent, or request user input; Controller performed no automatic action."
|
|
45
|
-
].join(" "), "Operator notification message"),
|
|
46
|
-
runId: requiredText(runId, "Leader Run id"),
|
|
47
|
-
progressAt: requiredText(progressAt, "Leader progress timestamp"),
|
|
48
|
-
classification: "truly-stalled",
|
|
49
|
-
evidenceKey: requiredText(evidenceKey, "Leader stall evidence"),
|
|
50
|
-
createdAt: previous?.createdAt ?? timestamp,
|
|
51
|
-
updatedAt: timestamp
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function requiredText(value, label) {
|
|
55
|
-
const normalized = value.trim();
|
|
56
|
-
if (normalized.length === 0)
|
|
57
|
-
throw new Error(`${label} is required.`);
|
|
58
|
-
return normalized;
|
|
59
|
-
}
|