@leuduan/lagent 0.0.0-stage → 0.1.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/LICENSE +16 -0
- package/README.md +144 -2
- package/dist/chunks/2O7ZGEIT.js +1 -0
- package/dist/chunks/2OSESBIL.js +1 -0
- package/dist/chunks/34KW6VNQ.js +1 -0
- package/dist/chunks/37YOGDGY.js +1 -0
- package/dist/chunks/3LQHQRIU.js +6 -0
- package/dist/chunks/3QCW4WDJ.js +1 -0
- package/dist/chunks/4XVRUSCQ.js +1 -0
- package/dist/chunks/6ECI2GGV.js +1 -0
- package/dist/chunks/74HKUGRR.js +1 -0
- package/dist/chunks/ADHERZLW.js +2 -0
- package/dist/chunks/AP6Q4EPT.js +36 -0
- package/dist/chunks/BM3S37EZ.js +1 -0
- package/dist/chunks/C5LYCXJG.js +1 -0
- package/dist/chunks/CDQG7RKA.js +1 -0
- package/dist/chunks/D7E6EWIE.js +3 -0
- package/dist/chunks/DDANMY45.js +3 -0
- package/dist/chunks/DRYAN665.js +1 -0
- package/dist/chunks/DXFXAYDN.js +17 -0
- package/dist/chunks/EGZI4XQX.js +24 -0
- package/dist/chunks/ENWFSU27.js +41 -0
- package/dist/chunks/G6RXC3AL.js +1 -0
- package/dist/chunks/G74AGRAJ.js +15 -0
- package/dist/chunks/GQGNVSKB.js +1 -0
- package/dist/chunks/IJ2WNMD5.js +7 -0
- package/dist/chunks/J5S4URAW.js +1 -0
- package/dist/chunks/JPZFKSWT.js +1 -0
- package/dist/chunks/KESCTXGO.js +5 -0
- package/dist/chunks/L3N4FIEN.js +1 -0
- package/dist/chunks/NAOUTU7A.js +4 -0
- package/dist/chunks/NDIM7MEW.js +1 -0
- package/dist/chunks/O4PPOM5Z.js +2 -0
- package/dist/chunks/OVZFGILJ.js +1 -0
- package/dist/chunks/P5ZHHOOM.js +6 -0
- package/dist/chunks/PUSUPTAT.js +1 -0
- package/dist/chunks/QMMLQJBS.js +1 -0
- package/dist/chunks/RK3VP2Q4.js +3 -0
- package/dist/chunks/SGGMBSBA.js +1 -0
- package/dist/chunks/SL2YLB2F.js +1 -0
- package/dist/chunks/TOOIB6J2.js +1 -0
- package/dist/chunks/TYTQRLTX.js +1 -0
- package/dist/chunks/UC3FVVJ2.js +5 -0
- package/dist/chunks/UCTEU62F.js +1 -0
- package/dist/chunks/UD3VJER6.js +1 -0
- package/dist/chunks/UKXMCHHT.js +1 -0
- package/dist/chunks/WUUKTSRT.js +7 -0
- package/dist/chunks/X65X4KP5.js +7 -0
- package/dist/chunks/YIR5MYGU.js +1 -0
- package/dist/chunks/YLNJXQ3Z.js +1 -0
- package/dist/context.d.ts +101 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +77 -0
- package/dist/journal/catalog.d.ts +112 -0
- package/dist/journal/forkChain.d.ts +16 -0
- package/dist/journal/index.d.ts +15 -0
- package/dist/journal/journal.d.ts +475 -0
- package/dist/journal/projection.d.ts +87 -0
- package/dist/journal/store.d.ts +181 -0
- package/dist/kit/claim.d.ts +13 -0
- package/dist/kit/drain.d.ts +10 -0
- package/dist/kit/extension.d.ts +180 -0
- package/dist/kit/grants.d.ts +9 -0
- package/dist/kit/modes.d.ts +65 -0
- package/dist/kit/retries.d.ts +25 -0
- package/dist/kit/scope.d.ts +32 -0
- package/dist/kit/service.d.ts +7 -0
- package/dist/kit/strategy.d.ts +10 -0
- package/dist/kit/timers.d.ts +43 -0
- package/dist/kit/tool.d.ts +72 -0
- package/dist/llm/client.d.ts +135 -0
- package/dist/llm/content.d.ts +52 -0
- package/dist/llm/door.d.ts +21 -0
- package/dist/llm/door.js +1 -0
- package/dist/llm/failure.d.ts +82 -0
- package/dist/llm/index.d.ts +16 -0
- package/dist/llm/primitives.d.ts +286 -0
- package/dist/llm/prompt.d.ts +21 -0
- package/dist/llm/provider.d.ts +63 -0
- package/dist/llm/readLedger.d.ts +24 -0
- package/dist/llm/request.d.ts +58 -0
- package/dist/loop/agent.d.ts +134 -0
- package/dist/loop/auxiliary.d.ts +54 -0
- package/dist/loop/chain.d.ts +46 -0
- package/dist/loop/chunks.d.ts +27 -0
- package/dist/loop/continuation.d.ts +166 -0
- package/dist/loop/decide.d.ts +64 -0
- package/dist/loop/errors.d.ts +162 -0
- package/dist/loop/forks.d.ts +61 -0
- package/dist/loop/holds.d.ts +104 -0
- package/dist/loop/hooks.d.ts +241 -0
- package/dist/loop/inbox.d.ts +188 -0
- package/dist/loop/index.d.ts +37 -0
- package/dist/loop/limits.d.ts +14 -0
- package/dist/loop/opening.d.ts +42 -0
- package/dist/loop/prepare.d.ts +30 -0
- package/dist/loop/projections.d.ts +307 -0
- package/dist/loop/replace.d.ts +33 -0
- package/dist/loop/requests.d.ts +129 -0
- package/dist/loop/route.d.ts +53 -0
- package/dist/loop/runtime.d.ts +85 -0
- package/dist/loop/state.d.ts +70 -0
- package/dist/loop/strategy.d.ts +71 -0
- package/dist/loop/summary.d.ts +3 -0
- package/dist/loop/surface.d.ts +153 -0
- package/dist/loop/threadState.d.ts +72 -0
- package/dist/loop/tool.d.ts +101 -0
- package/dist/loop/toolCalls.d.ts +42 -0
- package/dist/loop/wake.d.ts +32 -0
- package/dist/models/config/agent.d.ts +18 -0
- package/dist/models/config/prompt.d.ts +18 -0
- package/dist/models/door.d.ts +12 -0
- package/dist/models/door.js +1 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/jsonSchema.d.ts +7 -0
- package/dist/models/wire/journal.d.ts +2772 -0
- package/dist/models/wire/primitives.d.ts +65 -0
- package/dist/plugin.d.ts +53 -0
- package/dist/plugin.js +1 -0
- package/dist/plugins/agentsMd.d.ts +76 -0
- package/dist/plugins/agentsMd.js +1 -0
- package/dist/plugins/ask/askQuestion.d.ts +9 -0
- package/dist/plugins/ask/index.d.ts +26 -0
- package/dist/plugins/ask/index.js +1 -0
- package/dist/plugins/ask/service.d.ts +125 -0
- package/dist/plugins/commands/background.d.ts +8 -0
- package/dist/plugins/commands/foreground.d.ts +4 -0
- package/dist/plugins/commands/index.d.ts +40 -0
- package/dist/plugins/commands/index.js +1 -0
- package/dist/plugins/commands/output.d.ts +115 -0
- package/dist/plugins/commands/record.d.ts +549 -0
- package/dist/plugins/commands/service.d.ts +314 -0
- package/dist/plugins/commands/shell.d.ts +25 -0
- package/dist/plugins/compaction/checkpoint.d.ts +91 -0
- package/dist/plugins/compaction/config.d.ts +133 -0
- package/dist/plugins/compaction/estimate.d.ts +29 -0
- package/dist/plugins/compaction/index.d.ts +2 -0
- package/dist/plugins/compaction/index.js +7 -0
- package/dist/plugins/compaction/log.d.ts +61 -0
- package/dist/plugins/compaction/planner.d.ts +207 -0
- package/dist/plugins/compaction/preset.d.ts +86 -0
- package/dist/plugins/compaction/prune.d.ts +9 -0
- package/dist/plugins/compaction/records.d.ts +227 -0
- package/dist/plugins/compaction/segments.d.ts +23 -0
- package/dist/plugins/compaction/shared.d.ts +14 -0
- package/dist/plugins/compaction/summarize.d.ts +13 -0
- package/dist/plugins/dateAndBranch.d.ts +47 -0
- package/dist/plugins/dateAndBranch.js +1 -0
- package/dist/plugins/delegations/answers.d.ts +39 -0
- package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
- package/dist/plugins/delegations/cleanup.d.ts +161 -0
- package/dist/plugins/delegations/constraint.d.ts +76 -0
- package/dist/plugins/delegations/index.d.ts +39 -0
- package/dist/plugins/delegations/index.js +1 -0
- package/dist/plugins/delegations/notices.d.ts +261 -0
- package/dist/plugins/delegations/obligations.d.ts +210 -0
- package/dist/plugins/delegations/record.d.ts +632 -0
- package/dist/plugins/delegations/request.d.ts +381 -0
- package/dist/plugins/delegations/role.d.ts +30 -0
- package/dist/plugins/delegations/service.d.ts +562 -0
- package/dist/plugins/delegations/standing.d.ts +19 -0
- package/dist/plugins/delegations/stopCheck.d.ts +21 -0
- package/dist/plugins/delegations/testing.d.ts +16 -0
- package/dist/plugins/delegations/tools.d.ts +71 -0
- package/dist/plugins/delegations/waitBook.d.ts +116 -0
- package/dist/plugins/delegations/waits.d.ts +118 -0
- package/dist/plugins/diagnostics/digest.d.ts +14 -0
- package/dist/plugins/diagnostics/index.d.ts +68 -0
- package/dist/plugins/diagnostics/index.js +1 -0
- package/dist/plugins/historyRecall/history.d.ts +9 -0
- package/dist/plugins/historyRecall/index.d.ts +31 -0
- package/dist/plugins/historyRecall/index.js +1 -0
- package/dist/plugins/historyRecall/render.d.ts +34 -0
- package/dist/plugins/historyRecall/tools.d.ts +4 -0
- package/dist/plugins/mcp/catalog.d.ts +36 -0
- package/dist/plugins/mcp/config.d.ts +63 -0
- package/dist/plugins/mcp/connection.d.ts +53 -0
- package/dist/plugins/mcp/errors.d.ts +32 -0
- package/dist/plugins/mcp/index.d.ts +33 -0
- package/dist/plugins/mcp/index.js +5 -0
- package/dist/plugins/mcp/mount.d.ts +98 -0
- package/dist/plugins/mcp/names.d.ts +25 -0
- package/dist/plugins/mcp/render.d.ts +29 -0
- package/dist/plugins/mcp/slots.d.ts +15 -0
- package/dist/plugins/mcp/stdio.d.ts +49 -0
- package/dist/plugins/mcp/tool.d.ts +41 -0
- package/dist/plugins/providers/anthropic.d.ts +175 -0
- package/dist/plugins/providers/anthropicMessages.d.ts +65 -0
- package/dist/plugins/providers/codex.d.ts +60 -0
- package/dist/plugins/providers/codexAuth.d.ts +116 -0
- package/dist/plugins/providers/deepseek.d.ts +55 -0
- package/dist/plugins/providers/door.d.ts +61 -0
- package/dist/plugins/providers/door.js +1 -0
- package/dist/plugins/providers/failure.d.ts +23 -0
- package/dist/plugins/providers/gateway.d.ts +23 -0
- package/dist/plugins/providers/index.d.ts +6 -0
- package/dist/plugins/providers/openaiChat.d.ts +62 -0
- package/dist/plugins/providers/openaiResponses.d.ts +100 -0
- package/dist/plugins/providers/opencodeCopilot.d.ts +23 -0
- package/dist/plugins/providers/opencodeGo.d.ts +98 -0
- package/dist/plugins/providers/shared.d.ts +104 -0
- package/dist/plugins/providers/stream.d.ts +154 -0
- package/dist/plugins/routeContext.d.ts +22 -0
- package/dist/plugins/routeContext.js +1 -0
- package/dist/plugins/schedules/index.d.ts +21 -0
- package/dist/plugins/schedules/index.js +5 -0
- package/dist/plugins/schedules/record.d.ts +396 -0
- package/dist/plugins/schedules/service.d.ts +120 -0
- package/dist/plugins/schedules/time.d.ts +26 -0
- package/dist/plugins/schedules/tools.d.ts +6 -0
- package/dist/plugins/skills/discovery.d.ts +54 -0
- package/dist/plugins/skills/index.d.ts +31 -0
- package/dist/plugins/skills/index.js +1 -0
- package/dist/plugins/skills/tool.d.ts +11 -0
- package/dist/plugins/store/durableObject.d.ts +23 -0
- package/dist/plugins/store/durableObject.js +1 -0
- package/dist/plugins/store/durableObjectConnection.d.ts +27 -0
- package/dist/plugins/store/memory.d.ts +29 -0
- package/dist/plugins/store/sql.d.ts +59 -0
- package/dist/plugins/store/sqlite.d.ts +31 -0
- package/dist/plugins/store/sqlite.js +1 -0
- package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
- package/dist/plugins/subAgents/fork.d.ts +32 -0
- package/dist/plugins/subAgents/index.d.ts +67 -0
- package/dist/plugins/subAgents/index.js +1 -0
- package/dist/plugins/subAgents/tool.d.ts +38 -0
- package/dist/plugins/toolPolicy/index.d.ts +61 -0
- package/dist/plugins/toolPolicy/index.js +1 -0
- package/dist/plugins/tools/editFiles.d.ts +128 -0
- package/dist/plugins/tools/fsRead.d.ts +17 -0
- package/dist/plugins/tools/html.d.ts +23 -0
- package/dist/plugins/tools/index.d.ts +59 -0
- package/dist/plugins/tools/index.js +1 -0
- package/dist/plugins/tools/network.d.ts +23 -0
- package/dist/plugins/tools/ripgrep.d.ts +20 -0
- package/dist/plugins/tools/textEdit.d.ts +67 -0
- package/dist/plugins/tools/web.d.ts +32 -0
- package/dist/plugins/truncateToolOutput.d.ts +26 -0
- package/dist/plugins/truncateToolOutput.js +1 -0
- package/dist/plugins/usage/index.d.ts +24 -0
- package/dist/plugins/usage/index.js +1 -0
- package/dist/plugins/usage/tracker.d.ts +34 -0
- package/dist/plugins/verify/facts.d.ts +356 -0
- package/dist/plugins/verify/index.d.ts +75 -0
- package/dist/plugins/verify/index.js +1 -0
- package/dist/plugins/verify/service.d.ts +90 -0
- package/dist/plugins/workflows/assignment.d.ts +16 -0
- package/dist/plugins/workflows/bindings.d.ts +95 -0
- package/dist/plugins/workflows/cleanup.d.ts +38 -0
- package/dist/plugins/workflows/definition.d.ts +184 -0
- package/dist/plugins/workflows/fold.d.ts +373 -0
- package/dist/plugins/workflows/index.d.ts +28 -0
- package/dist/plugins/workflows/index.js +6 -0
- package/dist/plugins/workflows/observations.d.ts +81 -0
- package/dist/plugins/workflows/participants.d.ts +143 -0
- package/dist/plugins/workflows/policy.d.ts +112 -0
- package/dist/plugins/workflows/providers.d.ts +146 -0
- package/dist/plugins/workflows/record.d.ts +2863 -0
- package/dist/plugins/workflows/routing.d.ts +116 -0
- package/dist/plugins/workflows/schema.d.ts +26 -0
- package/dist/plugins/workflows/service.d.ts +477 -0
- package/dist/plugins/workflows/submit.d.ts +8 -0
- package/dist/plugins/workflows/view.d.ts +103 -0
- package/dist/plugins/workflows/work.d.ts +21 -0
- package/dist/plugins/workspaceContext.d.ts +38 -0
- package/dist/plugins/workspaceContext.js +1 -0
- package/dist/presets/agents.d.ts +7 -0
- package/dist/presets/base.d.ts +10 -0
- package/dist/presets/codex.d.ts +60 -0
- package/dist/presets/index.d.ts +4 -0
- package/dist/presets/prompts.d.ts +56 -0
- package/dist/sandbox/absent.d.ts +32 -0
- package/dist/sandbox/client.d.ts +39 -0
- package/dist/sandbox/files.d.ts +28 -0
- package/dist/sandbox/index.d.ts +49 -0
- package/dist/sandbox/index.js +4 -0
- package/dist/sandbox/mode.d.ts +57 -0
- package/dist/sandbox/policy.d.ts +86 -0
- package/dist/sandbox/protocol.d.ts +107 -0
- package/dist/sandbox/service.d.ts +143 -0
- package/dist/sandbox/worker.d.ts +12 -0
- package/dist/sandbox/worker.js +1 -0
- package/dist/services/admission.d.ts +174 -0
- package/dist/services/agents.d.ts +37 -0
- package/dist/services/birth.d.ts +220 -0
- package/dist/services/contributions.d.ts +73 -0
- package/dist/services/core.d.ts +34 -0
- package/dist/services/journal.d.ts +26 -0
- package/dist/services/launches.d.ts +104 -0
- package/dist/services/llm.d.ts +80 -0
- package/dist/services/owner.d.ts +367 -0
- package/dist/services/preset.d.ts +154 -0
- package/dist/services/presets.d.ts +139 -0
- package/dist/services/prompts.d.ts +67 -0
- package/dist/services/runEvents.d.ts +79 -0
- package/dist/services/thread.d.ts +267 -0
- package/dist/services/threadActivation.d.ts +100 -0
- package/dist/services/threadDirs.d.ts +38 -0
- package/dist/services/threadView.d.ts +92 -0
- package/dist/services/threads.d.ts +449 -0
- package/dist/services/tools.d.ts +41 -0
- package/dist/sys/environment.d.ts +47 -0
- package/dist/sys/git.d.ts +60 -0
- package/dist/sys/paths.d.ts +56 -0
- package/dist/sys/spawn.d.ts +176 -0
- package/dist/testing/clock.d.ts +17 -0
- package/dist/testing/fakeLlm.d.ts +74 -0
- package/dist/testing/fedLlm.d.ts +32 -0
- package/dist/testing/helpers.d.ts +344 -0
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/processes.d.ts +13 -0
- package/dist/testing/sandbox.d.ts +71 -0
- package/dist/testing/settlement.d.ts +6 -0
- package/dist/testing/tmpDirs.d.ts +17 -0
- package/dist/util/async.d.ts +8 -0
- package/dist/util/diff.d.ts +25 -0
- package/dist/util/dispatch.d.ts +8 -0
- package/dist/util/errors.d.ts +28 -0
- package/dist/util/foldState.d.ts +17 -0
- package/dist/util/freeze.d.ts +2 -0
- package/dist/util/ids.d.ts +2 -0
- package/dist/util/json.d.ts +37 -0
- package/dist/util/log.d.ts +6 -0
- package/dist/util/text.d.ts +21 -0
- package/dist/util/version.d.ts +2 -0
- package/package.json +175 -3
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The plugin that writes compaction's stand-ins, whichever strategy wrote them, as their `source` names it. */
|
|
3
|
+
export declare const COMPACTION_PLUGIN = "lagent:compaction";
|
|
4
|
+
/**
|
|
5
|
+
* The `source` of every checkpoint the `summarize` strategy records: what it planned, so a reader
|
|
6
|
+
* of the row can tell how much room the summary had and whether the plan reached its target.
|
|
7
|
+
*/
|
|
8
|
+
export declare const checkpointRecord: {
|
|
9
|
+
record: (value: {
|
|
10
|
+
summary_cap: number;
|
|
11
|
+
target_reached: boolean | null;
|
|
12
|
+
}) => import("../../models/index.js").ExtensionRecord;
|
|
13
|
+
parse: (value: {
|
|
14
|
+
summary_cap: number;
|
|
15
|
+
target_reached: boolean | null;
|
|
16
|
+
}) => {
|
|
17
|
+
summary_cap: number;
|
|
18
|
+
target_reached: boolean | null;
|
|
19
|
+
};
|
|
20
|
+
entry: (value: {
|
|
21
|
+
summary_cap: number;
|
|
22
|
+
target_reached: boolean | null;
|
|
23
|
+
}, options: import("../../plugin.js").AppendOptions) => {
|
|
24
|
+
type: "ext";
|
|
25
|
+
data: {
|
|
26
|
+
plugin: string;
|
|
27
|
+
instance_id: string;
|
|
28
|
+
kind: string;
|
|
29
|
+
version: number;
|
|
30
|
+
data: z.core.util.JSONType;
|
|
31
|
+
};
|
|
32
|
+
options: import("../../plugin.js").AppendOptions;
|
|
33
|
+
};
|
|
34
|
+
append(journal: import("../../plugin.js").PluginJournal, value: {
|
|
35
|
+
summary_cap: number;
|
|
36
|
+
target_reached: boolean | null;
|
|
37
|
+
}, options: import("../../plugin.js").AppendOptions): Promise<import("../../models/index.js").JournalEvent<"ext">>;
|
|
38
|
+
read(event: import("../../models/index.js").JournalEvent): {
|
|
39
|
+
summary_cap: number;
|
|
40
|
+
target_reached: boolean | null;
|
|
41
|
+
} | undefined;
|
|
42
|
+
contribution(message: {
|
|
43
|
+
role?: import("../../models/index.js").InputRole;
|
|
44
|
+
content: string | readonly import("../../llm/content.js").ContentPartInput[];
|
|
45
|
+
}, value: {
|
|
46
|
+
summary_cap: number;
|
|
47
|
+
target_reached: boolean | null;
|
|
48
|
+
}, options?: {
|
|
49
|
+
sourceSeqs?: readonly import("../../models/index.js").Seq[];
|
|
50
|
+
}): import("../../models/index.js").StepContribution;
|
|
51
|
+
matchesSource(record: import("../../util/json.js").DeepReadonly<import("../../models/index.js").ExtensionRecord>): boolean;
|
|
52
|
+
rejection(reason: string, value: {
|
|
53
|
+
summary_cap: number;
|
|
54
|
+
target_reached: boolean | null;
|
|
55
|
+
}): {
|
|
56
|
+
decision: "reject";
|
|
57
|
+
reason: string;
|
|
58
|
+
source: import("../../models/index.js").ExtensionRecord;
|
|
59
|
+
};
|
|
60
|
+
readContribution: (event: import("../../models/index.js").JournalEvent) => {
|
|
61
|
+
summary_cap: number;
|
|
62
|
+
target_reached: boolean | null;
|
|
63
|
+
} | undefined;
|
|
64
|
+
readSource: (source: import("../../util/json.js").DeepReadonly<import("../../models/index.js").ExtensionRecord> | null) => {
|
|
65
|
+
summary_cap: number;
|
|
66
|
+
target_reached: boolean | null;
|
|
67
|
+
} | undefined;
|
|
68
|
+
told: import("../../plugin.js").PluginProjection<import("../../kit/extension.js").ToldNotices<{
|
|
69
|
+
summary_cap: number;
|
|
70
|
+
target_reached: boolean | null;
|
|
71
|
+
}>>;
|
|
72
|
+
projection<State>(fold: {
|
|
73
|
+
key: string;
|
|
74
|
+
init(): State;
|
|
75
|
+
apply(state: State, value: {
|
|
76
|
+
summary_cap: number;
|
|
77
|
+
target_reached: boolean | null;
|
|
78
|
+
}, event: import("../../models/index.js").JournalEvent<"ext">): State;
|
|
79
|
+
onFork?: "inherit" | "reset";
|
|
80
|
+
}): import("../../plugin.js").PluginProjection<State>;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The `source` of every stand-in the `prune` strategy records: what the result it replaced held,
|
|
84
|
+
* its text in characters and its attachments (image and file parts), which the stand-in drops with
|
|
85
|
+
* the text.
|
|
86
|
+
*/
|
|
87
|
+
export declare const pruneRecord: {
|
|
88
|
+
record: (value: {
|
|
89
|
+
chars: number;
|
|
90
|
+
attachments: number;
|
|
91
|
+
}) => import("../../models/index.js").ExtensionRecord;
|
|
92
|
+
parse: (value: {
|
|
93
|
+
chars: number;
|
|
94
|
+
attachments: number;
|
|
95
|
+
}) => {
|
|
96
|
+
chars: number;
|
|
97
|
+
attachments: number;
|
|
98
|
+
};
|
|
99
|
+
entry: (value: {
|
|
100
|
+
chars: number;
|
|
101
|
+
attachments: number;
|
|
102
|
+
}, options: import("../../plugin.js").AppendOptions) => {
|
|
103
|
+
type: "ext";
|
|
104
|
+
data: {
|
|
105
|
+
plugin: string;
|
|
106
|
+
instance_id: string;
|
|
107
|
+
kind: string;
|
|
108
|
+
version: number;
|
|
109
|
+
data: z.core.util.JSONType;
|
|
110
|
+
};
|
|
111
|
+
options: import("../../plugin.js").AppendOptions;
|
|
112
|
+
};
|
|
113
|
+
append(journal: import("../../plugin.js").PluginJournal, value: {
|
|
114
|
+
chars: number;
|
|
115
|
+
attachments: number;
|
|
116
|
+
}, options: import("../../plugin.js").AppendOptions): Promise<import("../../models/index.js").JournalEvent<"ext">>;
|
|
117
|
+
read(event: import("../../models/index.js").JournalEvent): {
|
|
118
|
+
chars: number;
|
|
119
|
+
attachments: number;
|
|
120
|
+
} | undefined;
|
|
121
|
+
contribution(message: {
|
|
122
|
+
role?: import("../../models/index.js").InputRole;
|
|
123
|
+
content: string | readonly import("../../llm/content.js").ContentPartInput[];
|
|
124
|
+
}, value: {
|
|
125
|
+
chars: number;
|
|
126
|
+
attachments: number;
|
|
127
|
+
}, options?: {
|
|
128
|
+
sourceSeqs?: readonly import("../../models/index.js").Seq[];
|
|
129
|
+
}): import("../../models/index.js").StepContribution;
|
|
130
|
+
matchesSource(record: import("../../util/json.js").DeepReadonly<import("../../models/index.js").ExtensionRecord>): boolean;
|
|
131
|
+
rejection(reason: string, value: {
|
|
132
|
+
chars: number;
|
|
133
|
+
attachments: number;
|
|
134
|
+
}): {
|
|
135
|
+
decision: "reject";
|
|
136
|
+
reason: string;
|
|
137
|
+
source: import("../../models/index.js").ExtensionRecord;
|
|
138
|
+
};
|
|
139
|
+
readContribution: (event: import("../../models/index.js").JournalEvent) => {
|
|
140
|
+
chars: number;
|
|
141
|
+
attachments: number;
|
|
142
|
+
} | undefined;
|
|
143
|
+
readSource: (source: import("../../util/json.js").DeepReadonly<import("../../models/index.js").ExtensionRecord> | null) => {
|
|
144
|
+
chars: number;
|
|
145
|
+
attachments: number;
|
|
146
|
+
} | undefined;
|
|
147
|
+
told: import("../../plugin.js").PluginProjection<import("../../kit/extension.js").ToldNotices<{
|
|
148
|
+
chars: number;
|
|
149
|
+
attachments: number;
|
|
150
|
+
}>>;
|
|
151
|
+
projection<State>(fold: {
|
|
152
|
+
key: string;
|
|
153
|
+
init(): State;
|
|
154
|
+
apply(state: State, value: {
|
|
155
|
+
chars: number;
|
|
156
|
+
attachments: number;
|
|
157
|
+
}, event: import("../../models/index.js").JournalEvent<"ext">): State;
|
|
158
|
+
onFork?: "inherit" | "reset";
|
|
159
|
+
}): import("../../plugin.js").PluginProjection<State>;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* A summary the `summarize` strategy could not use, recorded with the request that asked for it:
|
|
163
|
+
* what its breaker counts. A run of them stops pressure from compacting until a checkpoint commits
|
|
164
|
+
* or the thread's installations change; it lasts across reopening, and a fork inherits it.
|
|
165
|
+
*/
|
|
166
|
+
export declare const unusableSummaryRecord: {
|
|
167
|
+
record: (value: {
|
|
168
|
+
reason: string;
|
|
169
|
+
}) => import("../../models/index.js").ExtensionRecord;
|
|
170
|
+
parse: (value: {
|
|
171
|
+
reason: string;
|
|
172
|
+
}) => {
|
|
173
|
+
reason: string;
|
|
174
|
+
};
|
|
175
|
+
entry: (value: {
|
|
176
|
+
reason: string;
|
|
177
|
+
}, options: import("../../plugin.js").AppendOptions) => {
|
|
178
|
+
type: "ext";
|
|
179
|
+
data: {
|
|
180
|
+
plugin: string;
|
|
181
|
+
instance_id: string;
|
|
182
|
+
kind: string;
|
|
183
|
+
version: number;
|
|
184
|
+
data: z.core.util.JSONType;
|
|
185
|
+
};
|
|
186
|
+
options: import("../../plugin.js").AppendOptions;
|
|
187
|
+
};
|
|
188
|
+
append(journal: import("../../plugin.js").PluginJournal, value: {
|
|
189
|
+
reason: string;
|
|
190
|
+
}, options: import("../../plugin.js").AppendOptions): Promise<import("../../models/index.js").JournalEvent<"ext">>;
|
|
191
|
+
read(event: import("../../models/index.js").JournalEvent): {
|
|
192
|
+
reason: string;
|
|
193
|
+
} | undefined;
|
|
194
|
+
contribution(message: {
|
|
195
|
+
role?: import("../../models/index.js").InputRole;
|
|
196
|
+
content: string | readonly import("../../llm/content.js").ContentPartInput[];
|
|
197
|
+
}, value: {
|
|
198
|
+
reason: string;
|
|
199
|
+
}, options?: {
|
|
200
|
+
sourceSeqs?: readonly import("../../models/index.js").Seq[];
|
|
201
|
+
}): import("../../models/index.js").StepContribution;
|
|
202
|
+
matchesSource(record: import("../../util/json.js").DeepReadonly<import("../../models/index.js").ExtensionRecord>): boolean;
|
|
203
|
+
rejection(reason: string, value: {
|
|
204
|
+
reason: string;
|
|
205
|
+
}): {
|
|
206
|
+
decision: "reject";
|
|
207
|
+
reason: string;
|
|
208
|
+
source: import("../../models/index.js").ExtensionRecord;
|
|
209
|
+
};
|
|
210
|
+
readContribution: (event: import("../../models/index.js").JournalEvent) => {
|
|
211
|
+
reason: string;
|
|
212
|
+
} | undefined;
|
|
213
|
+
readSource: (source: import("../../util/json.js").DeepReadonly<import("../../models/index.js").ExtensionRecord> | null) => {
|
|
214
|
+
reason: string;
|
|
215
|
+
} | undefined;
|
|
216
|
+
told: import("../../plugin.js").PluginProjection<import("../../kit/extension.js").ToldNotices<{
|
|
217
|
+
reason: string;
|
|
218
|
+
}>>;
|
|
219
|
+
projection<State>(fold: {
|
|
220
|
+
key: string;
|
|
221
|
+
init(): State;
|
|
222
|
+
apply(state: State, value: {
|
|
223
|
+
reason: string;
|
|
224
|
+
}, event: import("../../models/index.js").JournalEvent<"ext">): State;
|
|
225
|
+
onFork?: "inherit" | "reset";
|
|
226
|
+
}): import("../../plugin.js").PluginProjection<State>;
|
|
227
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One run of a surface between direct developer inputs: entries `start` up to, not including,
|
|
3
|
+
* `end`. A span may lie anywhere inside one and never across one, since no replacement may contain
|
|
4
|
+
* direct developer input, a `developer` `input/message` with no `source`.
|
|
5
|
+
*/
|
|
6
|
+
export type SurfaceSegment = {
|
|
7
|
+
readonly start: number;
|
|
8
|
+
readonly end: number;
|
|
9
|
+
/** Whether it runs to the newest message: the only segment that keeps a tail. */
|
|
10
|
+
readonly last: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The segments of `entries` from index `from` on, oldest first: the runs between direct developer
|
|
14
|
+
* inputs, which are the boundaries and belong to no segment. An empty run is not a segment, so when
|
|
15
|
+
* the newest entry is itself direct developer input no segment is `last`. Entries before `from`,
|
|
16
|
+
* such as a pinned opening, belong to none.
|
|
17
|
+
*
|
|
18
|
+
* Generic over anything that says whether it is direct developer input, so a strategy can segment
|
|
19
|
+
* the surface entries themselves or its own snapshot of them.
|
|
20
|
+
*/
|
|
21
|
+
export declare function surfaceSegments(entries: readonly {
|
|
22
|
+
readonly directDeveloperInput: boolean;
|
|
23
|
+
}[], from?: number): SurfaceSegment[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Context } from '@leuduan/cordis';
|
|
2
|
+
import type { SurfacePrepareInput } from '../../loop/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* A reporter that says each condition once for as long as the strategy lives, one activation. `key`
|
|
5
|
+
* names the condition (its cause, the route, the latest replacement), so a step that finds it again
|
|
6
|
+
* stays quiet.
|
|
7
|
+
*/
|
|
8
|
+
export declare function onceReporter(ctx: Context): (key: string, message: string) => void;
|
|
9
|
+
/** Whether the thread's agent has both recall tools granted now, so a stand-in or a footer may point at them. */
|
|
10
|
+
export declare function recallGranted(ctx: Context, agentName: string): boolean;
|
|
11
|
+
/** What the next request sends ahead of its messages: the recorded prompt and the tools the agent has now. */
|
|
12
|
+
export declare function estimateThreadHead(ctx: Context, threadId: string, agentName: string): number;
|
|
13
|
+
/** The input a step claims, which the request sends after the surface. */
|
|
14
|
+
export declare const estimateClaimed: (prepare: SurfacePrepareInput) => number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from '@leuduan/cordis';
|
|
2
|
+
import { type StrategyOptions, type SummarizeStrategyConfig } from './config.js';
|
|
3
|
+
/**
|
|
4
|
+
* The `summarize` strategy on one thread, provided from the thread's own scope. What it measures
|
|
5
|
+
* from is the journal, its breaker included (unusable summaries are recorded, see
|
|
6
|
+
* `unusableSummaryRecord`); its rate-limited reports last one activation.
|
|
7
|
+
*
|
|
8
|
+
* A thread runs one strategy, and every way of mounting this one, a root mount whose selector
|
|
9
|
+
* covers the thread, an installation on it, or both, ends here: providing it is refused when the
|
|
10
|
+
* thread already has one, the later of the two, which fails the activation or the installation
|
|
11
|
+
* rather than letting two strategies replace the same surface.
|
|
12
|
+
*/
|
|
13
|
+
export declare const summarizeStrategy: Plugin.Object<StrategyOptions<SummarizeStrategyConfig>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Plugin } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
declare const DateAndBranchSchema: z.ZodObject<{
|
|
4
|
+
date: z.ZodString;
|
|
5
|
+
time_zone: z.ZodString;
|
|
6
|
+
head: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
7
|
+
kind: z.ZodLiteral<"branch">;
|
|
8
|
+
name: z.ZodString;
|
|
9
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
10
|
+
kind: z.ZodLiteral<"detached">;
|
|
11
|
+
commit: z.ZodString;
|
|
12
|
+
}, z.core.$strict>], "kind">>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
/** What a thread is told: the day and, in a repository, its branch. */
|
|
15
|
+
export type DateAndBranch = z.output<typeof DateAndBranchSchema>;
|
|
16
|
+
declare const DateAndBranchConfigSchema: z.ZodObject<{
|
|
17
|
+
agents: z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodLiteral<"global">, z.ZodLiteral<"all">]>;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
export type DateAndBranchConfig = z.input<typeof DateAndBranchConfigSchema>;
|
|
20
|
+
/**
|
|
21
|
+
* Tells an agent the date and, when its `cwd` is in a git repository, the branch, as one notice
|
|
22
|
+
* that says both every time. `codexPreset` mounts it for the agents it equips; it is not handed
|
|
23
|
+
* down, since a sub-agent's task depends on neither.
|
|
24
|
+
*
|
|
25
|
+
* The facts are compared only on a turn's first model step, and told when they differ from the
|
|
26
|
+
* latest notice the model can still see: on a thread's first turn, on the first step of a turn after
|
|
27
|
+
* the day or the branch changed, and after a replacement took the notice off the surface. Never
|
|
28
|
+
* mid-turn, where a branch change is most likely the agent's own `git checkout`, which it knows.
|
|
29
|
+
*
|
|
30
|
+
* The date is the day in the process's time zone, which the notice names. The branch is read
|
|
31
|
+
* synchronously from the filesystem, since step listeners must not await: the repository is the
|
|
32
|
+
* nearest one at or above the `cwd` (`findRepository`), through a `.git` file for a linked worktree
|
|
33
|
+
* or a submodule, and its `HEAD` names the branch, or a commit for a detached head.
|
|
34
|
+
*
|
|
35
|
+
* Not a prompt section: the recorded prompt must not change while the thread lives, and both facts
|
|
36
|
+
* do. Mounted on the root it tells the agents `agents` selects on every thread; mounted through
|
|
37
|
+
* `thread.ctx`, that thread when it selects its agent.
|
|
38
|
+
*/
|
|
39
|
+
export declare const dateAndBranch: Plugin.Object<DateAndBranchConfig>;
|
|
40
|
+
/** The day `now` falls on in the process's time zone, and the branch of the repository holding `cwd`. */
|
|
41
|
+
export declare function currentDateAndBranch(cwd: string, now: Date): DateAndBranch;
|
|
42
|
+
/**
|
|
43
|
+
* What a thread is told: the day and, in a repository, the branch, whole every time, with what
|
|
44
|
+
* differs from `told`, the notice the model can still see, noted as previously.
|
|
45
|
+
*/
|
|
46
|
+
export declare function renderDateAndBranch(facts: DateAndBranch, told: DateAndBranch | null): string;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"../chunks/O4PPOM5Z.js";import"../chunks/OVZFGILJ.js";import"../chunks/G6RXC3AL.js";import"../chunks/DRYAN665.js";import"../chunks/2OSESBIL.js";import"../chunks/YLNJXQ3Z.js";import"../chunks/DDANMY45.js";import"../chunks/37YOGDGY.js";import"../chunks/KESCTXGO.js";import"../chunks/TYTQRLTX.js";import"../chunks/D7E6EWIE.js";export{b as currentDateAndBranch,a as dateAndBranch,c as renderDateAndBranch};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ToolResult } from '../../models/index.js';
|
|
2
|
+
import type { TaskSettlement } from './record.js';
|
|
3
|
+
import type { DelegationOutcome } from './request.js';
|
|
4
|
+
/** The most a failed task's answer quotes of the child's latest text. */
|
|
5
|
+
export declare const LATEST_TEXT_CHARS = 2000;
|
|
6
|
+
/** `text`, or its last `LATEST_TEXT_CHARS` characters marked as cut. */
|
|
7
|
+
export declare const quoteLatest: (text: string) => string;
|
|
8
|
+
/** What a caller is told of a settled task. */
|
|
9
|
+
export declare function outcomeOf(settlement: TaskSettlement): DelegationOutcome;
|
|
10
|
+
/** Why a call's result ended its task: how the call was answered. */
|
|
11
|
+
export declare function answeredBy(result: ToolResult): string;
|
|
12
|
+
/** A task holding one of its origin root's slots, and why it still holds it. */
|
|
13
|
+
export type SlotHolder = {
|
|
14
|
+
readonly taskId: string;
|
|
15
|
+
/** The thread doing it, or that will once the call that reserved the slot has opened the task. */
|
|
16
|
+
readonly childId: string;
|
|
17
|
+
readonly callerId: string;
|
|
18
|
+
readonly why: 'starting' | 'open' | 'waiting for an approval' | 'running a late turn' | 'being stopped';
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Why a delegating call gets no slot, in words the model can act on: how many of its origin root's
|
|
22
|
+
* slots are in use, which of them the calling thread holds and how to free one, or that the capacity is
|
|
23
|
+
* held elsewhere.
|
|
24
|
+
*/
|
|
25
|
+
export declare function capRefusal(limit: number, holders: readonly SlotHolder[], callerId: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Why a delegating call gets no slot while some thread's task state cannot be read: that thread
|
|
28
|
+
* may hold a slot, so how many are in use is unknown, and the cap fails closed.
|
|
29
|
+
*/
|
|
30
|
+
export declare function unknownOccupancy(unreadable: readonly {
|
|
31
|
+
childId: string;
|
|
32
|
+
error: string;
|
|
33
|
+
}[]): string;
|
|
34
|
+
/**
|
|
35
|
+
* Why a delegating call gets no slot when the thread at the top of the caller's origin tree cannot be
|
|
36
|
+
* found, a caller the catalog does not hold above it: whose slots it would take is unknown, and the
|
|
37
|
+
* cap fails closed.
|
|
38
|
+
*/
|
|
39
|
+
export declare const UNKNOWN_ROOT = "Cannot give an agent a task now: the conversation this thread belongs to cannot be found, so how many task slots are in use is unknown.";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { OriginCause } from '../../models/index.js';
|
|
3
|
+
import type { StartedOrigin } from './record.js';
|
|
4
|
+
/**
|
|
5
|
+
* What delegations records of an owner's assignment in a task's origin: which assignment, and the
|
|
6
|
+
* participant generation it runs on. The origin's `key` is opaque to core; this is the one codec
|
|
7
|
+
* that writes and reads it, so a host that attributes a task decodes it with {@link assignmentKey}.
|
|
8
|
+
*/
|
|
9
|
+
declare const AssignmentKeySchema: z.ZodObject<{
|
|
10
|
+
assignment: z.ZodString;
|
|
11
|
+
generation: z.ZodNumber;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
export type AssignmentKey = z.infer<typeof AssignmentKeySchema>;
|
|
14
|
+
/** A cause that is not an assignment of delegations' shape: a call's, or one whose `key` does not decode. */
|
|
15
|
+
export declare class AssignmentKeyError extends Error {
|
|
16
|
+
constructor(detail: string);
|
|
17
|
+
}
|
|
18
|
+
/** The assignment cause an owner's task records: the owner, and `key` as the codec writes it. */
|
|
19
|
+
export declare function assignmentCause(owner: string, key: AssignmentKey): StartedOrigin['cause'];
|
|
20
|
+
/** The key of an assignment cause, decoded; throws {@link AssignmentKeyError} for a call's cause or an invalid key. */
|
|
21
|
+
export declare function assignmentKey(cause: OriginCause): AssignmentKey;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import type { Seq } from '../../models/index.js';
|
|
3
|
+
import { type TaskRef, type TaskState } from './record.js';
|
|
4
|
+
/** Who stops a task, why, and the call that stopped it when a call did. */
|
|
5
|
+
export type StopOptions = {
|
|
6
|
+
readonly by: 'caller' | 'host' | 'ancestor';
|
|
7
|
+
readonly reason: string;
|
|
8
|
+
readonly callSeq: Seq | null;
|
|
9
|
+
};
|
|
10
|
+
/** A stop's durable answer: how the task ended, and whether its stop's cleanup is still running. */
|
|
11
|
+
export type StopOutcome = TaskRef & {
|
|
12
|
+
readonly state: Exclude<TaskState, 'open'>;
|
|
13
|
+
readonly cleanupPending: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The stop and its subtree cleanup, for the delegations service. A stop is a durable intent and a cleanup over
|
|
17
|
+
* the stopped thread's subtree: every thread under it with anything to quiet is signalled at once,
|
|
18
|
+
* then quieted deepest first by a cleanup of its own, one per thread id, which rejects that thread's
|
|
19
|
+
* unanswered confirmations and revokes its approved calls that have not run; `stop_cleaned` lands
|
|
20
|
+
* bottom-up. `resume` above it, or another stop of it, resumes a cleanup a crash left pending.
|
|
21
|
+
*
|
|
22
|
+
* The ordering it keeps: a stop's write is queued before `stop` returns, with nothing awaited, so a
|
|
23
|
+
* result listener orders it ahead of every write the caller enqueues after; that write reserves
|
|
24
|
+
* the walk over the subtree, so an opening queued behind it meets the walk (`blocksOpening`); and
|
|
25
|
+
* `drain` joins the stops and walks while the journal still takes their rows.
|
|
26
|
+
*/
|
|
27
|
+
export declare class StopCleanup {
|
|
28
|
+
/** Stops whose intent is on its way to the journal: the task constraint holds a task under one. */
|
|
29
|
+
private readonly stopping;
|
|
30
|
+
/** One cleanup per thread id, which every walker that reaches the thread joins. */
|
|
31
|
+
private readonly cleanups;
|
|
32
|
+
/**
|
|
33
|
+
* The walks over a stopped thread's subtree, by the stopped thread, each bound to the task whose
|
|
34
|
+
* stop started it: taken inside that stop's write, so no task opens on the thread from then until
|
|
35
|
+
* the walk ends, and a second stop of it joins. `walk` is `null` until the stop's write is durable.
|
|
36
|
+
*/
|
|
37
|
+
private readonly walks;
|
|
38
|
+
/** Stopped tasks whose subtree a walk in this process found quiet: revalidated once, then trusted. */
|
|
39
|
+
private readonly validated;
|
|
40
|
+
private readonly ctx;
|
|
41
|
+
private readonly ready;
|
|
42
|
+
constructor(ctx: Context,
|
|
43
|
+
/** Resolves once the task state can be served; a walk waits for it. */
|
|
44
|
+
ready: Promise<void>);
|
|
45
|
+
/**
|
|
46
|
+
* Stops task `taskId` of `childId`, decided inside one write on the child from its own rows: `null`
|
|
47
|
+
* when the child holds no such task, which a stop sent to a candidate child reads as "not this
|
|
48
|
+
* one". A settled task is left as it settled, and its outcome reported. A record the child's rows
|
|
49
|
+
* cannot be read for rejects. When the task is the child's latest and stopped, by this write or
|
|
50
|
+
* before, the write also takes the walk over the child's subtree for this task, so nothing opens on
|
|
51
|
+
* the child from then until the walk ends; once the decision is durable, a run of the child still
|
|
52
|
+
* serving the task is cancelled and the walk starts or is joined. Nobody awaits the walk.
|
|
53
|
+
*/
|
|
54
|
+
stop(childId: string, taskId: string, options: StopOptions): Promise<StopOutcome | null>;
|
|
55
|
+
/** Resolves once the walk over `threadId`'s subtree, if one runs, has ended, however it ended. */
|
|
56
|
+
whenWalked(threadId: string): Promise<void>;
|
|
57
|
+
/** Whether a stop's walk or a thread cleanup holds `threadId`, so no task may open on it now. */
|
|
58
|
+
blocksOpening(threadId: string): boolean;
|
|
59
|
+
/** Stops on their way to the journal that end `task`, or a task of a thread above its child. */
|
|
60
|
+
stopsAffecting(task: TaskRef): Promise<StopOutcome | null>[];
|
|
61
|
+
/**
|
|
62
|
+
* Re-enters `stop` for every thread under `under` whose stop's cleanup is pending, which resumes
|
|
63
|
+
* it, and for every thread whose latest task is stopped and has not been validated in this
|
|
64
|
+
* process, which walks its subtree once: a cleanup acknowledged before it covered the subtree can
|
|
65
|
+
* have left anything under it, an approved call that has not run included, which the catalog
|
|
66
|
+
* shows only as work a run would find. One under another resumed here is covered by that one's
|
|
67
|
+
* walk. Returns each stop, which resolves once its decision is durable and its walk started.
|
|
68
|
+
*/
|
|
69
|
+
resume(under: string): Promise<StopOutcome | null>[];
|
|
70
|
+
/** Waits for every stop on its way and every walk and thread cleanup running, for shutdown. */
|
|
71
|
+
drain(): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* The stop itself. A thread's own cleanup writes an ancestor's stop with `clean` false, since it
|
|
74
|
+
* is that cleanup; so the flag stays private rather than an option of `stop`: a stop from outside
|
|
75
|
+
* that took no walk would leave the stopped subtree unquieted.
|
|
76
|
+
*/
|
|
77
|
+
private decide;
|
|
78
|
+
/**
|
|
79
|
+
* Starts the walk the stop's write took over the stopped thread's subtree, or joins it. Nobody
|
|
80
|
+
* awaits it; a failure is reported and leaves the stop's cleanup pending, for the next `resume`
|
|
81
|
+
* above it or the next `stop` of it to resume. A walk that ends lets openings on the thread
|
|
82
|
+
* through again; one that found the subtree quiet marks every stopped task in it validated.
|
|
83
|
+
*/
|
|
84
|
+
private cleanUp;
|
|
85
|
+
/** Marks the stopped tasks at and under `threadId` validated: a walk just found them quiet. */
|
|
86
|
+
private markValidated;
|
|
87
|
+
/**
|
|
88
|
+
* Walks a stopped thread's subtree. Its workset is the stopped thread and every thread under it
|
|
89
|
+
* with anything to quiet (`toQuiet`), read from the catalog, whatever a thread between them
|
|
90
|
+
* acknowledged before, so a subtree an older cleanup certified only locally is checked again. Every
|
|
91
|
+
* thread in it is signalled at once, without waiting for any to go quiet; then each is quieted by
|
|
92
|
+
* its own cleanup, deepest first, so `stop_cleaned` lands bottom-up and the stopped thread's last.
|
|
93
|
+
* It is bound to `taskId`: if that is no longer the thread's latest task, it touches nothing. Its
|
|
94
|
+
* completion depends on each thread's cancel settling, which waits for the operation holding it.
|
|
95
|
+
*/
|
|
96
|
+
private walk;
|
|
97
|
+
/** The stopped thread and every thread under it with anything to quiet, by depth, deepest first. */
|
|
98
|
+
private workset;
|
|
99
|
+
/**
|
|
100
|
+
* Whether a thread under a stopped one has anything to quiet: a task open or being cleaned up
|
|
101
|
+
* after, or one whose state cannot be read; something live on it (`holdsWork`); or work a run
|
|
102
|
+
* would find, `has_work` or `turn_open`, which is how an approved call that has not run shows.
|
|
103
|
+
*/
|
|
104
|
+
private toQuiet;
|
|
105
|
+
/** Whether a run or an operation holds the thread, input waits on it, or a confirmation of it is unanswered. */
|
|
106
|
+
private holdsWork;
|
|
107
|
+
/** Whether a run serves the thread now, or an exclusive operation holds it. */
|
|
108
|
+
private busy;
|
|
109
|
+
/**
|
|
110
|
+
* Signals one thread of a stopped subtree, waiting for nothing: stops its task if open, as stopped
|
|
111
|
+
* by an ancestor, and begins its cancel.
|
|
112
|
+
*/
|
|
113
|
+
private signal;
|
|
114
|
+
/**
|
|
115
|
+
* Whether a cleanup cancel would stop anything on the thread: a run or an operation holding it, a
|
|
116
|
+
* pending run, or queued input. A cancel of a thread with none of these would only add a row, on
|
|
117
|
+
* every walk, which a restart repeats for every stopped task.
|
|
118
|
+
*/
|
|
119
|
+
private cancellable;
|
|
120
|
+
/** A thread's own cleanup: the one running, which every walker that reaches the thread joins, or a new one. */
|
|
121
|
+
private quietThread;
|
|
122
|
+
/**
|
|
123
|
+
* Quiets one thread of a stopped subtree, owning every write on it. Stops its task if still open,
|
|
124
|
+
* as stopped by an ancestor, once a stop of it already on its way has landed; cancels it when there
|
|
125
|
+
* is anything to stop (`cancellable`), which aborts the run or operation holding it, a late turn
|
|
126
|
+
* after a settle included, clears its queue and settles its pending run, and waits for that; then
|
|
127
|
+
* rejects its unanswered confirmations and
|
|
128
|
+
* takes back its approved calls without a result, so no later run runs one; then stops the
|
|
129
|
+
* commands this process runs for it and every thread under it, and waits for them to end. The
|
|
130
|
+
* thread and its subtree are loaded and held throughout, since only a loaded thread's
|
|
131
|
+
* confirmations can be read, and a loaded thread's command evidence needs no commands plugin.
|
|
132
|
+
* Then acknowledges, or, if something came back meanwhile, a run admitted since or input queued
|
|
133
|
+
* after the clear, does it again. A command whose end is not established keeps it from going
|
|
134
|
+
* quiet however often it tries: the failure names it.
|
|
135
|
+
*/
|
|
136
|
+
private quiet;
|
|
137
|
+
/** Stops the loaded thread's latest task if it is open, as stopped by an ancestor, once any stop of it on its way has landed. */
|
|
138
|
+
private stopOwnTask;
|
|
139
|
+
/** Stops the commands this process runs for `threadId` and every thread under it, and waits for them to end. */
|
|
140
|
+
private stopCommands;
|
|
141
|
+
/**
|
|
142
|
+
* Rejects the loaded thread's unanswered confirmations and takes back its approved calls that have
|
|
143
|
+
* no result, each as one write. A write that meets an answer given meanwhile, which a person can
|
|
144
|
+
* give at any time, records nothing; what is pending is read again and tried once more.
|
|
145
|
+
*/
|
|
146
|
+
private settleConfirmations;
|
|
147
|
+
/**
|
|
148
|
+
* Writes `stop_cleaned` for the thread's stops not yet acknowledged, decided inside one write, once
|
|
149
|
+
* the thread is quiet and so is everything under it; `false` when not. Quiet: no run and no
|
|
150
|
+
* operation holds the thread, its queue is empty, and none of its confirmations is unanswered or
|
|
151
|
+
* approved without a result. Under it: no task open or still being cleaned up after, none
|
|
152
|
+
* unreadable, and nothing running, held, queued or waiting for an answer. On it and under it: every
|
|
153
|
+
* command known to have ended (`commandWork`), so neither a stop that failed nor a termination no
|
|
154
|
+
* process saw is acknowledged as quiet. Whether a thread beneath
|
|
155
|
+
* has an approved call without a result is not in the catalog: its own cleanup, which ran first,
|
|
156
|
+
* took it back, and nothing can approve one since.
|
|
157
|
+
*/
|
|
158
|
+
private acknowledge;
|
|
159
|
+
/** Whether every thread under `threadId` is quiet, as the catalog and this process tell it. */
|
|
160
|
+
private quietUnder;
|
|
161
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { TaskReading } from './record.js';
|
|
2
|
+
/**
|
|
3
|
+
* What the task predicate reads of one task, every field a synchronous read the service already
|
|
4
|
+
* keeps: the child's catalog entry, the stops above it and on their way, whether its run still
|
|
5
|
+
* drains input accepted before it settled, and what authorizes it, by its origin.
|
|
6
|
+
*/
|
|
7
|
+
export type TaskView = {
|
|
8
|
+
readonly taskId: string;
|
|
9
|
+
/** The child's latest task, from its catalog entry. */
|
|
10
|
+
readonly reading: TaskReading;
|
|
11
|
+
/** Why a stop above the child keeps anything new from it, or `null`. */
|
|
12
|
+
readonly stoppedAbove: {
|
|
13
|
+
readonly kind: 'stopping' | 'unreadable';
|
|
14
|
+
readonly why: string;
|
|
15
|
+
} | null;
|
|
16
|
+
/** Whether a stop of the task, or of a thread above its child, is on its way to the journal. */
|
|
17
|
+
readonly stopOnItsWay: boolean;
|
|
18
|
+
/** Whether an outstanding stop obligation names the child, or a thread above it. */
|
|
19
|
+
readonly obligated: boolean;
|
|
20
|
+
/** Whether the task settled while the run that served it still drains input accepted before. */
|
|
21
|
+
readonly draining: boolean;
|
|
22
|
+
/** What authorizes the task: its opening call, or its owner's assignment. */
|
|
23
|
+
readonly authority: CallAuthority | AssignmentAuthority;
|
|
24
|
+
};
|
|
25
|
+
/** A call-opened task's authority: where its opening call stands. */
|
|
26
|
+
export type CallAuthority = {
|
|
27
|
+
readonly kind: 'call';
|
|
28
|
+
readonly background: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The opening call's result: its `receipt`; `answered` by anything else, which ends the task;
|
|
31
|
+
* `none` yet; `unknown` while the caller's rows have not been indexed in this process.
|
|
32
|
+
*/
|
|
33
|
+
readonly opening: 'receipt' | 'answered' | 'none' | 'unknown';
|
|
34
|
+
/**
|
|
35
|
+
* Whether the opening call still runs in this process, without a result: a background task's
|
|
36
|
+
* authority until its receipt is durable, a blocking task's until its wait is declared.
|
|
37
|
+
*/
|
|
38
|
+
readonly callRunsHere: boolean;
|
|
39
|
+
/** Whether the caller's catalog entry shows the opening call suspended on its wait: a blocking task's authority. */
|
|
40
|
+
readonly callSuspended: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* An owner's task's authority: the verdict of its live registered owner on the assignment its
|
|
44
|
+
* `started` row records, or why there is none (no owner registered under its name).
|
|
45
|
+
*/
|
|
46
|
+
export type AssignmentAuthority = {
|
|
47
|
+
readonly kind: 'assignment';
|
|
48
|
+
readonly verdict: {
|
|
49
|
+
readonly kind: 'allow';
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: 'hold';
|
|
52
|
+
readonly reason: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Whether a task may be run now: `allow`; `hold` with why, while something may still change; or
|
|
57
|
+
* `obsolete` with why, when the task has ended and nothing of its request remains to drain.
|
|
58
|
+
*/
|
|
59
|
+
export type TaskVerdict = {
|
|
60
|
+
readonly kind: 'allow';
|
|
61
|
+
} | {
|
|
62
|
+
readonly kind: 'hold';
|
|
63
|
+
readonly reason: string;
|
|
64
|
+
} | {
|
|
65
|
+
readonly kind: 'obsolete';
|
|
66
|
+
readonly reason: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The task predicate, pure: the task is its child's latest and open, or settled with its run still
|
|
70
|
+
* draining; no stop is recorded above it, on its way, or owed by an obligation; and its authority
|
|
71
|
+
* holds. A call's: while the task is open, its opening call was not answered by anything but its
|
|
72
|
+
* receipt, a background task's receipt is durable or its call runs here, and its state is readable;
|
|
73
|
+
* and a blocking task's call, which the child serves, runs here or waits for it. An owner's
|
|
74
|
+
* assignment's: its live owner allows it, open or draining; no call, receipt or wait is read.
|
|
75
|
+
*/
|
|
76
|
+
export declare function evaluateTask(view: TaskView): TaskVerdict;
|