@leuduan/lagent 0.0.0-stage → 44.0.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/LICENSE +16 -0
- package/README.md +157 -2
- package/dist/chunks/2GCIWSOA.js +5 -0
- package/dist/chunks/2P47AHNK.js +7 -0
- package/dist/chunks/34KW6VNQ.js +1 -0
- package/dist/chunks/3UMZMPWW.js +1 -0
- package/dist/chunks/5IRF47YB.js +1 -0
- package/dist/chunks/6DRCKZ2C.js +1 -0
- package/dist/chunks/6FRNHMCV.js +1 -0
- package/dist/chunks/7LI64H5X.js +17 -0
- package/dist/chunks/7VAPNE3L.js +1 -0
- package/dist/chunks/ASSQZH3F.js +1 -0
- package/dist/chunks/B4FXK5ER.js +77 -0
- package/dist/chunks/BBCW2FZK.js +1 -0
- package/dist/chunks/BPRCULZH.js +1 -0
- package/dist/chunks/CANPZYTH.js +24 -0
- package/dist/chunks/CQEVREBT.js +1 -0
- package/dist/chunks/CUK7CGC7.js +1 -0
- package/dist/chunks/D4PQP5MA.js +3 -0
- package/dist/chunks/DDANMY45.js +3 -0
- package/dist/chunks/DDZ7YF26.js +1 -0
- package/dist/chunks/EMRB4KCN.js +6 -0
- package/dist/chunks/EPYQ5M3B.js +3 -0
- package/dist/chunks/FJLU4UH3.js +1 -0
- package/dist/chunks/G44LG6VL.js +1 -0
- package/dist/chunks/GGSVIIWJ.js +2 -0
- package/dist/chunks/HK6ZSONF.js +1 -0
- package/dist/chunks/IAAEP6VL.js +30 -0
- package/dist/chunks/JCTBX33H.js +36 -0
- package/dist/chunks/JFX2MXBA.js +4 -0
- package/dist/chunks/JFZZXVWD.js +15 -0
- package/dist/chunks/KUZCL2SH.js +1 -0
- package/dist/chunks/MHC6VPB4.js +7 -0
- package/dist/chunks/MMNNZCBO.js +5 -0
- package/dist/chunks/MNJ4SRF7.js +1 -0
- package/dist/chunks/N6IXG2VL.js +1 -0
- package/dist/chunks/OCBPT7KE.js +1 -0
- package/dist/chunks/OL5A6ITQ.js +1 -0
- package/dist/chunks/PUSUPTAT.js +1 -0
- package/dist/chunks/Q75FUN7D.js +2 -0
- package/dist/chunks/Q7S5LFGN.js +1 -0
- package/dist/chunks/RCIHV3KG.js +1 -0
- package/dist/chunks/S34ZA2R6.js +1 -0
- package/dist/chunks/SS3B5W34.js +12 -0
- package/dist/chunks/VYMT4TXD.js +1 -0
- package/dist/chunks/W57RW55W.js +1 -0
- package/dist/compositions/base.d.ts +11 -0
- package/dist/compositions/codex.d.ts +66 -0
- package/dist/compositions/codexPrompts.d.ts +56 -0
- package/dist/context.d.ts +109 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +1 -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/llm/client.d.ts +135 -0
- package/dist/llm/content.d.ts +52 -0
- package/dist/llm/failure.d.ts +82 -0
- package/dist/llm/index.d.ts +22 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/primitives.d.ts +286 -0
- package/dist/llm/prompt.d.ts +21 -0
- package/dist/llm/provider.d.ts +74 -0
- package/dist/llm/readLedger.d.ts +24 -0
- package/dist/llm/request.d.ts +58 -0
- package/dist/loop/agent.d.ts +18 -0
- package/dist/loop/authorization.d.ts +41 -0
- package/dist/loop/auxiliary.d.ts +58 -0
- package/dist/loop/chunks.d.ts +27 -0
- package/dist/loop/completion.d.ts +17 -0
- package/dist/loop/errors.d.ts +139 -0
- package/dist/loop/hooks.d.ts +274 -0
- package/dist/loop/index.d.ts +16 -0
- package/dist/loop/runner.d.ts +134 -0
- package/dist/loop/runtime.d.ts +76 -0
- package/dist/loop/strategy.d.ts +80 -0
- package/dist/loop/surfacePrepare.d.ts +30 -0
- package/dist/loop/tool.d.ts +106 -0
- package/dist/loop/toolCalls.d.ts +35 -0
- package/dist/plugin.d.ts +50 -0
- package/dist/plugin.js +1 -0
- package/dist/plugins/agentsMd.d.ts +80 -0
- package/dist/plugins/agentsMd.js +1 -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/ask/tools.d.ts +9 -0
- package/dist/plugins/commands/index.d.ts +43 -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 +558 -0
- package/dist/plugins/commands/service.d.ts +321 -0
- package/dist/plugins/commands/shell.d.ts +25 -0
- package/dist/plugins/commands/tools.d.ts +10 -0
- package/dist/plugins/compaction/checkpoint.d.ts +94 -0
- package/dist/plugins/compaction/config.d.ts +133 -0
- package/dist/plugins/compaction/estimate.d.ts +37 -0
- package/dist/plugins/compaction/index.d.ts +87 -0
- package/dist/plugins/compaction/index.js +7 -0
- package/dist/plugins/compaction/planner.d.ts +207 -0
- package/dist/plugins/compaction/prune.d.ts +9 -0
- package/dist/plugins/compaction/record.d.ts +227 -0
- package/dist/plugins/compaction/segments.d.ts +23 -0
- package/dist/plugins/compaction/state.d.ts +68 -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 +633 -0
- package/dist/plugins/delegations/request.d.ts +384 -0
- package/dist/plugins/delegations/role.d.ts +30 -0
- package/dist/plugins/delegations/service.d.ts +563 -0
- package/dist/plugins/delegations/standing.d.ts +19 -0
- package/dist/plugins/delegations/stopCheck.d.ts +21 -0
- package/dist/plugins/delegations/tools.d.ts +71 -0
- package/dist/plugins/delegations/waitContracts.d.ts +118 -0
- package/dist/plugins/delegations/waitResolver.d.ts +116 -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/fileTools/config.d.ts +10 -0
- package/dist/plugins/fileTools/editFiles.d.ts +117 -0
- package/dist/plugins/fileTools/fsRead.d.ts +17 -0
- package/dist/plugins/fileTools/gitDiscovery.d.ts +9 -0
- package/dist/plugins/fileTools/index.d.ts +18 -0
- package/dist/plugins/fileTools/index.js +1 -0
- package/dist/plugins/fileTools/ripgrep.d.ts +20 -0
- package/dist/plugins/fileTools/textEdit.d.ts +67 -0
- package/dist/plugins/fileTools/tools.d.ts +6 -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/tools.d.ts +41 -0
- package/dist/plugins/mcp/version.d.ts +2 -0
- package/dist/plugins/routeNotice.d.ts +22 -0
- package/dist/plugins/routeNotice.js +1 -0
- package/dist/plugins/sandbox/absent.d.ts +33 -0
- package/dist/plugins/sandbox/client.d.ts +39 -0
- package/dist/plugins/sandbox/files.d.ts +28 -0
- package/dist/plugins/sandbox/index.d.ts +52 -0
- package/dist/plugins/sandbox/index.js +4 -0
- package/dist/plugins/sandbox/mode.d.ts +57 -0
- package/dist/plugins/sandbox/policy.d.ts +163 -0
- package/dist/plugins/sandbox/protocol.d.ts +107 -0
- package/dist/plugins/sandbox/service.d.ts +153 -0
- package/dist/plugins/sandbox/worker.d.ts +12 -0
- package/dist/plugins/sandbox/worker.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 +83 -0
- package/dist/plugins/skills/index.d.ts +31 -0
- package/dist/plugins/skills/index.js +1 -0
- package/dist/plugins/skills/tools.d.ts +11 -0
- package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
- package/dist/plugins/subAgents/index.d.ts +67 -0
- package/dist/plugins/subAgents/index.js +1 -0
- package/dist/plugins/subAgents/tools.d.ts +67 -0
- package/dist/plugins/threadDirs.d.ts +36 -0
- package/dist/plugins/threadDirs.js +1 -0
- package/dist/plugins/toolPolicy/index.d.ts +61 -0
- package/dist/plugins/toolPolicy/index.js +1 -0
- package/dist/plugins/truncateToolOutput.d.ts +30 -0
- package/dist/plugins/truncateToolOutput.js +6 -0
- package/dist/plugins/usage/index.d.ts +26 -0
- package/dist/plugins/usage/index.js +1 -0
- package/dist/plugins/usage/tracker.d.ts +34 -0
- package/dist/plugins/verify/index.d.ts +27 -0
- package/dist/plugins/verify/index.js +6 -0
- package/dist/plugins/verify/judgement.d.ts +16 -0
- package/dist/plugins/verify/record.d.ts +382 -0
- package/dist/plugins/verify/service.d.ts +93 -0
- package/dist/plugins/verify/state.d.ts +58 -0
- package/dist/plugins/webTools/html.d.ts +23 -0
- package/dist/plugins/webTools/index.d.ts +34 -0
- package/dist/plugins/webTools/index.js +1 -0
- package/dist/plugins/webTools/network.d.ts +23 -0
- package/dist/plugins/webTools/web.d.ts +32 -0
- package/dist/plugins/workflows/assignment.d.ts +20 -0
- package/dist/plugins/workflows/cleanup.d.ts +38 -0
- package/dist/plugins/workflows/definition.d.ts +184 -0
- package/dist/plugins/workflows/entryPlan.d.ts +95 -0
- package/dist/plugins/workflows/hostBindings.d.ts +146 -0
- package/dist/plugins/workflows/index.d.ts +28 -0
- package/dist/plugins/workflows/index.js +11 -0
- package/dist/plugins/workflows/observations.d.ts +81 -0
- package/dist/plugins/workflows/participantModels.d.ts +28 -0
- package/dist/plugins/workflows/participants.d.ts +143 -0
- package/dist/plugins/workflows/policy.d.ts +112 -0
- package/dist/plugins/workflows/record.d.ts +2849 -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/state.d.ts +373 -0
- package/dist/plugins/workflows/stopCheck.d.ts +13 -0
- package/dist/plugins/workflows/tools.d.ts +13 -0
- package/dist/plugins/workflows/view.d.ts +103 -0
- package/dist/plugins/workflows/workStatus.d.ts +21 -0
- package/dist/plugins/workspaceNotice.d.ts +36 -0
- package/dist/plugins/workspaceNotice.js +1 -0
- package/dist/providers/anthropic.d.ts +178 -0
- package/dist/providers/anthropicMessages.d.ts +66 -0
- package/dist/providers/codex.d.ts +71 -0
- package/dist/providers/codexAuth.d.ts +116 -0
- package/dist/providers/deepseek.d.ts +59 -0
- package/dist/providers/failure.d.ts +23 -0
- package/dist/providers/gateway.d.ts +24 -0
- package/dist/providers/index.d.ts +18 -0
- package/dist/providers/index.js +6 -0
- package/dist/providers/openaiChat.d.ts +73 -0
- package/dist/providers/openaiResponses.d.ts +109 -0
- package/dist/providers/opencodeCopilot.d.ts +23 -0
- package/dist/providers/opencodeGo.d.ts +109 -0
- package/dist/providers/shared.d.ts +112 -0
- package/dist/providers/stream.d.ts +156 -0
- package/dist/records/index.d.ts +13 -0
- package/dist/records/index.js +1 -0
- package/dist/records/journal.d.ts +2968 -0
- package/dist/records/toolResult.d.ts +65 -0
- package/dist/services/agents.d.ts +62 -0
- package/dist/services/catalogContributions.d.ts +73 -0
- package/dist/services/confinement/files.d.ts +118 -0
- package/dist/services/confinement/service.d.ts +219 -0
- package/dist/services/core.d.ts +28 -0
- package/dist/services/extensionEvents.d.ts +181 -0
- package/dist/services/journal.d.ts +26 -0
- package/dist/services/llm.d.ts +82 -0
- package/dist/services/modes.d.ts +65 -0
- package/dist/services/plugins.d.ts +34 -0
- package/dist/services/presets/definition.d.ts +154 -0
- package/dist/services/presets/installations.d.ts +139 -0
- package/dist/services/prompts.d.ts +85 -0
- package/dist/services/threads/activation.d.ts +100 -0
- package/dist/services/threads/admission.d.ts +174 -0
- package/dist/services/threads/birth.d.ts +219 -0
- package/dist/services/threads/index.d.ts +14 -0
- package/dist/services/threads/runEvents.d.ts +79 -0
- package/dist/services/threads/runOwner.d.ts +368 -0
- package/dist/services/threads/service.d.ts +450 -0
- package/dist/services/threads/thread.d.ts +268 -0
- package/dist/services/threads/view.d.ts +93 -0
- package/dist/services/tools.d.ts +118 -0
- package/dist/state/birth.d.ts +62 -0
- package/dist/state/chain.d.ts +46 -0
- package/dist/state/confirmations.d.ts +64 -0
- package/dist/state/continuation.d.ts +167 -0
- package/dist/state/decide.d.ts +72 -0
- package/dist/state/dispatches.d.ts +54 -0
- package/dist/state/errors.d.ts +26 -0
- package/dist/state/forks.d.ts +61 -0
- package/dist/state/holds.d.ts +104 -0
- package/dist/state/inbox.d.ts +188 -0
- package/dist/state/index.d.ts +31 -0
- package/dist/state/inputs.d.ts +58 -0
- package/dist/state/installations.d.ts +28 -0
- package/dist/state/limits.d.ts +14 -0
- package/dist/state/prompt.d.ts +13 -0
- package/dist/state/recovery.d.ts +7 -0
- package/dist/state/replace.d.ts +33 -0
- package/dist/state/requests.d.ts +129 -0
- package/dist/state/route.d.ts +61 -0
- package/dist/state/summary.d.ts +16 -0
- package/dist/state/surface.d.ts +153 -0
- package/dist/state/surfaceRead.d.ts +20 -0
- package/dist/state/thread.d.ts +73 -0
- package/dist/state/turns.d.ts +87 -0
- package/dist/state/waits.d.ts +38 -0
- package/dist/state/wake.d.ts +32 -0
- package/dist/stores/durableObject.d.ts +23 -0
- package/dist/stores/durableObject.js +1 -0
- package/dist/stores/durableObjectConnection.d.ts +27 -0
- package/dist/stores/memory.d.ts +29 -0
- package/dist/stores/sql.d.ts +59 -0
- package/dist/stores/sqlite.d.ts +31 -0
- package/dist/stores/sqlite.js +1 -0
- package/dist/sys/environment.d.ts +42 -0
- package/dist/sys/git.d.ts +47 -0
- package/dist/sys/paths.d.ts +9 -0
- package/dist/sys/spawn.d.ts +186 -0
- package/dist/testing/clock.d.ts +17 -0
- package/dist/testing/fakeLlm.d.ts +76 -0
- package/dist/testing/fedLlm.d.ts +34 -0
- package/dist/testing/helpers.d.ts +362 -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/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/jsonSchema.d.ts +7 -0
- package/dist/util/log.d.ts +6 -0
- package/dist/util/retries.d.ts +25 -0
- package/dist/util/text.d.ts +21 -0
- package/dist/util/timers.d.ts +43 -0
- package/package.json +183 -3
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import { Service, type Context } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { InvocationContext, WaitRequest } from '../../loop/index.js';
|
|
4
|
+
import type { ThreadSummary } from '../../records/journal.js';
|
|
5
|
+
import type { ToolResultPayloadInput } from '../../records/toolResult.js';
|
|
6
|
+
import type { AppendEntry, PluginJournal } from '../../journal/index.js';
|
|
7
|
+
import type { ToolReply } from '../../services/tools.js';
|
|
8
|
+
import { type StopOptions, type StopOutcome } from './cleanup.js';
|
|
9
|
+
import { type TaskRef, type TaskState } from './record.js';
|
|
10
|
+
import { type AdmissionRefused, type AssignmentOwner, type DelegationRequest, type AssignmentOwnerHandle } from './request.js';
|
|
11
|
+
import { type TaskStanding } from './standing.js';
|
|
12
|
+
declare module '@leuduan/cordis' {
|
|
13
|
+
interface Context {
|
|
14
|
+
/** Every delegation: the tasks children are given, their drives, waits and stops (optional plugin). */
|
|
15
|
+
delegations: DelegationsService;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare const DelegationsConfigSchema: z.ZodObject<{
|
|
19
|
+
maxOpenTasks: z.ZodNumber;
|
|
20
|
+
clock: z.ZodCustom<import("../../util/timers.js").Clock, import("../../util/timers.js").Clock>;
|
|
21
|
+
}, z.core.$strict>;
|
|
22
|
+
export type DelegationsConfig = z.input<typeof DelegationsConfigSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* One thread's latest task, as `tasks()` reads it from the catalog: the thread and the thread that
|
|
25
|
+
* gave it the task, then the task, or why its state cannot be read.
|
|
26
|
+
*/
|
|
27
|
+
export type TaskEntry = {
|
|
28
|
+
readonly childId: string;
|
|
29
|
+
readonly callerId: string;
|
|
30
|
+
} & ({
|
|
31
|
+
readonly taskId: string;
|
|
32
|
+
readonly background: boolean;
|
|
33
|
+
/** Whether its caller is owed a notice once it completes or fails. */
|
|
34
|
+
readonly notice: boolean;
|
|
35
|
+
readonly state: TaskState;
|
|
36
|
+
/**
|
|
37
|
+
* Open, and an approval under it waits: asked by the child, by a descendant it waits on through
|
|
38
|
+
* blocking tasks, or, while the child is parked, through any of its open tasks.
|
|
39
|
+
*/
|
|
40
|
+
readonly blocked: boolean;
|
|
41
|
+
readonly cleanupPending: boolean;
|
|
42
|
+
readonly firstLine: string;
|
|
43
|
+
/** Settled, while the run that served it still drains input accepted before it settled. */
|
|
44
|
+
readonly draining: boolean;
|
|
45
|
+
} | {
|
|
46
|
+
readonly state: 'unavailable';
|
|
47
|
+
readonly error: string;
|
|
48
|
+
});
|
|
49
|
+
/** Which threads' tasks `tasks()` lists: those under a thread, its own excluded, or those it created. */
|
|
50
|
+
export type TaskFilter = {
|
|
51
|
+
readonly under: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly callerThreadId: string;
|
|
54
|
+
};
|
|
55
|
+
/** What `read_agent` asks of its named tasks: how long to wait at most, and for what. */
|
|
56
|
+
export type ReadRequest = {
|
|
57
|
+
readonly tasks: readonly TaskRef[];
|
|
58
|
+
/** `settled` returns once any named task settles; `activity` also once any named child records anything. */
|
|
59
|
+
readonly until: 'settled' | 'activity';
|
|
60
|
+
/** The longest the read waits; zero reads at once. */
|
|
61
|
+
readonly waitSeconds: number;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* What a read returns: each named task as it stands; when nothing can advance a named open task,
|
|
65
|
+
* why each stands still (`noProgress`); and when the caller's chain kept the read from waiting, a
|
|
66
|
+
* note saying so.
|
|
67
|
+
*/
|
|
68
|
+
export type ReadOutcome = {
|
|
69
|
+
readonly tasks: readonly TaskStanding[];
|
|
70
|
+
readonly noProgress: readonly string[] | null;
|
|
71
|
+
readonly note: string | null;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Every delegation, from the call that opens a task to the stop that ends one: the one way a tool
|
|
75
|
+
* delegates (`delegate`), the one way an owner's assignment does (`registerOwner`), both through
|
|
76
|
+
* one admission, the task constraint core runs every delegated child under, the one read
|
|
77
|
+
* (`read`), the one stop, and the catalog read of the tasks under a thread (`tasks`). A task is
|
|
78
|
+
* recorded on its child (`record.ts`) and its state is the child's catalog contribution, so every
|
|
79
|
+
* question about it is a catalog read.
|
|
80
|
+
*
|
|
81
|
+
* Every start, a call's or an owner's, takes one of its origin root's `maxOpenTasks` slots before
|
|
82
|
+
* anything is created, and its opening write queues the child's input with the assignment's cause,
|
|
83
|
+
* so core's owner runs the child once the task constraint (`evaluate`) allows. An owner's task runs
|
|
84
|
+
* on its live owner's say, with no call, receipt or wait, and owes no notice. A blocking call suspends on a
|
|
85
|
+
* durable wait (`waitFor`) that this service resolves with the task's answer; a background call
|
|
86
|
+
* returns a receipt and `read_agent` waits the same way. The waits, slots and constraint are
|
|
87
|
+
* described in `docs/records/delegation.md`. A call's task ends no later than its opening call's result, unless
|
|
88
|
+
* that result is its receipt:
|
|
89
|
+
* the service watches `tool/result` rows, and one citing a task's opening call ends the task if it
|
|
90
|
+
* is still open, however core answered the call, a deny, an unregistered tool, an aborted turn or a
|
|
91
|
+
* cancel of the waiting caller included. The constraint's repair, before anything runs at startup,
|
|
92
|
+
* mends what a crash left: stops whose cleanup is pending, tasks whose calls were answered, stop
|
|
93
|
+
* obligations, owed notices, and waits satisfied while the process was down.
|
|
94
|
+
*
|
|
95
|
+
* A stop and its cleanup over the stopped thread's subtree have their own owner (`cleanup.ts`); so
|
|
96
|
+
* has the notice that tells a caller a background task completed or failed (`notices.ts`). This
|
|
97
|
+
* service decides when each is asked for. A steer (`steer`) queues a correction into a task only for
|
|
98
|
+
* the next step of a run serving its child, never into an owner's. A call from a caller whose chain
|
|
99
|
+
* of unattended work is at core's limit (`ctx.threads.chain`) is refused, blocking or background.
|
|
100
|
+
*
|
|
101
|
+
* The ordering it keeps beside its owners': the result listener asks for the stop of a task whose
|
|
102
|
+
* call was answered synchronously, inside the write that answered it, so the stop's write lands
|
|
103
|
+
* before any work the caller's later writes start; and shutdown joins the calls in flight, then the
|
|
104
|
+
* stops and cleanups, while the journal still takes their rows.
|
|
105
|
+
*/
|
|
106
|
+
export declare class DelegationsService extends Service<DelegationsConfig> {
|
|
107
|
+
static inject: string[];
|
|
108
|
+
readonly config: z.output<typeof DelegationsConfigSchema>;
|
|
109
|
+
/** Resolves once the contribution refresh registration queued has completed: nothing is served before. */
|
|
110
|
+
private readonly ready;
|
|
111
|
+
private refreshed;
|
|
112
|
+
private obligationsRefreshed;
|
|
113
|
+
/** Task slots taken by calls whose `started` row is not durable yet, by task id. */
|
|
114
|
+
private readonly reservations;
|
|
115
|
+
/**
|
|
116
|
+
* Tasks whose opening call runs in this process and has no result yet, from before the write that
|
|
117
|
+
* opens the task: a background task's authority until its receipt is durable, and a blocking
|
|
118
|
+
* task's until its call's wait is declared, which the caller's catalog then shows.
|
|
119
|
+
*/
|
|
120
|
+
private readonly openingCalls;
|
|
121
|
+
/**
|
|
122
|
+
* Opening calls' results by task id, as far as this process has read them: a receipt, or the result
|
|
123
|
+
* that answered the call otherwise while its task was open. Built for a caller by its repair, the
|
|
124
|
+
* one scan of its rows (`indexCaller`), and kept by the result listener from then on. Only what
|
|
125
|
+
* the task's eligibility needs: an entry lives while its task is the child's latest and open or
|
|
126
|
+
* draining (the only states that read it), or while its state cannot be read, and goes with the
|
|
127
|
+
* child's next task row or run settlement (`evictOpening`); a result that arrives for a task
|
|
128
|
+
* that is not eligible is not kept (`rememberOpening`).
|
|
129
|
+
*/
|
|
130
|
+
private readonly openingResults;
|
|
131
|
+
/** Callers whose rows were read into `openingResults` in this process. */
|
|
132
|
+
private readonly indexedCallers;
|
|
133
|
+
/** Stop obligations being carried out, by id: each is carried out once at a time. */
|
|
134
|
+
private readonly carrying;
|
|
135
|
+
/** Every stop and its subtree cleanup (`cleanup.ts`), handed the drives on a thread. */
|
|
136
|
+
private readonly cleanup;
|
|
137
|
+
/** Every notice's delivery and withdrawal (`notices.ts`). */
|
|
138
|
+
private readonly notices;
|
|
139
|
+
/**
|
|
140
|
+
* Starts in flight, delegating calls and owners' starts alike, by their caller, which shutdown
|
|
141
|
+
* lets finish before it drains.
|
|
142
|
+
*/
|
|
143
|
+
private readonly starts;
|
|
144
|
+
/**
|
|
145
|
+
* Owners' admissions in flight by task id, with what they start: an identical start joins the one
|
|
146
|
+
* in flight; a different one waits for it, then replays or conflicts with what it wrote.
|
|
147
|
+
*/
|
|
148
|
+
private readonly admitting;
|
|
149
|
+
/** The live registration of each owner of assignment-origin tasks, by its name. */
|
|
150
|
+
private readonly owners;
|
|
151
|
+
/** Owners' tasks whose settling their owner was told of in this process. */
|
|
152
|
+
private readonly settledTold;
|
|
153
|
+
/** The task constraint's registration with the owner, through which the wait resolver resolves delegation waits. */
|
|
154
|
+
private constraint;
|
|
155
|
+
/** Every delegation wait, from its declaration to its call's answer, and when and with what it resolves (`waitResolver.ts`). */
|
|
156
|
+
private readonly waits;
|
|
157
|
+
private closing;
|
|
158
|
+
constructor(ctx: Context, config: DelegationsConfig);
|
|
159
|
+
[Service.init](): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Runs one delegating call: the one way a tool delegates, adapting the call into the one admission
|
|
162
|
+
* every task opens through, with the call as its authority. In order: a call dispatched again with
|
|
163
|
+
* its resolved wait returns the answer recorded there; a continued child is checked to be one this
|
|
164
|
+
* thread created; a task this call already opened is waited for, or its recorded answer or receipt
|
|
165
|
+
* returned, before anything else is decided; otherwise the route is checked, a new role child
|
|
166
|
+
* refused if its role names a tool that is not registered, a start refused at the chain limit, a
|
|
167
|
+
* task slot taken, and the task opened by one write that queues its input with its `started` row
|
|
168
|
+
* and the request's own `rows`, creating the child on its target or continuing it. Then a blocking
|
|
169
|
+
* call suspends on the task (`waitFor`), and a background call returns its receipt. Never throws: a
|
|
170
|
+
* failure becomes an error reply. A reply about a child that exists names its `thread_id`; a
|
|
171
|
+
* refusal before one exists names none.
|
|
172
|
+
*/
|
|
173
|
+
delegate(context: InvocationContext, request: DelegationRequest): Promise<ToolReply>;
|
|
174
|
+
/** Keeps `start` among the starts in flight until it settles, for shutdown to join. */
|
|
175
|
+
private track;
|
|
176
|
+
/**
|
|
177
|
+
* Registers an owner of assignment-origin tasks: the one way an owner's assignment opens a task
|
|
178
|
+
* on a child and is let run, through the same admission, slots and checks as a call. Its
|
|
179
|
+
* `authorize` is asked inside every write that opens one of its tasks and whenever core asks
|
|
180
|
+
* whether such a task may run; a task whose owner has no live registration is held. Its
|
|
181
|
+
* `settled` is told when one of its tasks settles. One live registration per name; disposing the
|
|
182
|
+
* handle withdraws it, refusing its starts still in flight inside their writes.
|
|
183
|
+
*/
|
|
184
|
+
registerOwner(owner: AssignmentOwner): AssignmentOwnerHandle;
|
|
185
|
+
/** Asks core to evaluate again every child whose latest task `owner` assigned. */
|
|
186
|
+
private ownerChanged;
|
|
187
|
+
/**
|
|
188
|
+
* An owner's start, adapted into the one admission with its registration as the authority: the
|
|
189
|
+
* task and child ids derive from the request, so a repeat finds what it opened. Refused (`hold`)
|
|
190
|
+
* once the registration is withdrawn or shutdown has begun; a start already in flight then is
|
|
191
|
+
* joined by shutdown.
|
|
192
|
+
*/
|
|
193
|
+
private startAssignment;
|
|
194
|
+
/** Task `task.taskId` as its child records it, for the owner that assigned it; `null` when that owner assigned no such task. */
|
|
195
|
+
private outcome;
|
|
196
|
+
/**
|
|
197
|
+
* The latest task of each thread the filter names, from the catalog, in spawn order. `under` names every thread created under
|
|
198
|
+
* that one at any depth, and never that one itself, unlike `ctx.threads.list({ under })`: its own
|
|
199
|
+
* task is its caller's to read. `callerThreadId` names the threads that one created. A thread with
|
|
200
|
+
* no task is not listed. An older task than a thread's latest has settled, and is read from its
|
|
201
|
+
* child's rows.
|
|
202
|
+
*/
|
|
203
|
+
tasks(filter: TaskFilter): TaskEntry[];
|
|
204
|
+
/**
|
|
205
|
+
* The tasks a stop of everything under `threadId` stops: those open, still draining a late turn
|
|
206
|
+
* after they settled, or still being cleaned up after a stop. A task whose state cannot be read is
|
|
207
|
+
* not one, since what to stop of it is unknown.
|
|
208
|
+
*/
|
|
209
|
+
stopTargets(threadId: string): TaskRef[];
|
|
210
|
+
/**
|
|
211
|
+
* The rows of a stop obligation over everything under the thread a `cancel` is written on, for
|
|
212
|
+
* that cancel's `rows`: its targets, `stopTargets` read inside the write, and from that write no
|
|
213
|
+
* target, nothing under one, and no call of the run the cancel cuts short opens new work. The
|
|
214
|
+
* service then stops each target, and acknowledges the obligation once they are all quiet; one a
|
|
215
|
+
* crash left outstanding is carried out again by the next startup's repair. No rows when
|
|
216
|
+
* there is nothing to stop.
|
|
217
|
+
*/
|
|
218
|
+
stopObligationRows(reason: string): (threadId: string) => AppendEntry<'ext'>[];
|
|
219
|
+
/**
|
|
220
|
+
* Carries out again every stop obligation still outstanding on `threadId`, resuming each target's
|
|
221
|
+
* cleanup, as the startup repair does: what a host that composed one into a cancel asks for when
|
|
222
|
+
* it retries that stop, since an obligation whose targets were not yet quiet when it was carried
|
|
223
|
+
* out stays outstanding until something drives it again. Resolves once the stops have landed; the
|
|
224
|
+
* acknowledgement follows once every target is quiet.
|
|
225
|
+
*/
|
|
226
|
+
retryStops(threadId: string): Promise<void>;
|
|
227
|
+
/**
|
|
228
|
+
* `read_agent`'s read of tasks the calling thread started: where each stands now, or a durable
|
|
229
|
+
* wait for the first of these: a named task ended (`settled`); with `activity`, a named child
|
|
230
|
+
* recorded anything; nothing can advance a named open task (`no_progress`, saying why each stands
|
|
231
|
+
* still); the deadline. It reads at once with no wait asked, when one of them holds already, or
|
|
232
|
+
* when the caller's chain is at core's limit, since each resolution would open another reactive
|
|
233
|
+
* turn. Dispatched again with its resolved wait, it reads the tasks it named. A read that finds a
|
|
234
|
+
* background task ended returns once the notice its settle queued, or an owed one a crash left
|
|
235
|
+
* unsent, is durable on its caller.
|
|
236
|
+
*/
|
|
237
|
+
read(context: InvocationContext, request: ReadRequest): Promise<ReadOutcome | WaitRequest>;
|
|
238
|
+
/** What a read returns of `tasks`, once the notices of those that ended are durable. */
|
|
239
|
+
private readOutcome;
|
|
240
|
+
/**
|
|
241
|
+
* The startup repair of everything delegations owns, the task constraint's: before any thread
|
|
242
|
+
* runs, every stop whose cleanup a crash left pending is resumed, every task whose call was
|
|
243
|
+
* answered other than by its receipt is ended, the opening results of every caller with an open
|
|
244
|
+
* task are indexed, every stop obligation still outstanding is carried out, every notice owed
|
|
245
|
+
* and unsent is queued, and every delegation wait is tracked again, resolved now when what it
|
|
246
|
+
* waits on happened while the process was down. Resolves once those decisions and writes have
|
|
247
|
+
* landed, not once a cleanup's walk has ended. What cannot be read or written is reported and the
|
|
248
|
+
* rest goes on.
|
|
249
|
+
*/
|
|
250
|
+
private repair;
|
|
251
|
+
/**
|
|
252
|
+
* The repair of what delegations owns at and under `under`, without running anything: resumes
|
|
253
|
+
* every stop whose cleanup is pending there, and walks once more under a stopped task this
|
|
254
|
+
* process has not seen quiet; ends every task whose call was answered other than by its receipt;
|
|
255
|
+
* carries out `under`'s stop obligations; queues every notice owed and unsent. At startup over
|
|
256
|
+
* every root, and again as a caller is admitted, since a cleanup acknowledged before it covered
|
|
257
|
+
* the subtree can have left work beneath. Resolves once those writes have landed.
|
|
258
|
+
*/
|
|
259
|
+
private repairUnder;
|
|
260
|
+
/**
|
|
261
|
+
* Stops a task for good: one write on its child appends `stopped` if the task is still open, and
|
|
262
|
+
* resolves once that is durable; a settled task is left as it settled, and its outcome reported.
|
|
263
|
+
* A run of the child still serving the task is cancelled either way. When the child's latest task is stopped, by
|
|
264
|
+
* this call or before, its cleanup then quiets the child and every thread under it, and writes
|
|
265
|
+
* `stop_cleaned` bottom-up; nobody awaits that, a later stop of the same thread joins it, and a
|
|
266
|
+
* stop of a task whose cleanup a crash left pending resumes it, with no run.
|
|
267
|
+
*/
|
|
268
|
+
stop(taskId: string, options: StopOptions): Promise<StopOutcome>;
|
|
269
|
+
/**
|
|
270
|
+
* One `message_agent` steer: queues `message` into task `taskId` of `childId`, the task the call
|
|
271
|
+
* addresses, for the next step of the run that holds the child, and returns at once; `null` when
|
|
272
|
+
* the call addresses no task. Plugin-facing, as `delegate` is. The steer's input id derives from
|
|
273
|
+
* the call, so a re-dispatch first reports what became of a steer the child already knows, and
|
|
274
|
+
* decides nothing live. One write decides, inside it, that the task is open and that a run of the
|
|
275
|
+
* child takes the input at its next step, and refuses otherwise, naming the outcome or the state.
|
|
276
|
+
* Nothing waits for a run to start: a child whose run is only requested, or still being
|
|
277
|
+
* prepared for admission, is refused, since the caller's own run slot may be what it waits for. A
|
|
278
|
+
* steer never opens a task or asks for a run, and never reaches a child an owner's assignment
|
|
279
|
+
* created: only its owner gives it work.
|
|
280
|
+
*/
|
|
281
|
+
steer(context: InvocationContext, request: {
|
|
282
|
+
readonly childId: string;
|
|
283
|
+
readonly taskId: string | null;
|
|
284
|
+
readonly message: string;
|
|
285
|
+
}): Promise<ToolResultPayloadInput>;
|
|
286
|
+
/**
|
|
287
|
+
* The steer's check, run inside the `send` that queues it, with the inbox target decided: the
|
|
288
|
+
* addressed task is open, which also means its input is queued or claimed, since a discarded one
|
|
289
|
+
* settles it; and the input joins the next step of the run serving the child. A `next-turn`
|
|
290
|
+
* target, which no run takes now, is refused.
|
|
291
|
+
*/
|
|
292
|
+
private steerRows;
|
|
293
|
+
/** Why no run of an open task's child takes a steer now, and what its caller can do. */
|
|
294
|
+
private notRunning;
|
|
295
|
+
/** `delegate`'s call path: the tool invocation adapted into `admit`, and the call answered from what it decided. */
|
|
296
|
+
private runCall;
|
|
297
|
+
/**
|
|
298
|
+
* A recorded background task's call hands it to the owner again, which runs it once the task
|
|
299
|
+
* constraint allows: while the call runs here, which stands in for its receipt until that is
|
|
300
|
+
* durable, and after.
|
|
301
|
+
*/
|
|
302
|
+
private handOff;
|
|
303
|
+
/** The tool the call at `callSeq` named, from its loaded `tool/call` row; `null` when it cannot be read. */
|
|
304
|
+
private toolNameOf;
|
|
305
|
+
/**
|
|
306
|
+
* The one admission and opening of a task, whatever its authority; each outcome is typed by what
|
|
307
|
+
* the starter does next (`Admission`), a cancelled start's a `discard`, checked last inside its
|
|
308
|
+
* write. An
|
|
309
|
+
* owner's start identical to one in flight for the same task joins it, so concurrent starts of
|
|
310
|
+
* one assignment coalesce; a different one waits for it to finish, then replays or conflicts with
|
|
311
|
+
* what it wrote. A call is dispatched once at a time, and its re-dispatch replays.
|
|
312
|
+
*/
|
|
313
|
+
private admit;
|
|
314
|
+
/**
|
|
315
|
+
* One admission. An owner's start whose registration was withdrawn is held. A start whose task
|
|
316
|
+
* its child already records replays it (`replay`): nothing is judged again and no slot is taken.
|
|
317
|
+
* Otherwise its authority decides how the child is reached (`callReach`, `ownerReach`), a call is
|
|
318
|
+
* refused at its caller's chain limit, one of the origin tree's slots is taken (`reserveSlot`), an
|
|
319
|
+
* existing child's last task's notice is queued or found no longer owed, and one write (`open`)
|
|
320
|
+
* creates or continues the child.
|
|
321
|
+
*/
|
|
322
|
+
private admitOnce;
|
|
323
|
+
/**
|
|
324
|
+
* A start finding its task recorded: replayed, taking no slot and reopening nothing, when the
|
|
325
|
+
* recorded origin is the start's own, and for an owner's, its task input and its child's pinned
|
|
326
|
+
* configuration too; a conflict otherwise, never adopted. A call's replay compares its origin
|
|
327
|
+
* alone: the effect the call recorded decides, whatever its arguments would decide now.
|
|
328
|
+
*/
|
|
329
|
+
private replay;
|
|
330
|
+
/**
|
|
331
|
+
* How a call reaches its child, or why it does not: a start's child must not exist yet; a new child
|
|
332
|
+
* is born on the call's fields folded over the route of the turn making the call, resolved here
|
|
333
|
+
* once, a fork on the route at its cut, which must run; a continued child's change is checked here
|
|
334
|
+
* and decided by the write that makes it, against the route it reads then. A new role child is
|
|
335
|
+
* refused if its role names a tool that is not registered.
|
|
336
|
+
*/
|
|
337
|
+
private callReach;
|
|
338
|
+
/**
|
|
339
|
+
* Why what an owner pinned cannot be bound now, or `null`: its route's provider cannot run, a
|
|
340
|
+
* preset it installs or the global agent it names is not registered. A binding that comes back
|
|
341
|
+
* lets the same start through, so each is a `hold`, never a refusal.
|
|
342
|
+
*/
|
|
343
|
+
private unbound;
|
|
344
|
+
/**
|
|
345
|
+
* How an owner's start reaches its participant's child, or why it does not, with no caller route
|
|
346
|
+
* and no chain limit: its assignment's turns are fresh. Its pinned route must run now, else it is
|
|
347
|
+
* held. A child that does not exist is created on exactly the pinned configuration; one that
|
|
348
|
+
* exists is continued only when it is this owner's conversation for this generation under this
|
|
349
|
+
* caller, born exactly so (`birthConflicts`): anything else is a conflict. A pin whose installations
|
|
350
|
+
* are not all defining and named is refused before either.
|
|
351
|
+
*/
|
|
352
|
+
private ownerReach;
|
|
353
|
+
/** What an owner's child is born with: its pin, under delegations' own constraint owner. */
|
|
354
|
+
private pinnedSpec;
|
|
355
|
+
/**
|
|
356
|
+
* Why `childId` was not born as `configuration` pins it, or `null` when it was: its agent, that it
|
|
357
|
+
* is not a fork, and the birth fields core names. The recorded origin is the caller's to check.
|
|
358
|
+
*/
|
|
359
|
+
private birthConflicts;
|
|
360
|
+
/** Task `taskId` as `childId` records it, read while the child is loaded, with its `started` row; `null` when it records none. */
|
|
361
|
+
private recordedTask;
|
|
362
|
+
/**
|
|
363
|
+
* Opens the task: one write queues its input with its `started` row, the assignment's cause and
|
|
364
|
+
* the start's own rows, creating the child with `create`, or continuing it with `send`, a call's
|
|
365
|
+
* fields its route statement. Every check runs inside that write (`admissionCheck`, then for an
|
|
366
|
+
* owner's start its live owner's `authorize`), then the start's rows; any of them vetoing leaves
|
|
367
|
+
* nothing, and the admission says which refused and why. A write that found the task already
|
|
368
|
+
* written, by another start meanwhile, replays it.
|
|
369
|
+
*/
|
|
370
|
+
private open;
|
|
371
|
+
/**
|
|
372
|
+
* The one creation of a call's child, by its target: on a global agent; on a role, recorded as
|
|
373
|
+
* the child's defining installation of the `role` preset; or a fork of the calling thread cut at
|
|
374
|
+
* the request that produced the call. A replayed start never gets here: it finds the task it
|
|
375
|
+
* opened first, whatever its target has become.
|
|
376
|
+
*/
|
|
377
|
+
private createChild;
|
|
378
|
+
/**
|
|
379
|
+
* An owner's recheck inside the write that opens its task, `null` for a call's start: its
|
|
380
|
+
* registration is still live, what its pin names is still registered (`unbound`), and its
|
|
381
|
+
* `authorize` allows the assignment, typed as it says otherwise. Its starts still in flight when it is withdrawn are held here.
|
|
382
|
+
*/
|
|
383
|
+
private ownerCheck;
|
|
384
|
+
/** An owner's task as its owner judges it, from the origin it records or will record. */
|
|
385
|
+
private assignmentTask;
|
|
386
|
+
/**
|
|
387
|
+
* The checks of the write that opens a task, run inside it, `null` when the task may open, else
|
|
388
|
+
* the admission refused: no thread above the caller is being stopped (`discard`) or unreadable
|
|
389
|
+
* (`hold`); no stop obligation covers the start (`discard`); a delegated caller's own task is
|
|
390
|
+
* still open; and a child that exists can take another task ({@link continuation}). A new child
|
|
391
|
+
* has no folds yet, so its creation reads the caller and the catalog only.
|
|
392
|
+
*/
|
|
393
|
+
private admissionCheck;
|
|
394
|
+
/**
|
|
395
|
+
* Whether `threadId`, a thread that exists, can take another task now, as the write that would open
|
|
396
|
+
* one decides it (`admissionCheck`): `null` when it can; a `refusal`, durable for this thread, when
|
|
397
|
+
* it is not one delegations manages, a person's cancel holds it, it stopped mid-work, or something
|
|
398
|
+
* it or a thread under it started has an unknown end; a `wait` on the predecessor while its own task
|
|
399
|
+
* is open or being cleaned up after, a stop's walk holds it, an earlier run of it is still pending
|
|
400
|
+
* or a command is still ending; a `hold` while its task state cannot be read. What an owner reads,
|
|
401
|
+
* before asking for a continuation, to know whether its participant's conversation can be continued
|
|
402
|
+
* or must be replaced. Reads the thread's folds: the caller holds it loaded.
|
|
403
|
+
*/
|
|
404
|
+
continuation(threadId: string): AdmissionRefused | null;
|
|
405
|
+
/**
|
|
406
|
+
* Why nothing may start or be driven under `threadId`: it has a stop still being cleaned up after,
|
|
407
|
+
* or a thread above it has, or a thread above it has its latest task stopped, cleaned up after or
|
|
408
|
+
* not, since nothing under a stopped task is anyone's to run, whatever a cleanup acknowledged
|
|
409
|
+
* before it covered the subtree, or a thread above it has a task state that cannot be read.
|
|
410
|
+
*/
|
|
411
|
+
private stoppedAbove;
|
|
412
|
+
/**
|
|
413
|
+
* Why a stop obligation keeps a task that the row at `seq` of `callerId` opens from opening, or
|
|
414
|
+
* `null`: the caller is a target of an obligation outstanding on its origin root, or under one; or
|
|
415
|
+
* the caller is that root and the row (a call, or the row granting an assignment) came before the
|
|
416
|
+
* obligation, in the run it cancelled. A call a later message brings opens independently.
|
|
417
|
+
*/
|
|
418
|
+
private obligationOver;
|
|
419
|
+
/** Whether `obligation` names `threadId`, or a thread above it. */
|
|
420
|
+
private covers;
|
|
421
|
+
/** Whether a stop obligation outstanding on `childId`'s origin root names it, or a thread above it. */
|
|
422
|
+
private obligated;
|
|
423
|
+
/**
|
|
424
|
+
* Takes one of the task slots of the caller's origin root for a task until its `started` row is
|
|
425
|
+
* durable, or says why none is free: a `wait` on capacity, never queued, so a tree of tasks
|
|
426
|
+
* waiting on each other cannot deadlock on capacity; one pool, whatever a task's authority. Each origin tree has its own `maxOpenTasks`, so conversations
|
|
427
|
+
* in one journal never take each other's. Decided synchronously, so parallel calls in one step are
|
|
428
|
+
* admitted up to the limit exactly. Fails closed: while a task state under the root cannot be
|
|
429
|
+
* read, or the root cannot be found, how many slots are in use is unknown, and nothing new is
|
|
430
|
+
* admitted (a `hold`).
|
|
431
|
+
*/
|
|
432
|
+
private reserveSlot;
|
|
433
|
+
/**
|
|
434
|
+
* Every task holding a slot of the origin tree under `rootId`, blocking or background: one
|
|
435
|
+
* reserved by a call whose `started` row is not durable yet; an open one, blocked ones included; a
|
|
436
|
+
* settled one whose run still drains; and a stopped one whose cleanup is pending, since its old
|
|
437
|
+
* work may still run. Also the threads under it whose task state cannot be read, whose slots are
|
|
438
|
+
* unknown. A task belongs to the tree its caller is in.
|
|
439
|
+
*/
|
|
440
|
+
private slotHolders;
|
|
441
|
+
/** The latest task of each thread among `summaries` that has one, as `tasks()` lists it. */
|
|
442
|
+
private entriesOf;
|
|
443
|
+
/**
|
|
444
|
+
* The task constraint's verdict on a delegated child's pending run, read synchronously from the
|
|
445
|
+
* catalog and this process: the task predicate (`constraint.ts`) over the child's latest task,
|
|
446
|
+
* under the authority its origin records: a call's, where its opening call stands; an owner's
|
|
447
|
+
* assignment's, its live owner's verdict (`ownerVerdict`). Every child takes a start slot of its own.
|
|
448
|
+
*/
|
|
449
|
+
private evaluate;
|
|
450
|
+
/**
|
|
451
|
+
* Whether an owner's task may run, by its live owner: its `authorize` in `running`, anything but
|
|
452
|
+
* `allow` a hold; held too while no owner is registered under the name its origin records, or
|
|
453
|
+
* when the owner cannot judge it, which is reported.
|
|
454
|
+
*/
|
|
455
|
+
private ownerVerdict;
|
|
456
|
+
/** What answered the task's opening call, as far as the index knows. */
|
|
457
|
+
private openingOf;
|
|
458
|
+
/**
|
|
459
|
+
* Whether the opening result of `taskId` can still be read: the task is `childId`'s latest and open
|
|
460
|
+
* or draining, or its state cannot be read, so nothing says it is not.
|
|
461
|
+
*/
|
|
462
|
+
private openingNeeded;
|
|
463
|
+
/** Keeps `result` for `taskId`, which any of `childIds` may hold, unless none of them still reads it. */
|
|
464
|
+
private rememberOpening;
|
|
465
|
+
/** Drops `childId`'s results its rows made unneeded: its task ended, was succeeded, or its run settled. */
|
|
466
|
+
private evictOpening;
|
|
467
|
+
/**
|
|
468
|
+
* The repair half of the index: reads the loaded caller's rows from its oldest open task's call,
|
|
469
|
+
* once per process, recording each open task's receipt or other result. Rows written after it
|
|
470
|
+
* reach the index through the result listener.
|
|
471
|
+
*/
|
|
472
|
+
private indexCaller;
|
|
473
|
+
/** The child whose latest task is `taskId`, from the catalog. */
|
|
474
|
+
private childHolding;
|
|
475
|
+
/**
|
|
476
|
+
* The child holding an older task, whose rows record it: one of its caller's children, for a
|
|
477
|
+
* call's task; for any other, one of the children an owner's assignment created, a persistent
|
|
478
|
+
* participant's earlier tasks included.
|
|
479
|
+
*/
|
|
480
|
+
private findChild;
|
|
481
|
+
/**
|
|
482
|
+
* Carries out a stop obligation of `threadId`, once at a time: stops each target as the host, which
|
|
483
|
+
* aborts its drive and starts or joins the walk over its subtree, then acknowledges it. Each stop's
|
|
484
|
+
* write is queued before this returns. Resolves once the stops are durable; the acknowledgement
|
|
485
|
+
* follows, unawaited.
|
|
486
|
+
*/
|
|
487
|
+
private carryOut;
|
|
488
|
+
/**
|
|
489
|
+
* Writes `stop_completed` once every target is quiet: its drive ended and the walk over its subtree
|
|
490
|
+
* finished with its stop acknowledged. A target left being cleaned up after, by a walk that failed,
|
|
491
|
+
* leaves the obligation outstanding for the next `resume` over the thread.
|
|
492
|
+
*/
|
|
493
|
+
private acknowledgeObligation;
|
|
494
|
+
/** Resolves once the run that served `task`, if still pending, is held or settled. */
|
|
495
|
+
private runStopped;
|
|
496
|
+
/**
|
|
497
|
+
* Hands every row to the wait resolver, a turn's end and a receipt to the notice owner, and ends a task whose opening call was
|
|
498
|
+
* answered other than by its receipt. The stop is asked for here, synchronously, and the cleanup
|
|
499
|
+
* owner queues its write before returning, so it lands before anything the caller writes after its
|
|
500
|
+
* result.
|
|
501
|
+
*/
|
|
502
|
+
private onRow;
|
|
503
|
+
/**
|
|
504
|
+
* A person's cancel of an owner's child: the task fold stopped its task from the cancel row itself
|
|
505
|
+
* (`delegationTasks`), its cleanup pending. Here, in the cancel's listener, that cleanup starts,
|
|
506
|
+
* through the one stop, which finds the task stopped and writes nothing; a crash before it leaves
|
|
507
|
+
* the cleanup pending, which repair resumes (`StopCleanup.resume`). A call's task is held for its
|
|
508
|
+
* caller instead.
|
|
509
|
+
*/
|
|
510
|
+
private personCancelled;
|
|
511
|
+
/**
|
|
512
|
+
* Tells the owner of `threadId`'s latest task that it settled, once in this process, when it was
|
|
513
|
+
* an owner's assignment that has: the owner reads its outcome, a stop through `stop_agent` or a
|
|
514
|
+
* host's included, which its own scheduling would otherwise never learn of.
|
|
515
|
+
*/
|
|
516
|
+
private tellSettled;
|
|
517
|
+
/**
|
|
518
|
+
* The children that may hold the task the call at `callSeq` opened, still open or settled with its
|
|
519
|
+
* run still draining (a cancel answered the call waiting on that run), matched by the call, never by its provider's id: a start tool's child, named after the call; or, only for a `message_agent` call, read from the loaded
|
|
520
|
+
* caller, the caller's child whose latest task it is, or, when none reads so, every child whose
|
|
521
|
+
* task state cannot be read, which the stop's own write then checks. A result of any other tool
|
|
522
|
+
* costs one catalog lookup.
|
|
523
|
+
*/
|
|
524
|
+
private childrenHolding;
|
|
525
|
+
private onRunEvent;
|
|
526
|
+
/**
|
|
527
|
+
* One caller's repair at startup: indexes its opening calls' results with one scan of its rows,
|
|
528
|
+
* and ends every task whose call has a result other than its receipt, what a crash between a
|
|
529
|
+
* result and its stop left behind. Resolves once the stops it wrote landed.
|
|
530
|
+
*/
|
|
531
|
+
private reconcile;
|
|
532
|
+
/**
|
|
533
|
+
* The caller's children's open tasks, and settled ones whose run still drains, by the call that
|
|
534
|
+
* opened each, from the catalog or their rows: those a result of their opening call ends.
|
|
535
|
+
*/
|
|
536
|
+
private openTasksOf;
|
|
537
|
+
/**
|
|
538
|
+
* A child's latest task from its own rows, while it is open or settled with the run serving it
|
|
539
|
+
* still pending, draining; `null` otherwise.
|
|
540
|
+
*/
|
|
541
|
+
private openTaskOf;
|
|
542
|
+
/**
|
|
543
|
+
* Stops the wait resolver deciding and lets each decision under way land; lets each call in flight,
|
|
544
|
+
* opening its task, be answered on its aborted turn, so a result other than its receipt or its
|
|
545
|
+
* wait stops its task, and each owner's start in flight finish, a new one being refused; then
|
|
546
|
+
* waits for the stops and their cleanups while the journal still takes their rows. Tasks whose calls wait durably stay open, as
|
|
547
|
+
* background tasks do, their runs pending for the next startup, which decides by its policy. What
|
|
548
|
+
* it cannot finish waits for the next startup's repair.
|
|
549
|
+
*/
|
|
550
|
+
private shutdown;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* The latest task of each of `summaries`' threads, read without loading any (`readTask`), in their order:
|
|
554
|
+
* what `tasks()` lists, readable whether or not the service is mounted. A thread with no task is
|
|
555
|
+
* not listed; one delegations governs whose task state the catalog lacks is `unavailable`.
|
|
556
|
+
*/
|
|
557
|
+
export declare function taskEntries(journal: PluginJournal, summaries: readonly ThreadSummary[]): TaskEntry[];
|
|
558
|
+
/**
|
|
559
|
+
* Every task under `threadId` at any depth, never its own, from the catalog alone: `tasks({ under })`,
|
|
560
|
+
* the read a quiescence or cleanup check makes before it certifies the thread quiet, whether or not
|
|
561
|
+
* the service is mounted, so a task it cannot read is never taken for none.
|
|
562
|
+
*/
|
|
563
|
+
export declare function tasksUnder(journal: PluginJournal, threadId: string): TaskEntry[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import { type TaskRef, type TaskState } from './record.js';
|
|
3
|
+
import { type DelegationOutcome } from './request.js';
|
|
4
|
+
/** Where one task stands when a wait returns, and once it settled, what its caller is told. */
|
|
5
|
+
export type TaskStanding = TaskRef & {
|
|
6
|
+
readonly state: TaskState | 'unavailable';
|
|
7
|
+
readonly outcome: DelegationOutcome | null;
|
|
8
|
+
};
|
|
9
|
+
/** A named task's state from the catalog: a task that is not its child's latest has settled. */
|
|
10
|
+
export declare function taskState(ctx: Context, task: TaskRef): TaskState | 'unavailable' | 'superseded';
|
|
11
|
+
/** The named tasks that are not open, with their state. */
|
|
12
|
+
export declare function endedTasks(ctx: Context, tasks: readonly TaskRef[]): {
|
|
13
|
+
task: TaskRef;
|
|
14
|
+
state: "superseded" | "unavailable" | TaskState;
|
|
15
|
+
}[];
|
|
16
|
+
/** Where a task stands as a read returns it, with what its caller is told once it settled. */
|
|
17
|
+
export declare function taskStanding(ctx: Context, task: TaskRef, state: TaskState | 'unavailable' | 'superseded'): Promise<TaskStanding>;
|
|
18
|
+
/** Why a task's child is not running, for a caller told that nothing advances it. */
|
|
19
|
+
export declare function whyStill(ctx: Context, task: TaskRef): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import type { DelegationsService } from './service.js';
|
|
3
|
+
/**
|
|
4
|
+
* The sub-agent-waits rule: a delegated thread cannot answer while tasks it started are open, and
|
|
5
|
+
* what it leaves open when its turn settles is stopped, since its caller cannot see those tasks and
|
|
6
|
+
* may never follow up.
|
|
7
|
+
*
|
|
8
|
+
* A settled background task whose notice is still owed, unspent and unclaimed counts as open, so a
|
|
9
|
+
* child that settles just before the check sends the caller round once to read its notice.
|
|
10
|
+
*
|
|
11
|
+
* The check sends the model back at once, naming the open tasks, and never waits: waiting and
|
|
12
|
+
* any-of belong to `read_agent`. A child whose task state cannot be read rejects
|
|
13
|
+
* the answer with the error. The backstop stops the thread's open tasks at every turn ending that
|
|
14
|
+
* would settle a task (`settlingEnding`), and at a failed run with no successor, since after either
|
|
15
|
+
* its caller may never follow up on what it started; any other ending keeps them, since the next
|
|
16
|
+
* admission drives them again. It keys off the
|
|
17
|
+
* ending, not off the thread's own task: the task fold ignores endings before its input is claimed.
|
|
18
|
+
* A thread delegations does not manage (a root, or one made by hand), which no caller waits on,
|
|
19
|
+
* keeps its tasks across its answers.
|
|
20
|
+
*/
|
|
21
|
+
export declare function waitForOwnTasks(ctx: Context, service: DelegationsService): void;
|