@aragon-agent/cli 0.6.55 → 0.6.56
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/CHANGELOG.md +2912 -2864
- package/README.md +160 -45
- package/dist/agent/controller.d.ts +47 -0
- package/dist/agent/controller.js +153 -2
- package/dist/agent/governance-wiring.js +8 -1
- package/dist/agent/system-prompt.d.ts +26 -0
- package/dist/agent/system-prompt.js +11 -0
- package/dist/app/App.js +101 -3
- package/dist/cli.js +29 -1
- package/dist/commands/builtins.js +4 -0
- package/dist/commands/catalog.js +1 -0
- package/dist/commands/registry.d.ts +8 -0
- package/dist/config/app-paths.d.ts +10 -0
- package/dist/config/app-paths.js +12 -0
- package/dist/config/cli-commands.d.ts +29 -0
- package/dist/config/cli-commands.js +76 -1
- package/dist/config/env.d.ts +2 -1
- package/dist/config/env.js +12 -1
- package/dist/config/load.d.ts +10 -0
- package/dist/config/load.js +13 -2
- package/dist/config/store.js +11 -1
- package/dist/exec/bridge/server.d.ts +7 -0
- package/dist/exec/bridge/server.js +6 -2
- package/dist/exec/cli-commands.js +4 -0
- package/dist/exec/index.js +2 -0
- package/dist/exec/options.d.ts +11 -0
- package/dist/exec/options.js +21 -1
- package/dist/gene/block.d.ts +33 -0
- package/dist/gene/block.js +51 -0
- package/dist/gene/capacity.d.ts +74 -0
- package/dist/gene/capacity.js +169 -0
- package/dist/gene/catalog-reconcile.d.ts +13 -0
- package/dist/gene/catalog-reconcile.js +105 -0
- package/dist/gene/catalog-stats.d.ts +27 -0
- package/dist/gene/catalog-stats.js +89 -0
- package/dist/gene/catalog-sync.d.ts +82 -0
- package/dist/gene/catalog-sync.js +324 -0
- package/dist/gene/catalog.d.ts +160 -0
- package/dist/gene/catalog.js +433 -0
- package/dist/gene/cli-commands.d.ts +50 -0
- package/dist/gene/cli-commands.js +500 -0
- package/dist/gene/command-report.d.ts +40 -0
- package/dist/gene/command-report.js +246 -0
- package/dist/gene/command.d.ts +29 -0
- package/dist/gene/command.js +561 -0
- package/dist/gene/commit-apply-types.d.ts +13 -0
- package/dist/gene/commit-apply-types.js +1 -0
- package/dist/gene/commit-compound.d.ts +34 -0
- package/dist/gene/commit-compound.js +212 -0
- package/dist/gene/commit-counts.d.ts +41 -0
- package/dist/gene/commit-counts.js +70 -0
- package/dist/gene/commit-exec.d.ts +42 -0
- package/dist/gene/commit-exec.js +134 -0
- package/dist/gene/commit-head.d.ts +52 -0
- package/dist/gene/commit-head.js +97 -0
- package/dist/gene/commit-plan.d.ts +95 -0
- package/dist/gene/commit-plan.js +68 -0
- package/dist/gene/commit-prepare.d.ts +63 -0
- package/dist/gene/commit-prepare.js +159 -0
- package/dist/gene/commit-types.d.ts +234 -0
- package/dist/gene/commit-types.js +3 -0
- package/dist/gene/curator/agent.d.ts +137 -0
- package/dist/gene/curator/agent.js +203 -0
- package/dist/gene/curator/budget.d.ts +69 -0
- package/dist/gene/curator/budget.js +131 -0
- package/dist/gene/curator/conflicts.d.ts +54 -0
- package/dist/gene/curator/conflicts.js +143 -0
- package/dist/gene/curator/curator.d.ts +170 -0
- package/dist/gene/curator/curator.js +617 -0
- package/dist/gene/curator/deps.d.ts +34 -0
- package/dist/gene/curator/deps.js +48 -0
- package/dist/gene/curator/deterministic.d.ts +62 -0
- package/dist/gene/curator/deterministic.js +287 -0
- package/dist/gene/curator/executors.d.ts +36 -0
- package/dist/gene/curator/executors.js +379 -0
- package/dist/gene/curator/lanes.d.ts +52 -0
- package/dist/gene/curator/lanes.js +99 -0
- package/dist/gene/curator/lease.d.ts +76 -0
- package/dist/gene/curator/lease.js +171 -0
- package/dist/gene/curator/library.d.ts +36 -0
- package/dist/gene/curator/library.js +169 -0
- package/dist/gene/curator/lifecycle.d.ts +52 -0
- package/dist/gene/curator/lifecycle.js +109 -0
- package/dist/gene/curator/maintenance.d.ts +71 -0
- package/dist/gene/curator/maintenance.js +213 -0
- package/dist/gene/curator/probation.d.ts +51 -0
- package/dist/gene/curator/probation.js +71 -0
- package/dist/gene/curator/probe.d.ts +131 -0
- package/dist/gene/curator/probe.js +534 -0
- package/dist/gene/curator/prompt.d.ts +18 -0
- package/dist/gene/curator/prompt.js +128 -0
- package/dist/gene/curator/publish.d.ts +64 -0
- package/dist/gene/curator/publish.js +113 -0
- package/dist/gene/curator/recheck.d.ts +55 -0
- package/dist/gene/curator/recheck.js +103 -0
- package/dist/gene/curator/run-events.d.ts +63 -0
- package/dist/gene/curator/run-events.js +55 -0
- package/dist/gene/curator/similarity.d.ts +13 -0
- package/dist/gene/curator/similarity.js +46 -0
- package/dist/gene/curator/switches.d.ts +78 -0
- package/dist/gene/curator/switches.js +146 -0
- package/dist/gene/curator/task-context.d.ts +93 -0
- package/dist/gene/curator/task-context.js +63 -0
- package/dist/gene/curator/task-runner.d.ts +56 -0
- package/dist/gene/curator/task-runner.js +257 -0
- package/dist/gene/curator/tool-support.d.ts +112 -0
- package/dist/gene/curator/tool-support.js +197 -0
- package/dist/gene/curator/toolkit.d.ts +49 -0
- package/dist/gene/curator/toolkit.js +104 -0
- package/dist/gene/curator/tools-read.d.ts +4 -0
- package/dist/gene/curator/tools-read.js +177 -0
- package/dist/gene/curator/tools-release.d.ts +73 -0
- package/dist/gene/curator/tools-release.js +287 -0
- package/dist/gene/curator/tools-verify.d.ts +47 -0
- package/dist/gene/curator/tools-verify.js +202 -0
- package/dist/gene/curator/tools-write.d.ts +26 -0
- package/dist/gene/curator/tools-write.js +394 -0
- package/dist/gene/curator/tools.d.ts +23 -0
- package/dist/gene/curator/tools.js +21 -0
- package/dist/gene/curator/validate/common.d.ts +87 -0
- package/dist/gene/curator/validate/common.js +132 -0
- package/dist/gene/curator/validate/evidence-tokens.d.ts +36 -0
- package/dist/gene/curator/validate/evidence-tokens.js +139 -0
- package/dist/gene/curator/validate/index.d.ts +23 -0
- package/dist/gene/curator/validate/index.js +62 -0
- package/dist/gene/curator/validate/knowledge.d.ts +25 -0
- package/dist/gene/curator/validate/knowledge.js +216 -0
- package/dist/gene/curator/validate/live-check.d.ts +14 -0
- package/dist/gene/curator/validate/live-check.js +144 -0
- package/dist/gene/curator/validate/ports.d.ts +67 -0
- package/dist/gene/curator/validate/ports.js +1 -0
- package/dist/gene/curator/validate/prompts.d.ts +41 -0
- package/dist/gene/curator/validate/prompts.js +161 -0
- package/dist/gene/curator/validate/skill.d.ts +15 -0
- package/dist/gene/curator/validate/skill.js +251 -0
- package/dist/gene/curator/validate/tool.d.ts +6 -0
- package/dist/gene/curator/validate/tool.js +217 -0
- package/dist/gene/curator/validate/types.d.ts +90 -0
- package/dist/gene/curator/validate/types.js +1 -0
- package/dist/gene/curator/validator-ports.d.ts +38 -0
- package/dist/gene/curator/validator-ports.js +29 -0
- package/dist/gene/diag.d.ts +209 -0
- package/dist/gene/diag.js +549 -0
- package/dist/gene/env.d.ts +10 -0
- package/dist/gene/env.js +214 -0
- package/dist/gene/eval-recorder.d.ts +84 -0
- package/dist/gene/eval-recorder.js +222 -0
- package/dist/gene/explain-transport.d.ts +3 -0
- package/dist/gene/explain-transport.js +39 -0
- package/dist/gene/explain.d.ts +96 -0
- package/dist/gene/explain.js +293 -0
- package/dist/gene/fs.d.ts +39 -0
- package/dist/gene/fs.js +139 -0
- package/dist/gene/fsck.d.ts +68 -0
- package/dist/gene/fsck.js +134 -0
- package/dist/gene/gc-library-sweeps.d.ts +9 -0
- package/dist/gene/gc-library-sweeps.js +220 -0
- package/dist/gene/gc-rejected-set.d.ts +15 -0
- package/dist/gene/gc-rejected-set.js +63 -0
- package/dist/gene/gc-safe.d.ts +12 -0
- package/dist/gene/gc-safe.js +74 -0
- package/dist/gene/gc-scope-sweeps.d.ts +18 -0
- package/dist/gene/gc-scope-sweeps.js +297 -0
- package/dist/gene/gc-types.d.ts +55 -0
- package/dist/gene/gc-types.js +26 -0
- package/dist/gene/gc.d.ts +42 -0
- package/dist/gene/gc.js +129 -0
- package/dist/gene/gene-errors.d.ts +23 -0
- package/dist/gene/gene-errors.js +29 -0
- package/dist/gene/hints.d.ts +91 -0
- package/dist/gene/hints.js +394 -0
- package/dist/gene/hub.d.ts +149 -0
- package/dist/gene/hub.js +371 -0
- package/dist/gene/import-plan.d.ts +80 -0
- package/dist/gene/import-plan.js +294 -0
- package/dist/gene/import-proposal.d.ts +23 -0
- package/dist/gene/import-proposal.js +101 -0
- package/dist/gene/import-skill-port.d.ts +6 -0
- package/dist/gene/import-skill-port.js +53 -0
- package/dist/gene/import-sources.d.ts +48 -0
- package/dist/gene/import-sources.js +140 -0
- package/dist/gene/index-writer.d.ts +36 -0
- package/dist/gene/index-writer.js +101 -0
- package/dist/gene/learn/learn-call.d.ts +63 -0
- package/dist/gene/learn/learn-call.js +157 -0
- package/dist/gene/learn/learn-prompt.d.ts +51 -0
- package/dist/gene/learn/learn-prompt.js +245 -0
- package/dist/gene/learn/learner.d.ts +181 -0
- package/dist/gene/learn/learner.js +426 -0
- package/dist/gene/learn/ledger.d.ts +220 -0
- package/dist/gene/learn/ledger.js +394 -0
- package/dist/gene/learn/proposal-build.d.ts +83 -0
- package/dist/gene/learn/proposal-build.js +211 -0
- package/dist/gene/learn/proposal-guard.d.ts +43 -0
- package/dist/gene/learn/proposal-guard.js +37 -0
- package/dist/gene/learn/signals-port.d.ts +47 -0
- package/dist/gene/learn/signals-port.js +86 -0
- package/dist/gene/maintenance-paths.d.ts +7 -0
- package/dist/gene/maintenance-paths.js +20 -0
- package/dist/gene/maintenance-probation.d.ts +33 -0
- package/dist/gene/maintenance-probation.js +127 -0
- package/dist/gene/maintenance-proposals.d.ts +24 -0
- package/dist/gene/maintenance-proposals.js +68 -0
- package/dist/gene/maintenance-runner.d.ts +92 -0
- package/dist/gene/maintenance-runner.js +262 -0
- package/dist/gene/maintenance-tasks.d.ts +37 -0
- package/dist/gene/maintenance-tasks.js +95 -0
- package/dist/gene/manager-actions.d.ts +12 -0
- package/dist/gene/manager-actions.js +279 -0
- package/dist/gene/manager-approve.d.ts +29 -0
- package/dist/gene/manager-approve.js +84 -0
- package/dist/gene/manager-context.d.ts +90 -0
- package/dist/gene/manager-context.js +201 -0
- package/dist/gene/manager-detail.d.ts +17 -0
- package/dist/gene/manager-detail.js +313 -0
- package/dist/gene/manager-gc.d.ts +13 -0
- package/dist/gene/manager-gc.js +81 -0
- package/dist/gene/manager-library.d.ts +39 -0
- package/dist/gene/manager-library.js +90 -0
- package/dist/gene/manager-list.d.ts +27 -0
- package/dist/gene/manager-list.js +170 -0
- package/dist/gene/manager-queue.d.ts +16 -0
- package/dist/gene/manager-queue.js +124 -0
- package/dist/gene/manager-stats.d.ts +28 -0
- package/dist/gene/manager-stats.js +53 -0
- package/dist/gene/manager-view.d.ts +27 -0
- package/dist/gene/manager-view.js +124 -0
- package/dist/gene/manager.d.ts +56 -0
- package/dist/gene/manager.js +179 -0
- package/dist/gene/orphan-scopes.d.ts +37 -0
- package/dist/gene/orphan-scopes.js +150 -0
- package/dist/gene/paths.d.ts +73 -0
- package/dist/gene/paths.js +239 -0
- package/dist/gene/plan-content.d.ts +73 -0
- package/dist/gene/plan-content.js +522 -0
- package/dist/gene/plan-lifecycle.d.ts +29 -0
- package/dist/gene/plan-lifecycle.js +310 -0
- package/dist/gene/policy.d.ts +71 -0
- package/dist/gene/policy.js +313 -0
- package/dist/gene/project-learning.d.ts +25 -0
- package/dist/gene/project-learning.js +54 -0
- package/dist/gene/propagation.d.ts +48 -0
- package/dist/gene/propagation.js +45 -0
- package/dist/gene/queue-lock.d.ts +22 -0
- package/dist/gene/queue-lock.js +99 -0
- package/dist/gene/queue-record.d.ts +57 -0
- package/dist/gene/queue-record.js +145 -0
- package/dist/gene/queue.d.ts +235 -0
- package/dist/gene/queue.js +764 -0
- package/dist/gene/read.d.ts +61 -0
- package/dist/gene/read.js +252 -0
- package/dist/gene/runlog.d.ts +101 -0
- package/dist/gene/runlog.js +404 -0
- package/dist/gene/schema-lite.d.ts +24 -0
- package/dist/gene/schema-lite.js +159 -0
- package/dist/gene/scope-guard.d.ts +23 -0
- package/dist/gene/scope-guard.js +9 -0
- package/dist/gene/scope-lock.d.ts +48 -0
- package/dist/gene/scope-lock.js +222 -0
- package/dist/gene/scope-verify.d.ts +63 -0
- package/dist/gene/scope-verify.js +123 -0
- package/dist/gene/secrets.d.ts +43 -0
- package/dist/gene/secrets.js +161 -0
- package/dist/gene/service-context.d.ts +43 -0
- package/dist/gene/service-context.js +79 -0
- package/dist/gene/service-prepare.d.ts +25 -0
- package/dist/gene/service-prepare.js +219 -0
- package/dist/gene/service-types.d.ts +196 -0
- package/dist/gene/service-types.js +1 -0
- package/dist/gene/service-view.d.ts +41 -0
- package/dist/gene/service-view.js +69 -0
- package/dist/gene/service.d.ts +114 -0
- package/dist/gene/service.js +761 -0
- package/dist/gene/session-start.d.ts +36 -0
- package/dist/gene/session-start.js +212 -0
- package/dist/gene/store-port.d.ts +88 -0
- package/dist/gene/store-port.js +10 -0
- package/dist/gene/store-rows.d.ts +36 -0
- package/dist/gene/store-rows.js +72 -0
- package/dist/gene/store.d.ts +125 -0
- package/dist/gene/store.js +622 -0
- package/dist/gene/tombstones.d.ts +47 -0
- package/dist/gene/tombstones.js +61 -0
- package/dist/gene/tool-runner.d.ts +47 -0
- package/dist/gene/tool-runner.js +154 -0
- package/dist/gene/tool-screen.d.ts +41 -0
- package/dist/gene/tool-screen.js +227 -0
- package/dist/gene/tools.d.ts +112 -0
- package/dist/gene/tools.js +539 -0
- package/dist/gene/transfer.d.ts +85 -0
- package/dist/gene/transfer.js +433 -0
- package/dist/gene/ui-hints.d.ts +15 -0
- package/dist/gene/ui-hints.js +67 -0
- package/dist/gene/usage-fold-cursor.d.ts +24 -0
- package/dist/gene/usage-fold-cursor.js +115 -0
- package/dist/gene/usage-fold.d.ts +49 -0
- package/dist/gene/usage-fold.js +397 -0
- package/dist/gene/usage.d.ts +67 -0
- package/dist/gene/usage.js +231 -0
- package/dist/gene/version-service.d.ts +118 -0
- package/dist/gene/version-service.js +453 -0
- package/dist/gene/wiring-events.d.ts +43 -0
- package/dist/gene/wiring-events.js +113 -0
- package/dist/gene/wiring-models.d.ts +46 -0
- package/dist/gene/wiring-models.js +81 -0
- package/dist/gene/wiring.d.ts +200 -0
- package/dist/gene/wiring.js +764 -0
- package/dist/governance/prompts/orchestrator-block.js +3 -2
- package/dist/host/gene.d.ts +26 -0
- package/dist/host/gene.js +24 -0
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/team/runtime.d.ts +5 -0
- package/dist/team/runtime.js +23 -0
- package/dist/team/subagent.d.ts +34 -0
- package/dist/team/subagent.js +39 -2
- package/dist/tools/index.d.ts +36 -2
- package/dist/tools/index.js +48 -7
- package/package.json +3 -3
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The curator's model seam and its per-task agent loop (gene-bank spec 10.3, 9.5).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* EVERYTHING MODEL-DRIVEN GOES THROUGH `CuratorModelPort`. The host, the validators' small JSON
|
|
7
|
+
* calls and the agent loop reach a provider only through it, so the curator's tests script it and
|
|
8
|
+
* never touch a network, and the production adapter (`createCuratorModelPort`) is the one place
|
|
9
|
+
* that knows about `Agent`, `ProviderRegistry` and the fast tier.
|
|
10
|
+
*
|
|
11
|
+
* ONE AGENT PER TASK, NO FILES, NO SHELL. `assembleCuratorAgent` hands the model the always-on
|
|
12
|
+
* tools (`gene_search`, `gene_read`, `gene_toolkit`) and nothing else; the management groups are
|
|
13
|
+
* added by `gene_toolkit load` through `setTools`, which takes effect on the NEXT model call.
|
|
14
|
+
* There is no `bash`, no file tool, no `gene_run`: the curator reads and writes the library
|
|
15
|
+
* through its own tools and executes nothing (I-25).
|
|
16
|
+
*
|
|
17
|
+
* LIMITS ARE ENFORCED HERE, NOT TRUSTED TO THE MODEL. `runCuratorAgent` stops a task that crosses
|
|
18
|
+
* its token, turn or wall-clock budget, or that has already finished (`gene_finish`) or been
|
|
19
|
+
* abandoned, BEFORE another model call is made. The stop reason is recorded first and the abort
|
|
20
|
+
* second, so a deadline and a cancel are never confused with a failure (the lesson of
|
|
21
|
+
* `learn-call.ts`).
|
|
22
|
+
*/
|
|
23
|
+
import { type AgentConfig, type AgentEvent, type AgentTool, type ModelRef, type ProviderRegistry, type UserMessage } from '@aragon-agent/core';
|
|
24
|
+
import type { ModelJsonRequest, ModelJsonResponse } from './validate/ports.js';
|
|
25
|
+
import type { TaskLimits } from './budget.js';
|
|
26
|
+
import { type HubScheduler } from '../hub.js';
|
|
27
|
+
export interface CuratorRunOptions {
|
|
28
|
+
signal: AbortSignal;
|
|
29
|
+
/** Called after every model turn with that turn's token usage. */
|
|
30
|
+
onTurn(usage: {
|
|
31
|
+
in: number;
|
|
32
|
+
out: number;
|
|
33
|
+
}): void;
|
|
34
|
+
/** Called after every tool call finishes, so the runner can stop before the next model call. */
|
|
35
|
+
onToolEnd?(toolName: string): void;
|
|
36
|
+
}
|
|
37
|
+
export interface CuratorRunEnd {
|
|
38
|
+
error?: {
|
|
39
|
+
message: string;
|
|
40
|
+
errorType?: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface CuratorAgentHandle {
|
|
44
|
+
/** Run one prompt to completion (or until aborted). Never rejects. */
|
|
45
|
+
run(prompt: string, options: CuratorRunOptions): Promise<CuratorRunEnd>;
|
|
46
|
+
/** Replace the visible tool array; the NEXT model call sees it. */
|
|
47
|
+
setTools(tools: AgentTool[]): void;
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
50
|
+
export type CuratorModelAvailability = {
|
|
51
|
+
ok: true;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
reason: 'no_fast_tier';
|
|
55
|
+
hint?: string;
|
|
56
|
+
};
|
|
57
|
+
export interface CuratorModelPort {
|
|
58
|
+
/** Absent means "always available". Read before every claim, so a lost key pauses the curator. */
|
|
59
|
+
available?(): CuratorModelAvailability;
|
|
60
|
+
createAgent(options: {
|
|
61
|
+
systemPrompt: string;
|
|
62
|
+
tools: AgentTool[];
|
|
63
|
+
}): CuratorAgentHandle;
|
|
64
|
+
/** The validators' one-shot JSON call. Absent or null => model checks are skipped, never faked. */
|
|
65
|
+
completeJson?(request: ModelJsonRequest, signal?: AbortSignal): Promise<ModelJsonResponse | null>;
|
|
66
|
+
}
|
|
67
|
+
/** The part of the toolkit the agent needs: what is visible now, and where to push changes. */
|
|
68
|
+
export interface ToolkitBinding {
|
|
69
|
+
visible(): AgentTool[];
|
|
70
|
+
bind(setter: (tools: AgentTool[]) => void): void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* One agent for one task: the toolkit's always-on tools in, and `gene_toolkit load` wired to
|
|
74
|
+
* `setTools` so a loaded group reaches the model on its next call. No other tool is ever added.
|
|
75
|
+
*/
|
|
76
|
+
export declare function assembleCuratorAgent(port: CuratorModelPort, systemPrompt: string, toolkit: ToolkitBinding): CuratorAgentHandle;
|
|
77
|
+
export type AgentStop = 'finished' | 'tokens' | 'turns' | 'timeout' | 'aborted' | 'error' | 'done';
|
|
78
|
+
export interface AgentRunSummary {
|
|
79
|
+
stop: AgentStop;
|
|
80
|
+
usage: {
|
|
81
|
+
in: number;
|
|
82
|
+
out: number;
|
|
83
|
+
};
|
|
84
|
+
turns: number;
|
|
85
|
+
error?: {
|
|
86
|
+
message: string;
|
|
87
|
+
errorType?: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface RunAgentOptions {
|
|
91
|
+
handle: CuratorAgentHandle;
|
|
92
|
+
prompt: string;
|
|
93
|
+
limits: TaskLimits;
|
|
94
|
+
/** The host's cancel (dispose). */
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
/** True once the task has ended by its own tools (`gene_finish`) or was abandoned. */
|
|
97
|
+
shouldStop(): boolean;
|
|
98
|
+
/** Spend is reported as it happens so the daily budget sees an aborted task too. */
|
|
99
|
+
onUsage?(usage: {
|
|
100
|
+
in: number;
|
|
101
|
+
out: number;
|
|
102
|
+
}): void;
|
|
103
|
+
scheduler?: Pick<HubScheduler, 'after'>;
|
|
104
|
+
}
|
|
105
|
+
/** Run the agent under its limits. Never throws. */
|
|
106
|
+
export declare function runCuratorAgent(options: RunAgentOptions): Promise<AgentRunSummary>;
|
|
107
|
+
/** The slice of `Agent` the adapter uses; a test passes a fake. */
|
|
108
|
+
export interface AgentLike {
|
|
109
|
+
prompt(message: string | UserMessage): Promise<void>;
|
|
110
|
+
abort(): void;
|
|
111
|
+
subscribe(listener: (event: AgentEvent) => void): () => void;
|
|
112
|
+
setTools(tools: AgentTool[]): void;
|
|
113
|
+
}
|
|
114
|
+
export interface CuratorModelChoice {
|
|
115
|
+
ref: ModelRef;
|
|
116
|
+
getApiKey(providerId: string): string | undefined;
|
|
117
|
+
}
|
|
118
|
+
export type CuratorModelResolution = {
|
|
119
|
+
ok: true;
|
|
120
|
+
choice: CuratorModelChoice;
|
|
121
|
+
} | {
|
|
122
|
+
ok: false;
|
|
123
|
+
reason: 'no_fast_tier';
|
|
124
|
+
hint?: string;
|
|
125
|
+
};
|
|
126
|
+
export interface CuratorModelDeps {
|
|
127
|
+
/** Which model `gene.curatorModel` selects right now, or why there is none. */
|
|
128
|
+
resolve(): CuratorModelResolution;
|
|
129
|
+
/** A FAIL-FAST registry: a background task must not sit on a rate limit (10.3). */
|
|
130
|
+
registry?(): ProviderRegistry;
|
|
131
|
+
/** Test seam. Production builds a real `Agent`. */
|
|
132
|
+
agentFactory?(config: AgentConfig): AgentLike;
|
|
133
|
+
/** Output cap per model call. */
|
|
134
|
+
maxTokens?: number;
|
|
135
|
+
}
|
|
136
|
+
/** The thin production adapter. Everything with a decision in it lives above this line. */
|
|
137
|
+
export declare function createCuratorModelPort(deps: CuratorModelDeps): CuratorModelPort;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The curator's model seam and its per-task agent loop (gene-bank spec 10.3, 9.5).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* EVERYTHING MODEL-DRIVEN GOES THROUGH `CuratorModelPort`. The host, the validators' small JSON
|
|
7
|
+
* calls and the agent loop reach a provider only through it, so the curator's tests script it and
|
|
8
|
+
* never touch a network, and the production adapter (`createCuratorModelPort`) is the one place
|
|
9
|
+
* that knows about `Agent`, `ProviderRegistry` and the fast tier.
|
|
10
|
+
*
|
|
11
|
+
* ONE AGENT PER TASK, NO FILES, NO SHELL. `assembleCuratorAgent` hands the model the always-on
|
|
12
|
+
* tools (`gene_search`, `gene_read`, `gene_toolkit`) and nothing else; the management groups are
|
|
13
|
+
* added by `gene_toolkit load` through `setTools`, which takes effect on the NEXT model call.
|
|
14
|
+
* There is no `bash`, no file tool, no `gene_run`: the curator reads and writes the library
|
|
15
|
+
* through its own tools and executes nothing (I-25).
|
|
16
|
+
*
|
|
17
|
+
* LIMITS ARE ENFORCED HERE, NOT TRUSTED TO THE MODEL. `runCuratorAgent` stops a task that crosses
|
|
18
|
+
* its token, turn or wall-clock budget, or that has already finished (`gene_finish`) or been
|
|
19
|
+
* abandoned, BEFORE another model call is made. The stop reason is recorded first and the abort
|
|
20
|
+
* second, so a deadline and a cancel are never confused with a failure (the lesson of
|
|
21
|
+
* `learn-call.ts`).
|
|
22
|
+
*/
|
|
23
|
+
import { Agent, initProviders, DEFAULT_RETRY_POLICY, } from '@aragon-agent/core';
|
|
24
|
+
import { formatStreamError } from '@aragon-agent/tui/model/agent/reducer';
|
|
25
|
+
import { realScheduler } from '../hub.js';
|
|
26
|
+
/**
|
|
27
|
+
* One agent for one task: the toolkit's always-on tools in, and `gene_toolkit load` wired to
|
|
28
|
+
* `setTools` so a loaded group reaches the model on its next call. No other tool is ever added.
|
|
29
|
+
*/
|
|
30
|
+
export function assembleCuratorAgent(port, systemPrompt, toolkit) {
|
|
31
|
+
const handle = port.createAgent({ systemPrompt, tools: toolkit.visible() });
|
|
32
|
+
toolkit.bind((tools) => handle.setTools(tools));
|
|
33
|
+
return handle;
|
|
34
|
+
}
|
|
35
|
+
/** Run the agent under its limits. Never throws. */
|
|
36
|
+
export async function runCuratorAgent(options) {
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
let reason = null;
|
|
39
|
+
const stopWith = (why) => {
|
|
40
|
+
reason ??= why;
|
|
41
|
+
controller.abort();
|
|
42
|
+
};
|
|
43
|
+
const usage = { in: 0, out: 0 };
|
|
44
|
+
let turns = 0;
|
|
45
|
+
const external = () => stopWith('aborted');
|
|
46
|
+
if (options.signal?.aborted === true)
|
|
47
|
+
stopWith('aborted');
|
|
48
|
+
else
|
|
49
|
+
options.signal?.addEventListener('abort', external, { once: true });
|
|
50
|
+
const scheduler = options.scheduler ?? realScheduler;
|
|
51
|
+
const cancelTimer = scheduler.after(options.limits.wallMs, () => stopWith('timeout'));
|
|
52
|
+
try {
|
|
53
|
+
const end = await options.handle.run(options.prompt, {
|
|
54
|
+
signal: controller.signal,
|
|
55
|
+
onTurn: (turn) => {
|
|
56
|
+
turns += 1;
|
|
57
|
+
usage.in += turn.in;
|
|
58
|
+
usage.out += turn.out;
|
|
59
|
+
options.onUsage?.(turn);
|
|
60
|
+
if (usage.in + usage.out >= options.limits.tokens)
|
|
61
|
+
stopWith('tokens');
|
|
62
|
+
else if (turns >= options.limits.turns)
|
|
63
|
+
stopWith('turns');
|
|
64
|
+
},
|
|
65
|
+
onToolEnd: () => {
|
|
66
|
+
if (options.shouldStop())
|
|
67
|
+
stopWith('finished');
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
if (reason !== null)
|
|
71
|
+
return { stop: reason, usage, turns };
|
|
72
|
+
if (end.error !== undefined)
|
|
73
|
+
return { stop: 'error', usage, turns, error: end.error };
|
|
74
|
+
return { stop: 'done', usage, turns };
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
cancelTimer();
|
|
78
|
+
options.signal?.removeEventListener('abort', external);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const CURATOR_RETRY_POLICY = { ...DEFAULT_RETRY_POLICY, maxRetries: 1 };
|
|
82
|
+
const JSON_CALL_MAX_TOKENS = 600;
|
|
83
|
+
function lastErrorOf(event) {
|
|
84
|
+
if (event.type !== 'message_update' || event.streamEvent.type !== 'error')
|
|
85
|
+
return null;
|
|
86
|
+
const error = event.streamEvent.error;
|
|
87
|
+
return {
|
|
88
|
+
message: formatStreamError(error),
|
|
89
|
+
...(typeof error.errorType === 'string' ? { errorType: error.errorType } : {}),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function wrapAgent(agent) {
|
|
93
|
+
return {
|
|
94
|
+
setTools: (tools) => agent.setTools(tools),
|
|
95
|
+
dispose: () => agent.abort(),
|
|
96
|
+
async run(prompt, options) {
|
|
97
|
+
let failure;
|
|
98
|
+
const unsubscribe = agent.subscribe((event) => {
|
|
99
|
+
if (event.type === 'turn_end') {
|
|
100
|
+
const usage = event.usage;
|
|
101
|
+
options.onTurn({ in: usage?.inputTokens ?? 0, out: usage?.outputTokens ?? 0 });
|
|
102
|
+
}
|
|
103
|
+
else if (event.type === 'tool_execution_end') {
|
|
104
|
+
options.onToolEnd?.(event.toolName);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
failure = lastErrorOf(event) ?? failure;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const onAbort = () => agent.abort();
|
|
111
|
+
if (options.signal.aborted)
|
|
112
|
+
onAbort();
|
|
113
|
+
else
|
|
114
|
+
options.signal.addEventListener('abort', onAbort, { once: true });
|
|
115
|
+
try {
|
|
116
|
+
await agent.prompt(prompt);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
failure = { message: error instanceof Error ? error.message : String(error) };
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
unsubscribe();
|
|
123
|
+
options.signal.removeEventListener('abort', onAbort);
|
|
124
|
+
}
|
|
125
|
+
return failure === undefined ? {} : { error: failure };
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function parseJson(text) {
|
|
130
|
+
const trimmed = text.trim().replace(/^```(?:json)?\s*/i, '').replace(/\s*```$/, '');
|
|
131
|
+
return JSON.parse(trimmed);
|
|
132
|
+
}
|
|
133
|
+
/** One bounded JSON completion on the chosen model, or null when it cannot be answered. */
|
|
134
|
+
async function completeJsonOn(registry, choice, request, signal) {
|
|
135
|
+
const apiKey = choice.getApiKey(choice.ref.providerId);
|
|
136
|
+
if (apiKey === undefined)
|
|
137
|
+
return null;
|
|
138
|
+
const { ref } = choice;
|
|
139
|
+
const reply = await registry.complete(ref.providerId, {
|
|
140
|
+
model: ref.modelId,
|
|
141
|
+
messages: [{ role: 'user', content: request.user, timestamp: Date.now() }],
|
|
142
|
+
systemPrompt: request.system,
|
|
143
|
+
apiKey,
|
|
144
|
+
...(ref.baseUrl === undefined ? {} : { baseUrl: ref.baseUrl }),
|
|
145
|
+
...(signal === undefined ? {} : { signal }),
|
|
146
|
+
temperature: 0,
|
|
147
|
+
maxTokens: Math.min(request.maxTokens, JSON_CALL_MAX_TOKENS),
|
|
148
|
+
});
|
|
149
|
+
const text = reply.content
|
|
150
|
+
.filter((block) => block.type === 'text')
|
|
151
|
+
.map((block) => block.text)
|
|
152
|
+
.join('');
|
|
153
|
+
const usage = reply.usage;
|
|
154
|
+
try {
|
|
155
|
+
return {
|
|
156
|
+
json: parseJson(text),
|
|
157
|
+
model: ref.modelId,
|
|
158
|
+
...(usage ? { usage: { in: usage.inputTokens ?? 0, out: usage.outputTokens ?? 0 } } : {}),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function agentConfigOf(deps, choice, registry, prompt) {
|
|
166
|
+
return {
|
|
167
|
+
systemPrompt: prompt.systemPrompt,
|
|
168
|
+
model: choice.ref,
|
|
169
|
+
tools: prompt.tools,
|
|
170
|
+
thinkingLevel: 'off',
|
|
171
|
+
providerRegistry: registry,
|
|
172
|
+
getApiKey: (providerId) => choice.getApiKey(providerId),
|
|
173
|
+
maxTokens: deps.maxTokens ?? 4096,
|
|
174
|
+
timeouts: { llmCallTimeout: 90_000, idleTimeout: 90_000, toolTimeout: 30_000 },
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/** The thin production adapter. Everything with a decision in it lives above this line. */
|
|
178
|
+
export function createCuratorModelPort(deps) {
|
|
179
|
+
let registry = null;
|
|
180
|
+
const getRegistry = () => {
|
|
181
|
+
registry ??= deps.registry?.() ?? initProviders({ retryPolicy: CURATOR_RETRY_POLICY });
|
|
182
|
+
return registry;
|
|
183
|
+
};
|
|
184
|
+
const choose = () => {
|
|
185
|
+
const resolved = deps.resolve();
|
|
186
|
+
if (!resolved.ok)
|
|
187
|
+
throw new Error(`curator model unavailable: ${resolved.reason}`);
|
|
188
|
+
return resolved.choice;
|
|
189
|
+
};
|
|
190
|
+
return {
|
|
191
|
+
available() {
|
|
192
|
+
const resolved = deps.resolve();
|
|
193
|
+
if (resolved.ok)
|
|
194
|
+
return { ok: true };
|
|
195
|
+
return { ok: false, reason: resolved.reason, ...(resolved.hint ? { hint: resolved.hint } : {}) };
|
|
196
|
+
},
|
|
197
|
+
createAgent(prompt) {
|
|
198
|
+
const config = agentConfigOf(deps, choose(), getRegistry(), prompt);
|
|
199
|
+
return wrapAgent(deps.agentFactory?.(config) ?? new Agent(config));
|
|
200
|
+
},
|
|
201
|
+
completeJson: (request, signal) => completeJsonOn(getRegistry(), choose(), request, signal),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { GeneConfig } from '@aragon-agent/tui/model/config/schema';
|
|
2
|
+
export interface TaskLimits {
|
|
3
|
+
tokens: number;
|
|
4
|
+
turns: number;
|
|
5
|
+
wallMs: number;
|
|
6
|
+
}
|
|
7
|
+
export interface DailyState {
|
|
8
|
+
limit: number;
|
|
9
|
+
used: number;
|
|
10
|
+
exhausted: boolean;
|
|
11
|
+
/** When the window is expected to have room again; null while under the limit. */
|
|
12
|
+
resetAt: number | null;
|
|
13
|
+
}
|
|
14
|
+
export interface BudgetDeps {
|
|
15
|
+
now(): number;
|
|
16
|
+
/** `GeneRunLog.tokensSince`: the shared, cross-process sum. */
|
|
17
|
+
tokensSince(sinceMs: number): Promise<number>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Cold-start imports (`origin.source === 'import'`) are claimed only while at least this share of
|
|
21
|
+
* the day's token allowance is still unspent: they must never starve live learning.
|
|
22
|
+
*/
|
|
23
|
+
export declare const IMPORT_MIN_REMAINING_SHARE = 0.5;
|
|
24
|
+
/** May a cold-start import proposal be claimed now? Pure over the day's budget state. */
|
|
25
|
+
export declare function importClaimAllowed(daily: Pick<DailyState, 'limit' | 'used'>): boolean;
|
|
26
|
+
export declare class CuratorBudget {
|
|
27
|
+
private readonly deps;
|
|
28
|
+
constructor(deps: BudgetDeps);
|
|
29
|
+
taskLimits(config: Pick<GeneConfig, 'curatorTaskTokens'>): TaskLimits;
|
|
30
|
+
daily(config: Pick<GeneConfig, 'dailyTokens'>): Promise<DailyState>;
|
|
31
|
+
private estimateReset;
|
|
32
|
+
}
|
|
33
|
+
export declare const BREAKER_THRESHOLD = 3;
|
|
34
|
+
export declare const BREAKER_OPEN_MS: number;
|
|
35
|
+
export interface BreakerView {
|
|
36
|
+
state: 'closed' | 'open' | 'half_open';
|
|
37
|
+
/** While open: when the trial request is allowed. */
|
|
38
|
+
until?: number;
|
|
39
|
+
failures: number;
|
|
40
|
+
lastError?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface BreakerOptions {
|
|
43
|
+
now(): number;
|
|
44
|
+
threshold?: number;
|
|
45
|
+
openMs?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Counts INFRASTRUCTURE failures only (model errors, timeouts, lock timeouts). A validation
|
|
49
|
+
* failure is a verdict, not a failure, and a task that used the model successfully resets the
|
|
50
|
+
* streak whatever it decided.
|
|
51
|
+
*/
|
|
52
|
+
export declare class CircuitBreaker {
|
|
53
|
+
private readonly options;
|
|
54
|
+
private failures;
|
|
55
|
+
private openUntil;
|
|
56
|
+
private trialOut;
|
|
57
|
+
private lastError;
|
|
58
|
+
constructor(options: BreakerOptions);
|
|
59
|
+
private threshold;
|
|
60
|
+
private openMs;
|
|
61
|
+
private isTripped;
|
|
62
|
+
view(): BreakerView;
|
|
63
|
+
/** May a model task start now? In half-open exactly ONE caller gets `true`. */
|
|
64
|
+
allow(): boolean;
|
|
65
|
+
recordSuccess(): void;
|
|
66
|
+
recordInfraFailure(error: string): void;
|
|
67
|
+
/** A trial that ended without touching the infrastructure either way is not evidence. */
|
|
68
|
+
releaseTrial(): void;
|
|
69
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the curator may spend, and when it stops asking for more (gene-bank spec 10.3, 10.6, X-2).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* THREE LAYERS, EACH VISIBLE:
|
|
7
|
+
* - per TASK tokens (`gene.curatorTaskTokens`), turns (14) and wall clock (240 s). A task that
|
|
8
|
+
* crosses one is stopped and retried later; it cannot run away.
|
|
9
|
+
* - per DAY a rolling 24 h sum of every `tokens` field in the run log (the learner's, the
|
|
10
|
+
* curator's, the validators' and retrieval's share ONE budget). At the limit the
|
|
11
|
+
* curator pauses and the queue keeps everything. The deterministic P0 paths
|
|
12
|
+
* (revoke, rollback, recheck) never consult it: they spend no tokens.
|
|
13
|
+
* - per FAILURE STREAK three consecutive infrastructure failures open a breaker for 30 minutes;
|
|
14
|
+
* then ONE trial request is let through (half-open) and its result decides.
|
|
15
|
+
*
|
|
16
|
+
* THE RESET TIME IS AN ESTIMATE. A rolling window has no single reset instant: spend ages out
|
|
17
|
+
* hour by hour. `daily()` probes the window an hour at a time and reports the first instant at
|
|
18
|
+
* which the sum is back under the limit, which is what a queued item's `notBefore` and the
|
|
19
|
+
* "paused: daily budget" line show.
|
|
20
|
+
*/
|
|
21
|
+
import { GENE_LIMITS } from '@aragon-agent/tui/model/gene/limits';
|
|
22
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
23
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
24
|
+
/** When the limit is zero there is no instant at which more is allowed; look again in an hour. */
|
|
25
|
+
const ZERO_LIMIT_RECHECK_MS = HOUR_MS;
|
|
26
|
+
/**
|
|
27
|
+
* Cold-start imports (`origin.source === 'import'`) are claimed only while at least this share of
|
|
28
|
+
* the day's token allowance is still unspent: they must never starve live learning.
|
|
29
|
+
*/
|
|
30
|
+
export const IMPORT_MIN_REMAINING_SHARE = 0.5;
|
|
31
|
+
/** May a cold-start import proposal be claimed now? Pure over the day's budget state. */
|
|
32
|
+
export function importClaimAllowed(daily) {
|
|
33
|
+
if (daily.limit <= 0)
|
|
34
|
+
return false;
|
|
35
|
+
return daily.limit - daily.used >= daily.limit * IMPORT_MIN_REMAINING_SHARE;
|
|
36
|
+
}
|
|
37
|
+
export class CuratorBudget {
|
|
38
|
+
deps;
|
|
39
|
+
constructor(deps) {
|
|
40
|
+
this.deps = deps;
|
|
41
|
+
}
|
|
42
|
+
taskLimits(config) {
|
|
43
|
+
return {
|
|
44
|
+
tokens: config.curatorTaskTokens,
|
|
45
|
+
turns: GENE_LIMITS.curatorMaxTurns,
|
|
46
|
+
wallMs: GENE_LIMITS.curatorWallClockMs,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async daily(config) {
|
|
50
|
+
const now = this.deps.now();
|
|
51
|
+
const limit = config.dailyTokens;
|
|
52
|
+
const used = await this.deps.tokensSince(now - DAY_MS);
|
|
53
|
+
if (limit > 0 && used < limit)
|
|
54
|
+
return { limit, used, exhausted: false, resetAt: null };
|
|
55
|
+
return { limit, used, exhausted: true, resetAt: await this.estimateReset(now, limit) };
|
|
56
|
+
}
|
|
57
|
+
async estimateReset(now, limit) {
|
|
58
|
+
if (limit <= 0)
|
|
59
|
+
return now + ZERO_LIMIT_RECHECK_MS;
|
|
60
|
+
for (let hour = 1; hour <= 24; hour += 1) {
|
|
61
|
+
const since = now - DAY_MS + hour * HOUR_MS;
|
|
62
|
+
if ((await this.deps.tokensSince(since)) < limit)
|
|
63
|
+
return now + hour * HOUR_MS;
|
|
64
|
+
}
|
|
65
|
+
return now + DAY_MS;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
// Circuit breaker
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
export const BREAKER_THRESHOLD = 3;
|
|
72
|
+
export const BREAKER_OPEN_MS = 30 * 60 * 1000;
|
|
73
|
+
/**
|
|
74
|
+
* Counts INFRASTRUCTURE failures only (model errors, timeouts, lock timeouts). A validation
|
|
75
|
+
* failure is a verdict, not a failure, and a task that used the model successfully resets the
|
|
76
|
+
* streak whatever it decided.
|
|
77
|
+
*/
|
|
78
|
+
export class CircuitBreaker {
|
|
79
|
+
options;
|
|
80
|
+
failures = 0;
|
|
81
|
+
openUntil = 0;
|
|
82
|
+
trialOut = false;
|
|
83
|
+
lastError;
|
|
84
|
+
constructor(options) {
|
|
85
|
+
this.options = options;
|
|
86
|
+
}
|
|
87
|
+
threshold() {
|
|
88
|
+
return this.options.threshold ?? BREAKER_THRESHOLD;
|
|
89
|
+
}
|
|
90
|
+
openMs() {
|
|
91
|
+
return this.options.openMs ?? BREAKER_OPEN_MS;
|
|
92
|
+
}
|
|
93
|
+
isTripped() {
|
|
94
|
+
return this.failures >= this.threshold();
|
|
95
|
+
}
|
|
96
|
+
view() {
|
|
97
|
+
const base = { failures: this.failures, ...(this.lastError ? { lastError: this.lastError } : {}) };
|
|
98
|
+
if (!this.isTripped())
|
|
99
|
+
return { state: 'closed', ...base };
|
|
100
|
+
if (this.options.now() < this.openUntil)
|
|
101
|
+
return { state: 'open', until: this.openUntil, ...base };
|
|
102
|
+
return { state: 'half_open', ...base };
|
|
103
|
+
}
|
|
104
|
+
/** May a model task start now? In half-open exactly ONE caller gets `true`. */
|
|
105
|
+
allow() {
|
|
106
|
+
const view = this.view();
|
|
107
|
+
if (view.state === 'closed')
|
|
108
|
+
return true;
|
|
109
|
+
if (view.state === 'open' || this.trialOut)
|
|
110
|
+
return false;
|
|
111
|
+
this.trialOut = true;
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
recordSuccess() {
|
|
115
|
+
this.failures = 0;
|
|
116
|
+
this.openUntil = 0;
|
|
117
|
+
this.trialOut = false;
|
|
118
|
+
this.lastError = undefined;
|
|
119
|
+
}
|
|
120
|
+
recordInfraFailure(error) {
|
|
121
|
+
this.failures += 1;
|
|
122
|
+
this.lastError = error.slice(0, 120);
|
|
123
|
+
this.trialOut = false;
|
|
124
|
+
if (this.isTripped())
|
|
125
|
+
this.openUntil = this.options.now() + this.openMs();
|
|
126
|
+
}
|
|
127
|
+
/** A trial that ended without touching the infrastructure either way is not evidence. */
|
|
128
|
+
releaseTrial() {
|
|
129
|
+
this.trialOut = false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { GeneContent, GeneIndexRow, GeneScope, GeneType, GeneValidationCheck } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
import type { ValidatorPorts } from './validate/ports.js';
|
|
3
|
+
import { type NeighbourRelation } from './validate/prompts.js';
|
|
4
|
+
export type { NeighbourRelation };
|
|
5
|
+
export type ConflictDecision = {
|
|
6
|
+
action: 'proceed';
|
|
7
|
+
} | {
|
|
8
|
+
action: 'merge';
|
|
9
|
+
into: string;
|
|
10
|
+
mode: 'fold' | 'replace';
|
|
11
|
+
supersedes: string[];
|
|
12
|
+
by: 'model' | 'code';
|
|
13
|
+
} | {
|
|
14
|
+
action: 'revise';
|
|
15
|
+
target: string;
|
|
16
|
+
by: 'model' | 'code';
|
|
17
|
+
} | {
|
|
18
|
+
action: 'needs_human';
|
|
19
|
+
reason: 'conflict_with_human';
|
|
20
|
+
against: string;
|
|
21
|
+
by: 'model' | 'code';
|
|
22
|
+
};
|
|
23
|
+
export interface ClassifiedNeighbour {
|
|
24
|
+
row: GeneIndexRow;
|
|
25
|
+
relation: NeighbourRelation;
|
|
26
|
+
by: 'model' | 'code';
|
|
27
|
+
}
|
|
28
|
+
/** A gene an agent must never overwrite (G-07, I-7, I-12). */
|
|
29
|
+
export declare function isProtectedGene(row: Pick<GeneIndexRow, 'pinned' | 'trust' | 'class'>): boolean;
|
|
30
|
+
/** Pure routing over already-classified neighbours. See the file header for the table. */
|
|
31
|
+
export declare function decideConflict(neighbours: readonly ClassifiedNeighbour[]): ConflictDecision;
|
|
32
|
+
export interface NeighbourSubject {
|
|
33
|
+
type: GeneType;
|
|
34
|
+
scope: GeneScope;
|
|
35
|
+
content: Pick<GeneContent, 'name' | 'purpose' | 'trigger' | 'tags' | 'body'>;
|
|
36
|
+
/** The candidate's own id (a revise): never its own neighbour. */
|
|
37
|
+
geneId?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function fetchNeighbours(ports: ValidatorPorts, subject: NeighbourSubject): Promise<{
|
|
40
|
+
rows: GeneIndexRow[];
|
|
41
|
+
vec: Int8Array;
|
|
42
|
+
}>;
|
|
43
|
+
/** Same scope, same type, vector cosine at or above the duplicate threshold. */
|
|
44
|
+
export declare function codeDuplicates(candidateVec: Int8Array, scope: GeneScope, rows: readonly GeneIndexRow[]): ClassifiedNeighbour[];
|
|
45
|
+
export interface ConflictReport {
|
|
46
|
+
checks: GeneValidationCheck[];
|
|
47
|
+
decision: ConflictDecision;
|
|
48
|
+
usage: {
|
|
49
|
+
in: number;
|
|
50
|
+
out: number;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Classify the candidate against its neighbours and decide. Never throws. */
|
|
54
|
+
export declare function runConflictCheck(ports: ValidatorPorts, subject: NeighbourSubject): Promise<ConflictReport>;
|