@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The application-facing API: mount the core on a root, compose providers, tools, agents and
|
|
3
|
+
* presets, and drive threads through `ctx.threads`.
|
|
4
|
+
*
|
|
5
|
+
* The package has a few doors and nothing else: this one for applications, `@leuduan/lagent/plugin`
|
|
6
|
+
* for plugin authors, `@leuduan/lagent/llm` for the model and provider contracts,
|
|
7
|
+
* `@leuduan/lagent/providers` for the shipped providers, `@leuduan/lagent/sqlite` for the SQLite store
|
|
8
|
+
* (which needs `node:sqlite`), `@leuduan/lagent/models` for the serialized shapes, one
|
|
9
|
+
* `@leuduan/lagent/plugins/<name>` per shipped plugin, and `@leuduan/lagent/testing` for test doubles. A
|
|
10
|
+
* value lives on one door: this one holds what an application constructs (the core, the memory
|
|
11
|
+
* store), catches (the errors) or composes from `presets/`; a shipped plugin's exports, its presets
|
|
12
|
+
* included, are on its own door. The core's services are reached as `ctx.<name>`, so their classes
|
|
13
|
+
* are exported as types only. Keep this
|
|
14
|
+
* entry point small enough that an embedder can understand it without first learning the engine
|
|
15
|
+
* internals.
|
|
16
|
+
*/
|
|
17
|
+
export * from './context.js';
|
|
18
|
+
export { core } from './services/core.js';
|
|
19
|
+
export type { CoreConfig } from './services/core.js';
|
|
20
|
+
export type { AgentResolution, AgentsService } from './services/agents.js';
|
|
21
|
+
export type { ToolsService } from './services/tools.js';
|
|
22
|
+
export { registerProvider } from './services/llm.js';
|
|
23
|
+
export type { LlmService, RetryPolicy } from './services/llm.js';
|
|
24
|
+
export type { PromptsService } from './services/prompts.js';
|
|
25
|
+
export { registerPreset } from './services/presets.js';
|
|
26
|
+
export type { ConfigurationPlan, InitialInstallationInput, InstallationInput, PresetsService, } from './services/presets.js';
|
|
27
|
+
export { UNCONFINED_LAUNCH } from './services/launches.js';
|
|
28
|
+
export type { LaunchesService, Launched, LaunchHandle, LaunchHandler, LaunchOptions, LaunchProvenance, LaunchRequest, PreparedLaunch, } from './services/launches.js';
|
|
29
|
+
export type { ThreadDirsConfig, ThreadDirsService } from './services/threadDirs.js';
|
|
30
|
+
export type { ConfigurationChange, ConfigurationResult, RetainOptions, RetainedMembers, Retention, ThreadFilter, Threads, ThreadsConfig, ThreadsService, } from './services/threads.js';
|
|
31
|
+
export type { MissingDetail, OwnerHandle, OwnerReadiness, OwnerRegistration, StartOptions, StartupPolicy, ThreadInspection, WaitResolution, WaitValue, } from './services/owner.js';
|
|
32
|
+
export { heldOrSettled, UnknownRunError, waitForRun } from './services/runEvents.js';
|
|
33
|
+
export type { RunEvent, RunSource, RunState } from './services/runEvents.js';
|
|
34
|
+
export type { BirthChoice, BirthInput, CreateThreadOptions, ForkCut, ForkOptions, Opening, Reuse, } from './services/birth.js';
|
|
35
|
+
export { Thread } from './services/thread.js';
|
|
36
|
+
export type { ThreadView } from './services/threadView.js';
|
|
37
|
+
export type { CancelOptions, ConfirmationAnswer } from './services/thread.js';
|
|
38
|
+
export { repositoryReadRoots } from './sys/git.js';
|
|
39
|
+
export { buildSpawnEnvironment, CODEX_ENVIRONMENT_POLICY, NON_INTERACTIVE_ENVIRONMENT, resolveTrustedPrograms, } from './sys/environment.js';
|
|
40
|
+
export type { SpawnEnvironmentPolicy, TrustedPrograms } from './sys/environment.js';
|
|
41
|
+
export type { ChainStanding, CompactOptions, ConfirmationState, ForkPoint, InputFate, InstallationRecord, ModelSelection, ReplacementRule, RouteStatement, Target, ConstraintAnswer, Hold, HoldBasis, HoldReason, BirthConflict, BirthSpec, ForkOpening, FreshOpening, Refusal, RowRef, RunOutcome, RowsResult, RowsWrite, InputReceipt, SendOptions, SendOutcome, StreamedChunk, SurfacePrepareOutcome, TurnLimits, WaitDeclaration, WaitEntry, WithdrawOptions, WithdrawOutcome, WithdrawRows, } from './loop/index.js';
|
|
42
|
+
export { AuxiliaryRefusedError, BirthConflictError, ConfirmationAnsweredError, CorruptHistoryError, DepthExceededError, ForkCutError, ReplacementRefusedError, RestoreFailedError, RouteConflictError, RouteUnavailableError, ThreadActivatingError, ThreadBusyError, ThreadUnsettledError, UnknownAgentError, UnknownThreadError, WriteRefusedError, } from './loop/index.js';
|
|
43
|
+
export { CorruptJournalError, forkChain, IncompatibleJournalError, InvalidOriginError, JournalBusyError, JournalCommitError, StoreBusyError, } from './journal/index.js';
|
|
44
|
+
export type { AppendOutcome, Attempt, ForkLink, InvalidOriginReason, JournalStore, ThreadIndexEntry, ThreadSummaryCore, WriterLease, } from './journal/index.js';
|
|
45
|
+
export { MemoryJournalStore } from './plugins/store/memory.js';
|
|
46
|
+
export { base, codexPreset } from './presets/index.js';
|
|
47
|
+
export { COMMUNICATION_GUIDANCE_PROMPT, FORMATTING_PROMPT } from './presets/prompts.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import{d as L}from"./chunks/3LQHQRIU.js";import{a as S}from"./chunks/ADHERZLW.js";import{a as N,b as A}from"./chunks/BM3S37EZ.js";import{a as F}from"./chunks/TOOIB6J2.js";import{c as d}from"./chunks/X65X4KP5.js";import{a as B}from"./chunks/IJ2WNMD5.js";import{a as s,b as x,c as i}from"./chunks/ENWFSU27.js";import{a as Me,b as Ue,c as Ye,d as Ke}from"./chunks/2O7ZGEIT.js";import{a as C,b as m,c as D,d as f}from"./chunks/P5ZHHOOM.js";import"./chunks/6ECI2GGV.js";import{e as W}from"./chunks/UCTEU62F.js";import{b as Y}from"./chunks/UC3FVVJ2.js";import"./chunks/4XVRUSCQ.js";import{a as G}from"./chunks/O4PPOM5Z.js";import{c as Fe}from"./chunks/OVZFGILJ.js";import{t as U}from"./chunks/EGZI4XQX.js";import{b as De,c as We,d as Ge}from"./chunks/UD3VJER6.js";import{b as v,c as M}from"./chunks/SGGMBSBA.js";import{b as Ce,c as I}from"./chunks/3QCW4WDJ.js";import"./chunks/C5LYCXJG.js";import"./chunks/J5S4URAW.js";import{e as w}from"./chunks/G74AGRAJ.js";import"./chunks/SL2YLB2F.js";import{b as Be,c as je,d as Ve,f as qe}from"./chunks/JPZFKSWT.js";import{b as p}from"./chunks/RK3VP2Q4.js";import"./chunks/74HKUGRR.js";import"./chunks/QMMLQJBS.js";import"./chunks/YIR5MYGU.js";import{a as P}from"./chunks/L3N4FIEN.js";import"./chunks/NAOUTU7A.js";import"./chunks/UKXMCHHT.js";import"./chunks/WUUKTSRT.js";import"./chunks/NDIM7MEW.js";import"./chunks/34KW6VNQ.js";import"./chunks/PUSUPTAT.js";import"./chunks/CDQG7RKA.js";import"./chunks/G6RXC3AL.js";import{b as Se}from"./chunks/GQGNVSKB.js";import"./chunks/DXFXAYDN.js";import"./chunks/DRYAN665.js";import"./chunks/2OSESBIL.js";import{A as ve,B as Pe,C as Ie,D as xe,E as Ne,H as Ae,I as Le,r as we,s as ye,t as ke,u as Oe,v as Ee,w as Te,x as be,y as Re,z as _e}from"./chunks/YLNJXQ3Z.js";import"./chunks/DDANMY45.js";import{b as ce,c as le,l as ue,m as ge,q as pe,u as me,x as fe}from"./chunks/37YOGDGY.js";import{a as _}from"./chunks/KESCTXGO.js";import"./chunks/TYTQRLTX.js";import"./chunks/D7E6EWIE.js";var y=["edit_files"],j={name:"main",basePrompt:"You are a helpful AI assistant."};var He={name:"lagent:base",inject:["agents"],async apply(e){v(e,j),await e.plugin(S),await e.plugin(L),await e.plugin(N,{confirm:A})}};import{z as R}from"zod";var V="You are a coding agent working in the user's workspace. You and the user share its files: with the tools you are given, you read, search and change them and run commands there. Your job is to carry the user's task through to a result they can review.",q=`- Carry the task through to the end within the turn: understand it, make the change, validate it, and report. Do not stop at analysis, a proposal or a half-finished fix.
|
|
2
|
+
- Unless the user asks a question, asks for a plan or a review, or is brainstorming, assume they want the change made, and make it rather than describe it.
|
|
3
|
+
- When you hit a blocker, try to work through it yourself first. Ask the user, with ask_question, only when the answer changes what you would do and you cannot find it out yourself.
|
|
4
|
+
- Do not guess or make up an answer: read the code, run the command, look it up.
|
|
5
|
+
- Messages may arrive while you work. When they conflict, the newest one steers; otherwise honour every request since your last answer, and make sure your final answer responds to the newest.`,K='Before a group of related tool calls, write one short line saying what you are about to do, and after the first, how it follows from what you found; for example "The loader is in src/config.ts; now checking its callers." Group related calls under one line instead of narrating each, and write none before a trivial read. Before a large edit, say what you are changing.',k=`- Read the code you are about to change, and let it show you how to change it: follow the repository's existing patterns, helpers and style.
|
|
6
|
+
- Fix the problem at its root cause rather than patching the symptom, and keep the solution as simple as the problem allows. Add an abstraction only when it removes real complexity.
|
|
7
|
+
- Follow the AGENTS.md files you are told for the files you touch. Each governs its directory's tree and the deeper one wins on a conflict; the user's direct instructions beat any of them. Working below your working directory, look for AGENTS.md there too.
|
|
8
|
+
- Keep the change to what the task needs. Do not fix unrelated bugs or failing tests; mention them in your final answer.
|
|
9
|
+
- Update the documentation your change makes wrong.
|
|
10
|
+
- Default to ASCII in files, and add a comment only where the code does not explain itself.
|
|
11
|
+
- Never add copyright or licence headers unless asked. Do not commit or create branches unless asked.`,c="- Make every change to a file with edit_files: creating, updating, moving or deleting it. Never write a file through a command, such as a shell heredoc, `echo >`, `sed -i` or a script; running the project's own formatter or code generator is fine.\n- Read the lines you change before editing them: an edit's old text must match the file as it is now.\n- edit_files answers with the diff it applied. Trust it, and do not re-read the file to check.\n- If an edit is interrupted, or applies only some of its files, re-read the files it named before editing them again.",l="The worktree may hold changes you did not make. Assume they are the user's, and never revert them unless asked.\n- Leave changes unrelated to your task alone.\n- In files you are working on, read the changes carefully and work with them.\n- Never run `git reset --hard`, `git checkout --`, `git restore`, `git clean` or anything else that discards changes unless the user clearly asked for that operation; when the request is ambiguous, ask first.\n- If those changes make your task impossible, ask the user how to proceed.",O=`- When the project can be built or tested, use that to check your work. Start with the tests closest to what you changed, then widen as you gain confidence.
|
|
12
|
+
- Let coverage scale with risk: focused for a narrow change, broader when the change touches shared behaviour, contracts between modules, or what users do.
|
|
13
|
+
- Add a test where the codebase has an obvious place for one. Do not add a test suite or a formatter to a repository that has none, and do not write tests that only mirror the implementation.
|
|
14
|
+
- Run the project's formatter and linter on the files you changed when it has them.
|
|
15
|
+
- A failure your change did not cause is not yours to fix: mention it.`,H=`- Independent tool calls can run in parallel: make every call that does not need another's result in the same response. When a call depends on an earlier one's output, wait for that result first.
|
|
16
|
+
- Hand work to a sub-agent when you do not need to see its steps, so your conversation keeps only its outcome:
|
|
17
|
+
- explore: find and understand things in the workspace, such as where something is handled, how a module works or what a change would affect. It only reads.
|
|
18
|
+
- delegate: a self-contained task that needs nothing from this conversation but the task you write, including one that changes files or runs commands, such as updating every call site of a function and making the tests pass, or finding out why a command fails and fixing it.
|
|
19
|
+
- fork: a task of several steps that needs your context: answering a question by experiment, working out why something fails, checking whether an approach works.
|
|
20
|
+
- review: a second reading of a change, or of any code, when the user asks for one or a change is large or subtle enough that one helps; never as a routine step. Its findings are evidence: weigh each against the code before acting on it. To get them fixed, delegate the findings with their evidence. Check the repository's status before asking for a review of uncommitted work: an empty change still starts a reviewer.
|
|
21
|
+
- Work directly when one or two calls will do, when you need the raw output yourself (the exact lines you are about to edit, command output you must reason over), when the next step waits on a decision, or when the answer is already in the conversation.
|
|
22
|
+
- Give independent parts separate calls in one response, so they run concurrently. Write each task as an outcome: what to find out or do, and what to return, such as "the function that validates tokens, with its file and line" rather than "look at the auth code". Explore, delegate and review see only the task you write; a fork sees your conversation too. Either way, name the target (for a review, "the uncommitted changes", "the current work against main", "commit abc123" or the code to read), the outcome you expect, the constraints, and which files you or other sub-agents are changing and which commands share outputs, such as test discovery, a build directory or a server port.
|
|
23
|
+
- Start a review only after the work it reviews has settled, in a later response than the calls that make that work: a waiting call does not stop the others in its response.
|
|
24
|
+
- In a forked task, do the work yourself rather than forking again.`,E="A long task can outgrow your context. The conversation may then be compacted: a checkpoint stands in for the messages it condensed. Compaction does not end the task. Continue from the checkpoint without restarting or redoing finished work, and keep the original objective together with every correction the user made since.",J="When you need the exact text of something condensed, such as the user's wording or a command's output, read it back with history_read or find it with history_search rather than reconstructing it.",u=`- Your file tools read and change files in the working directory and the application data directory, and also read the read roots your workspace notice names. Do not go looking through the rest of the machine, such as other projects or the home directory, unless the task needs it.
|
|
25
|
+
- Avoid destructive or irreversible commands, such as deleting what you did not create, force-pushing or dropping data, unless the user asked for them.
|
|
26
|
+
- Do not push, publish, deploy or send anything to others unless asked.
|
|
27
|
+
- Do not search for, print or copy out secrets such as credentials, API keys and tokens.`,$=`- For a task with no prior context, where the user is starting something new, be ambitious and show creativity in the implementation.
|
|
28
|
+
- In an existing codebase, do exactly what the user asks with surgical precision. Treat the surrounding code with respect and do not overstep, for example by renaming files or variables unnecessarily, while still being proactive enough to finish the task well.
|
|
29
|
+
- Use judicious initiative to choose the right level of detail and complexity for the user's needs: high-value, creative touches when the scope is vague; surgical, targeted work when it is tightly specified; no gold-plating either way.`,X=`- Lead with the outcome, then give what the user needs to trust it and act on it, like a concise teammate handing off work.
|
|
30
|
+
- Size the answer by the change: a sentence or two for a small fix, a short walkthrough grouped by theme for a large one, a plain conversational reply to a casual question. Even a large one keeps to the points that matter, well under fifty lines.
|
|
31
|
+
- Say what you ran to validate the work, and what you did not run and why.
|
|
32
|
+
- Point to code as \`path:line\`, with the path relative to the working directory and a single line rather than a range.
|
|
33
|
+
- Do not paste before-and-after code or the contents of files you wrote: the user has the files. Never ask them to save or copy anything.
|
|
34
|
+
- Mention the problems you noticed but left alone, and anything you could not do.
|
|
35
|
+
- When there is an obvious next step, such as running the wider test suite, committing, or building the next piece, offer it as a short question rather than doing it unasked.`,T=`- Write in English unless the user asks for another language.
|
|
36
|
+
- Be direct and concise, and state the assumptions you made. Leave out flattery, filler and needless apologies.
|
|
37
|
+
- Use plain characters: no emoji unless asked, and no look-alike or invisible Unicode, such as an en dash for a hyphen.`,b=`- Answer in Markdown, with only as much structure as helps: short paragraphs by default, flat lists for parallel items, and a heading only when a long answer has distinct parts.
|
|
38
|
+
- Put code, commands and multi-line output in fenced code blocks labelled with their language.
|
|
39
|
+
- Wrap file paths, commands, environment variables and code identifiers in backticks.`,z=e=>{let t=e("rg_search"),o=e("rg_files");return`You are an exploration sub-agent: you investigate the workspace to answer the task you are given, and report what you found without changing anything.
|
|
40
|
+
|
|
41
|
+
Use read_file${t?" and rg_search to inspect and search":" to inspect"} code; read_file reads by line, so read the part you need.
|
|
42
|
+
Use ${o?"rg_files to find files by name pattern, and ":""}list_dir to see what a directory holds or for an overview of the workspace.
|
|
43
|
+
Request only the output you need, since tool output may be truncated, and make several targeted calls rather than one broad one.
|
|
44
|
+
Answer with your findings, pointing to code as \`path:line\`, and say what you looked for but could not find.`},Q="Sub-agent that explores the workspace without changing it: codebase exploration, file discovery and code understanding. It reports its findings.",Z="Fork yourself to execute one sub-task in isolation. The forked thread gets a clone of your current conversation context, executes the task independently, and its result is returned to you. Use this when you want to 'clone yourself' to do a sub-task without polluting your main conversation thread. Call this tool once per task; several calls in one response run concurrently.",ee="Sub-agents inherit your permissions and share your working directory. Give sub-agents that run at the same time disjoint files to write, or let only one of them write; disjoint files still share test discovery, build output and ports, so do not run tests or builds in two of them at once.",Je="You are a sub-agent: another agent handed you one task, which you carry out in the user's workspace with the tools you are given, reading, searching and changing its files and running commands there. You do not see the conversation that led to the task: the task is all you know of it. Your answer goes back to the agent that asked, not to the user.",te=`- Where these instructions say to ask the user, you cannot: stop there, and put the question in your answer, with what you found and what each answer would change.
|
|
45
|
+
- Before you answer, wait for every background command whose result you rely on, and stop every background command you started.`,$e=`Your answer is all the agent that asked gets back, so make it complete on its own:
|
|
46
|
+
- Lead with the outcome: what you did, or what you found.
|
|
47
|
+
- Point to code as \`path:line\`, with the path relative to the working directory.
|
|
48
|
+
- Say what you ran to check it, each command exactly, and what it showed.
|
|
49
|
+
- Say what is left undone, what you could not do, and what you are unsure of.`,Xe="You are a code review sub-agent: another agent asked you for a second reading of code in the user's workspace, a change or code as it stands, and you report the problems you find, with their evidence. You do not see the conversation that led to the task: the task names what to review and anything to focus on. Your answer goes back to the agent that asked, not to the user.",ze="- Read the change with git through run_command: a diff of the uncommitted changes, of the current work against a branch's merge base, or of one commit, with the repository's status and log. Note which commits you compared. Read the code around each change, and the code that depends on it, as far as you need to judge it. When the task names code rather than a change, review that code as it stands.\n- Review and report; do not fix. Run a command only when a finding needs the evidence: an existing test, the type checker, a linter, or a small reproduction. Prefer existing tests.\n- When a check needs a file inside the repository, create a new, uniquely named file with edit_files. Never change a file that existed before you started, the user's untracked files included.\n- Clean up what you created. Just before deleting a temporary file, read it again, and delete it only if it is still exactly what you wrote. Never restore the workspace wholesale, such as with `git checkout`, `git restore`, `git stash` or `git clean`.\n- Running tests writes caches and build output, which is fine: what you keep intact is the user's work.\n- When the target is a commit, or anything but the current work, your commands run on the checkout, not on the reviewed revision. Say which HEAD and which local changes they ran on, and do not claim that a check passing there shows the reviewed revision passes.\n- If files your findings rely on change while you review, check those findings again, or mark them uncertain.",Qe=`Flag a problem only when all of these hold:
|
|
50
|
+
- It meaningfully affects the correctness, performance, security or maintainability of the code.
|
|
51
|
+
- It is discrete and actionable: one issue, not a remark about the codebase in general or several issues together.
|
|
52
|
+
- When the task names a change, the change introduced it: problems that were there before are not flagged. When it names code, the problem is in that code.
|
|
53
|
+
- You can show it from the code or from what you ran. Speculating that something may break elsewhere is not enough: name the code that is affected. It must not rest on assumptions about the codebase or the author's intent that you have not stated.
|
|
54
|
+
- It is clearly not a deliberate choice, and the author would fix it if they knew.
|
|
55
|
+
- Fixing it does not demand more rigour than the rest of the codebase shows.
|
|
56
|
+
|
|
57
|
+
Ignore style, formatting, naming and typos unless they hide a bug or break a rule the repository's AGENTS.md files state. When a rule supports a finding, cite the AGENTS.md file and line it comes from.
|
|
58
|
+
|
|
59
|
+
Report every finding the author would want to fix, not only the first; when nothing clearly qualifies, report none. For each finding:
|
|
60
|
+
- A short title tagged with its priority: [P0] blocks a release or major use, whatever the inputs; [P1] urgent, for the next cycle; [P2] normal, to fix eventually; [P3] low, nice to have.
|
|
61
|
+
- Its location as \`path:line\` in the reviewed code, with the path relative to the repository, keeping the range as short as possible.
|
|
62
|
+
- One short paragraph saying why it is a problem and the inputs, scenarios or environments it needs, so its severity is clear, and the evidence: what you read or ran. Claim no more severity than it has, quote no more than three lines of code, and keep the tone matter-of-fact, with no praise.
|
|
63
|
+
|
|
64
|
+
When the task asks for a design assessment, alternatives or improvements, give them after the findings, under a heading of their own, apart from the problems you showed. When it asks for a severity scale or an output format, follow it instead of these.
|
|
65
|
+
|
|
66
|
+
End with:
|
|
67
|
+
- the scope you reviewed, and for a git target the commits you compared;
|
|
68
|
+
- the checks you ran, each command exactly, with its result;
|
|
69
|
+
- every experiment, what it left behind, and where its reproduction is kept, with how to run it;
|
|
70
|
+
- the limits of the review: what you did not read or could not check.
|
|
71
|
+
Then a one-line verdict: whether the reviewed code is correct, meaning existing code and tests will not break and it has no blocking problem. Non-blocking issues such as style do not count against it. "No qualifying findings" is not a guarantee of correctness: when you found none, say so plainly, with what you covered.
|
|
72
|
+
|
|
73
|
+
Answer in plain text, not JSON. The task may narrow what to look at, and the repository's AGENTS.md files may add rules; both take precedence over these guidelines.`,oe=(e,t)=>[e,...t.map(([o,a])=>_(o,a))].join(`
|
|
74
|
+
|
|
75
|
+
`),re=oe(Je,[["codebase",k],["editing",c],["dirtyWorktree",l],["validation",O],["safety",u],["subAgent",te],["answer",$e]]),ne=oe(Xe,[["evidence",ze],["editing",c],["dirtyWorktree",l],["safety",u],["subAgent",te],["rubric",Qe]]),ae="Sub-agent that carries out one self-contained task in the workspace with a fresh context: it reads, changes files, runs commands, and reports what it did and found. It sees only the task you write, not this conversation, so state the target, the outcome you expect and any constraints.",se="Sub-agent that reviews code in the workspace with a fresh context: a change (the uncommitted changes, the current work against a branch such as main, or one commit) or code as it stands. It may run tests and reproductions to gather evidence, changes nothing of yours, and reports the problems it can show, each tagged [P0] to [P3] at a file and line. Name the target and any focus in the task.";var Ze=[...s,...y,...w,...i,d,...U],et=[{tool:d,plugin:"skills"}],tt=[{tag:"autonomy",render:()=>q},{tag:"preambles",render:()=>K},{tag:"codebase",render:()=>k},{tag:"editing",render:()=>c},{tag:"dirtyWorktree",render:()=>l},{tag:"validation",render:()=>O},{tag:"delegation",render:()=>H},{tag:"forking",render:()=>ee},{tag:"longWork",render:({tools:e})=>Y.every(t=>e.some(o=>o.name===t))?`${E}
|
|
76
|
+
|
|
77
|
+
${J}`:E},{tag:"safety",render:()=>u},{tag:"ambitionPrecision",render:()=>$},{tag:"finalAnswer",render:()=>X},{tag:"communication",render:()=>T},{tag:"formatting",render:()=>b}],ot=R.strictObject({explore:R.strictObject({web:R.boolean().default(!1)}).prefault({}),agentsMd:C}),rt="codex.explore",nt="codex.general",at="codex.review",he=[...x,"web_search"],st=(e,t)=>[...s,...e?i:[]].filter(o=>t(o)||!he.includes(o)),ie=e=>[...s,...y,...w,...i,d].filter(t=>e(t)||!he.includes(t)),it=P({id:"codex#2",placement:"thread",schema:ot,inject:["tools","prompts","journal","threadDirs"],async setup(e,{explore:t,agentsMd:o},a){let r=[a.thread.agentName];if(e.get("presets")?.has(m)!==!0)throw new Error("codex hands down agents-md, which is not registered: register agentsMdPreset at startup");for(let{tool:n,plugin:g}of et)if(!e.tools.has(void 0,n))throw new Error(`codex grants ${n}, which is not registered: mount the ${g} plugin on the root`);for(let n of Ze)M(e,n,r);p(e,{tag:"base",slot:"base",agents:r,render:()=>V}),tt.forEach(({tag:n,render:g},de)=>p(e,{tag:n,slot:"instruction",agents:r,order:de,render:g})),a.kind==="installation"?(f(e,{holder:`codex in installation ${a.installationId}`,...o}),I(e,{presetId:m,config:o,installationId:D})):f(e,{holder:"codex for its agents",...o}),await e.plugin(F),await e.plugin(W,{agents:r});let h=n=>e.tools.has(void 0,n);await e.plugin(B,{endpoints:[{toolName:"explore",callers:r,description:Q,target:{kind:"role",id:rt,basePrompt:z(h),tools:st(t.web,h)}},{toolName:"delegate",callers:r,description:ae,target:{kind:"role",id:nt,basePrompt:re,tools:ie(h)}},{toolName:"fork",callers:r,description:Z,target:{kind:"fork"}},{toolName:"review",callers:r,description:se,target:{kind:"role",id:at,basePrompt:ne,tools:ie(h)}}]}),await e.plugin(G,{agents:r})}});export{Ne as AuxiliaryRefusedError,be as BirthConflictError,je as CODEX_ENVIRONMENT_POLICY,T as COMMUNICATION_GUIDANCE_PROMPT,ve as ConfirmationAnsweredError,xe as CorruptHistoryError,pe as CorruptJournalError,Ee as DepthExceededError,b as FORMATTING_PROMPT,Te as ForkCutError,me as IncompatibleJournalError,ce as InvalidOriginError,ue as JournalBusyError,fe as JournalCommitError,Ke as MemoryJournalStore,Be as NON_INTERACTIVE_ENVIRONMENT,Ie as ReplacementRefusedError,Oe as RestoreFailedError,Ae as RouteConflictError,Le as RouteUnavailableError,ge as StoreBusyError,Ue as Thread,_e as ThreadActivatingError,ke as ThreadBusyError,Pe as ThreadUnsettledError,Se as UNCONFINED_LAUNCH,we as UnknownAgentError,De as UnknownRunError,ye as UnknownThreadError,Re as WriteRefusedError,He as base,Ve as buildSpawnEnvironment,it as codexPreset,Ye as core,le as forkChain,Ge as heldOrSettled,Ce as registerPreset,Me as registerProvider,Fe as repositoryReadRoots,qe as resolveTrustedPrograms,We as waitForRun};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ThreadOrigin, ThreadSummary } from '../models/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Why a walk up the origin tree stopped short of a thread with no caller: `missing`, the caller is
|
|
4
|
+
* not in the catalog; `cycle`, the caller was already met. `at` is the last thread the walk reached,
|
|
5
|
+
* the one whose caller could not be followed, or `null` when that is a prospective opening, which has
|
|
6
|
+
* no id yet. Neither happens in a journal that kept its rules: a
|
|
7
|
+
* caller exists before the threads it creates, so origins cannot form a cycle.
|
|
8
|
+
*/
|
|
9
|
+
export type OriginBreak = {
|
|
10
|
+
readonly broken: 'missing' | 'cycle';
|
|
11
|
+
readonly at: string | null;
|
|
12
|
+
};
|
|
13
|
+
/** A thread and the threads that called it, nearest first, with whether the walk reached a root. */
|
|
14
|
+
export type CallerChain = {
|
|
15
|
+
/** `threadId` first, then its caller, that one's caller, out to a thread with no caller. */
|
|
16
|
+
readonly threads: readonly ThreadSummary[];
|
|
17
|
+
readonly chain: 'complete' | OriginBreak;
|
|
18
|
+
};
|
|
19
|
+
/** A thread not written yet, as far as its callers and requirements go: a write's resolved opening supplies both. */
|
|
20
|
+
export type OriginOpening = {
|
|
21
|
+
readonly origin: ThreadOrigin | null;
|
|
22
|
+
readonly requires: readonly string[];
|
|
23
|
+
};
|
|
24
|
+
/** A constraint owner a run needs, and the threads whose `requires` name it. */
|
|
25
|
+
export type RequiredOwner = {
|
|
26
|
+
readonly owner: string;
|
|
27
|
+
/** Nearest first. Empty for an owner only a prospective opening's own `requires` names. */
|
|
28
|
+
readonly introducedBy: readonly string[];
|
|
29
|
+
};
|
|
30
|
+
/** What `requiredOwners` found, with whether the callers it read up to a root. */
|
|
31
|
+
export type RequiredOwners = {
|
|
32
|
+
readonly owners: readonly RequiredOwner[];
|
|
33
|
+
readonly chain: 'complete' | OriginBreak;
|
|
34
|
+
};
|
|
35
|
+
/** Which rule an origin broke: see {@link Origins.validate}. */
|
|
36
|
+
export type InvalidOriginReason = 'unknown-caller' | 'source-missing' | 'source-off-lineage' | 'source-not-a-call';
|
|
37
|
+
/** An origin whose caller or cited row breaks `origins.validate`'s rule; `reason` says which. */
|
|
38
|
+
export declare class InvalidOriginError extends Error {
|
|
39
|
+
readonly origin: ThreadOrigin;
|
|
40
|
+
readonly reason: InvalidOriginReason;
|
|
41
|
+
constructor(origin: ThreadOrigin, reason: InvalidOriginReason);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The origin tree, read from the catalog: each thread's spawn row names the caller whose
|
|
45
|
+
* `tool/call` created it, and the threads with no caller head a tree each. Queries read summaries
|
|
46
|
+
* only and load nothing; they follow `origin` and never fork lineage, which is `Thread.lineageRoot`'s.
|
|
47
|
+
* A thread the catalog does not hold has no chain and no subtree.
|
|
48
|
+
*/
|
|
49
|
+
export interface Origins {
|
|
50
|
+
/**
|
|
51
|
+
* `threadId` and the threads that called it, upward to its origin root; see {@link CallerChain}.
|
|
52
|
+
* An incomplete chain says so, and its last thread still has an `origin`.
|
|
53
|
+
*/
|
|
54
|
+
callers(threadId: string): CallerChain;
|
|
55
|
+
/** The last thread of {@link callers}: the origin root, or the last thread reached when the chain is incomplete. */
|
|
56
|
+
root(threadId: string): ThreadSummary | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* The threads created under `threadId` at any depth, in spawn order, a caller before the threads
|
|
59
|
+
* it created, with `threadId` itself first when `self`. Each thread is listed once, so a cycle
|
|
60
|
+
* ends the walk rather than repeating it, and `self: false` drops the start in a cycle too.
|
|
61
|
+
*/
|
|
62
|
+
subtree(threadId: string, options: {
|
|
63
|
+
readonly self: boolean;
|
|
64
|
+
}): ThreadSummary[];
|
|
65
|
+
/** Whether `threadId` is `ancestorId` or was created under it. */
|
|
66
|
+
isUnder(threadId: string, ancestorId: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The constraint owners a thread's run needs: what its own `requires` names and what every thread
|
|
69
|
+
* above it by origin requires, each with the threads that introduced it. A prospective opening
|
|
70
|
+
* stands for a thread not written yet; its callers are read from the catalog, and a caller the
|
|
71
|
+
* catalog does not hold is `missing` at `null`, the opening itself. Only readiness is inherited, never a
|
|
72
|
+
* caller's holds.
|
|
73
|
+
*/
|
|
74
|
+
requiredOwners(threadOrOpening: string | OriginOpening): RequiredOwners;
|
|
75
|
+
/**
|
|
76
|
+
* Checks the one rule an origin's cited row must meet, whoever records the origin: its caller is a
|
|
77
|
+
* known thread, `source_seq` is a row of the caller's lineage, its own or one a fork it continues
|
|
78
|
+
* inherits, and for a `call` cause it is a `tool/call` row. What an assignment's granting row means
|
|
79
|
+
* is the owner's. Throws {@link InvalidOriginError} naming what is wrong. Reads the one row from
|
|
80
|
+
* the store when it is not loaded and loads nothing else, so a caller that is not loaded validates.
|
|
81
|
+
*/
|
|
82
|
+
validate(origin: ThreadOrigin): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The catalog of one summary per thread, in spawn order, with the index of which threads each
|
|
86
|
+
* caller created: the one owner of the origin graph, so the index cannot trail the summaries. Every
|
|
87
|
+
* change to the catalog goes through it. An origin never changes, so a thread's caller is indexed
|
|
88
|
+
* when its summary first enters.
|
|
89
|
+
*/
|
|
90
|
+
export declare class Catalog {
|
|
91
|
+
private readonly summaries;
|
|
92
|
+
/** Position in spawn order: kept by a replaced summary, new for one added after a delete. */
|
|
93
|
+
private readonly ranks;
|
|
94
|
+
/** Caller id to the threads it created, among those the catalog holds. The caller itself may not be held. */
|
|
95
|
+
private readonly children;
|
|
96
|
+
private nextRank;
|
|
97
|
+
readonly origins: Omit<Origins, 'validate'>;
|
|
98
|
+
get(threadId: string): ThreadSummary | undefined;
|
|
99
|
+
has(threadId: string): boolean;
|
|
100
|
+
keys(): IterableIterator<string>;
|
|
101
|
+
values(): IterableIterator<ThreadSummary>;
|
|
102
|
+
/** The summaries by thread id, live: a read sees later changes. */
|
|
103
|
+
view(): ReadonlyMap<string, ThreadSummary>;
|
|
104
|
+
/** Adds a thread's summary after the others, or replaces it where it stands. */
|
|
105
|
+
set(threadId: string, summary: ThreadSummary): void;
|
|
106
|
+
delete(threadId: string): void;
|
|
107
|
+
/** Replaces every summary, the new ones in the order given. */
|
|
108
|
+
reset(summaries: Iterable<ThreadSummary>): void;
|
|
109
|
+
private callers;
|
|
110
|
+
private subtree;
|
|
111
|
+
private requiredOwners;
|
|
112
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** What a fork walk reads of a catalog summary. */
|
|
2
|
+
export type ForkLink = {
|
|
3
|
+
readonly thread_id: string;
|
|
4
|
+
readonly fork: {
|
|
5
|
+
readonly thread_id: string;
|
|
6
|
+
} | null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* `threadId` and the threads it was forked from, nearest first, out to the thread no fork leads
|
|
10
|
+
* from: the catalog's view of the lineage the journal folds, without loading a row. It follows
|
|
11
|
+
* `fork` and never delegation origin (`origins.callers`'). The start is first and an unknown start
|
|
12
|
+
* yields nothing; the walk stops at a source the catalog does not hold and at a thread it already
|
|
13
|
+
* met, so a journal that broke its rules, with a cycle or a lost source, ends the chain rather than
|
|
14
|
+
* looping or throwing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function forkChain<S extends ForkLink>(summaries: ReadonlyMap<string, S>, threadId: string): S[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The journal: an append-only event stream and the folds over it.
|
|
3
|
+
*
|
|
4
|
+
* Knows envelopes and one row shape: a `thread/spawned` naming a fork point, where a thread's folds
|
|
5
|
+
* continue from another's. A writer judges what it writes inside its own `transact` callback; the
|
|
6
|
+
* journal parses and records. Nothing here has heard of agents, turns or tools. A store
|
|
7
|
+
* backend implements `JournalStore`; a plugin that wants durable state registers a `PluginProjection`. Neither
|
|
8
|
+
* needs the loop.
|
|
9
|
+
*/
|
|
10
|
+
export { InvalidOriginError } from './catalog.js';
|
|
11
|
+
export type { CallerChain, InvalidOriginReason, OriginBreak, OriginOpening, Origins, RequiredOwner, RequiredOwners, } from './catalog.js';
|
|
12
|
+
export * from './forkChain.js';
|
|
13
|
+
export * from './journal.js';
|
|
14
|
+
export * from './projection.js';
|
|
15
|
+
export * from './store.js';
|