@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,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The user's switches, as the curator reads them (gene-bank spec 14.2, I-18, V-26).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* TWO SOURCES, THE STRICTER WINS. The curator may run in a different process from the one the
|
|
7
|
+
* user is typing in (a terminal holds the lease while the desktop settings page is open). Its
|
|
8
|
+
* own in-process config object therefore cannot be the only truth: the effective value of every
|
|
9
|
+
* safety-relevant setting is the stricter of the LIVE config this process was handed and the
|
|
10
|
+
* PERSISTED `config.json` as it is on disk right now. Either side saying "off" is "off".
|
|
11
|
+
*
|
|
12
|
+
* THE DISK READ IS CHEAP ON PURPOSE. `createPersistedGeneConfigReader` stats the file and only
|
|
13
|
+
* re-parses when the size or mtime moved, so asking at three checkpoints per task costs three
|
|
14
|
+
* `stat` calls in the common case.
|
|
15
|
+
*
|
|
16
|
+
* A BROKEN PERSISTED READER NEVER LOOSENS ANYTHING. If the reader throws or finds no file, the
|
|
17
|
+
* live config alone decides; it can only have made the answer stricter, never wider.
|
|
18
|
+
*/
|
|
19
|
+
import { promises as nodeFs } from 'node:fs';
|
|
20
|
+
import { clampGeneConfig } from '@aragon-agent/tui/model/config/schema';
|
|
21
|
+
/**
|
|
22
|
+
* `min` / `and` of the live and the persisted value. Only the settings that gate safety or spend
|
|
23
|
+
* are tightened; `curatorModel` and the manager-facing knobs stay as the live process has them.
|
|
24
|
+
*/
|
|
25
|
+
export function stricterGeneConfig(live, persisted) {
|
|
26
|
+
if (persisted === null)
|
|
27
|
+
return live;
|
|
28
|
+
const both = (a, b) => a && (b ?? true);
|
|
29
|
+
const least = (a, b) => typeof b === 'number' && Number.isFinite(b) ? Math.min(a, b) : a;
|
|
30
|
+
return {
|
|
31
|
+
...live,
|
|
32
|
+
enabled: both(live.enabled, persisted.enabled),
|
|
33
|
+
use: both(live.use, persisted.use),
|
|
34
|
+
autoLearn: both(live.autoLearn, persisted.autoLearn),
|
|
35
|
+
toolsAllowNetwork: both(live.toolsAllowNetwork, persisted.toolsAllowNetwork),
|
|
36
|
+
probeMode: live.probeMode === 'off' || persisted.probeMode === 'off' ? 'off' : 'readonly',
|
|
37
|
+
dailyTokens: least(live.dailyTokens, persisted.dailyTokens),
|
|
38
|
+
curatorTaskTokens: least(live.curatorTaskTokens, persisted.curatorTaskTokens),
|
|
39
|
+
curatorConcurrency: least(live.curatorConcurrency, persisted.curatorConcurrency),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Does this origin carry SESSION or PROJECT content, so that the per-project switch applies?
|
|
44
|
+
* An exhaustive switch (no `default`) on purpose: a new source is a compile error until someone
|
|
45
|
+
* decides which side of the privacy line it is on.
|
|
46
|
+
*/
|
|
47
|
+
export function sourceCarriesProjectContent(source) {
|
|
48
|
+
switch (source) {
|
|
49
|
+
case 'reviewer':
|
|
50
|
+
case 'import':
|
|
51
|
+
case 'governance':
|
|
52
|
+
return true;
|
|
53
|
+
case 'system':
|
|
54
|
+
case 'user_flag':
|
|
55
|
+
return false;
|
|
56
|
+
default: {
|
|
57
|
+
const never = source;
|
|
58
|
+
return never;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** One object the host, the tools and the publish gate all ask, so there is one definition. */
|
|
63
|
+
export class SwitchGuard {
|
|
64
|
+
deps;
|
|
65
|
+
constructor(deps) {
|
|
66
|
+
this.deps = deps;
|
|
67
|
+
}
|
|
68
|
+
async effective() {
|
|
69
|
+
const live = this.deps.live();
|
|
70
|
+
if (this.deps.persisted === undefined)
|
|
71
|
+
return live;
|
|
72
|
+
try {
|
|
73
|
+
return stricterGeneConfig(live, await this.deps.persisted());
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return live;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async check() {
|
|
80
|
+
const config = await this.effective();
|
|
81
|
+
if (!config.enabled)
|
|
82
|
+
return { on: false, reason: 'disabled', config };
|
|
83
|
+
if (this.deps.redteam?.() === true)
|
|
84
|
+
return { on: false, reason: 'redteam', config };
|
|
85
|
+
if (!config.autoLearn)
|
|
86
|
+
return { on: false, reason: 'learning_off', config };
|
|
87
|
+
return { on: true, config };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The per-project switch for ONE proposal's origin. Deliberately NOT part of `check()`: the
|
|
91
|
+
* global verdict pauses the whole curator, whereas a project exclusion must only drop the
|
|
92
|
+
* proposals that came from that project and leave every other project's work running.
|
|
93
|
+
*
|
|
94
|
+
* `projectKey === null` (an origin that predates the field) cannot be judged and is allowed;
|
|
95
|
+
* the learner, which holds the project root, is the authority at the moment content would leave
|
|
96
|
+
* the machine. A repository marker is only visible when `project.json` names the root.
|
|
97
|
+
*/
|
|
98
|
+
async checkFor(origin) {
|
|
99
|
+
if (origin.projectKey === null || this.deps.projects === undefined)
|
|
100
|
+
return { on: true };
|
|
101
|
+
if (!sourceCarriesProjectContent(origin.source))
|
|
102
|
+
return { on: true };
|
|
103
|
+
let root = null;
|
|
104
|
+
try {
|
|
105
|
+
root = await this.deps.projects.rootOf(origin.projectKey);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
root = null;
|
|
109
|
+
}
|
|
110
|
+
const verdict = await this.deps.projects.policy.refresh(origin.projectKey, root);
|
|
111
|
+
return verdict.learn ? { on: true } : { on: false, reason: 'project_excluded' };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Reads the `gene` section of the user's config file, caching on `size:mtime`. A missing or
|
|
116
|
+
* unparsable file reads as null (the live config then decides alone).
|
|
117
|
+
*/
|
|
118
|
+
export function createPersistedGeneConfigReader(options) {
|
|
119
|
+
let cache = null;
|
|
120
|
+
return async () => {
|
|
121
|
+
let stamp;
|
|
122
|
+
try {
|
|
123
|
+
const stat = await nodeFs.stat(options.path);
|
|
124
|
+
stamp = `${stat.size}:${stat.mtimeMs}`;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
cache = null;
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
if (cache !== null && cache.stamp === stamp)
|
|
131
|
+
return cache.value;
|
|
132
|
+
options.onParse?.();
|
|
133
|
+
let value = null;
|
|
134
|
+
try {
|
|
135
|
+
const parsed = JSON.parse(await nodeFs.readFile(options.path, 'utf8'));
|
|
136
|
+
if (parsed !== null && typeof parsed.gene === 'object' && parsed.gene !== null) {
|
|
137
|
+
value = clampGeneConfig(parsed.gene);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
value = null;
|
|
142
|
+
}
|
|
143
|
+
cache = { stamp, value };
|
|
144
|
+
return value;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state of ONE curator task, shared by its tools and its runner (gene-bank spec 9.5, 10.3).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHY A CONTEXT OBJECT. The curator's tools are plain functions the model calls; what makes them
|
|
7
|
+
* safe is what they know about the task they belong to: which proposal, which basis, which
|
|
8
|
+
* candidates THIS task created, what the validators said about each of them. A tool must be able
|
|
9
|
+
* to refuse "publish gs_x" when nothing validated gs_x in this task, and the runner must be able
|
|
10
|
+
* to settle the queue item from what the tools did and not from what the model claims.
|
|
11
|
+
*
|
|
12
|
+
* `assertCuratorContext` IS THE GATE THE SPEC ASKS FOR (9.5): every management tool calls it
|
|
13
|
+
* first. A tool array is only ever built around a context, and the context goes inactive the
|
|
14
|
+
* moment its task ends, so a leaked tool reference (or a foreground agent handed the array by
|
|
15
|
+
* mistake) finds a dead context and gets a refusal instead of a library write.
|
|
16
|
+
*/
|
|
17
|
+
import { type ToolResult } from '@aragon-agent/core';
|
|
18
|
+
import type { GeneClass, GeneEvidence, GeneNeedsHuman, GeneProposal, GeneScope, GeneType } from '@aragon-agent/tui/model/gene/types';
|
|
19
|
+
import type { EvidenceInput } from '../commit-types.js';
|
|
20
|
+
import type { ClaimedItem } from '../queue.js';
|
|
21
|
+
import type { CandidateOutcome } from './validate/index.js';
|
|
22
|
+
export type FinishOutcome = 'published' | 'merged' | 'rejected' | 'needs_human' | 'no_change' | 'retry';
|
|
23
|
+
export declare const FINISH_OUTCOMES: readonly FinishOutcome[];
|
|
24
|
+
/** Why a task was dropped half way; each maps to a `superseded` queue outcome. */
|
|
25
|
+
export type AbandonReason = 'learning_off' | 'stale_basis' | 'human_edit' | 'cancelled' | 'forgotten' | 'redteam' | 'disabled' | 'project_excluded';
|
|
26
|
+
export interface CandidateRef {
|
|
27
|
+
id: string;
|
|
28
|
+
scope: GeneScope;
|
|
29
|
+
type: GeneType;
|
|
30
|
+
version: number;
|
|
31
|
+
/** The class the model asked for; anything but `standard` was demoted and is reported. */
|
|
32
|
+
requestedClass?: GeneClass;
|
|
33
|
+
}
|
|
34
|
+
export interface StoredValidation {
|
|
35
|
+
outcome: CandidateOutcome;
|
|
36
|
+
/** The candidate's content hash at validation time: a later edit invalidates the verdict. */
|
|
37
|
+
contentHash: string;
|
|
38
|
+
version: number;
|
|
39
|
+
}
|
|
40
|
+
export interface FinishRequest {
|
|
41
|
+
outcome: FinishOutcome;
|
|
42
|
+
note: string;
|
|
43
|
+
}
|
|
44
|
+
export interface TaskUsage {
|
|
45
|
+
/** Tokens spent by the validators' own model calls in this task. */
|
|
46
|
+
validation: {
|
|
47
|
+
in: number;
|
|
48
|
+
out: number;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export declare const CURATOR_CONTEXT_BRAND: unique symbol;
|
|
52
|
+
export interface CuratorTaskContext {
|
|
53
|
+
readonly brand: typeof CURATOR_CONTEXT_BRAND;
|
|
54
|
+
/** False once the task has ended: every tool then refuses. */
|
|
55
|
+
active: boolean;
|
|
56
|
+
proposal: GeneProposal;
|
|
57
|
+
claimed: ClaimedItem;
|
|
58
|
+
scope: GeneScope;
|
|
59
|
+
/** Proposal evidence, redacted, with refs minted once so every commit and check agrees. */
|
|
60
|
+
evidence: GeneEvidence[];
|
|
61
|
+
evidenceInputs: EvidenceInput[];
|
|
62
|
+
/** Gene ids whose commit already carried the evidence (it is added once per gene). */
|
|
63
|
+
evidenceAttached: Set<string>;
|
|
64
|
+
/** `latestVersion` of every gene the proposal names, as read when the task started. */
|
|
65
|
+
basis: Map<string, number>;
|
|
66
|
+
/** The queue item's basis moved after the proposal was made; evaluate once on the new one. */
|
|
67
|
+
rebased: boolean;
|
|
68
|
+
/** How many times a write hit a moved basis; the second one drops the task. */
|
|
69
|
+
staleHits: number;
|
|
70
|
+
candidates: Map<string, CandidateRef>;
|
|
71
|
+
validations: Map<string, StoredValidation>;
|
|
72
|
+
usage: TaskUsage;
|
|
73
|
+
finish: FinishRequest | null;
|
|
74
|
+
abandoned: AbandonReason | null;
|
|
75
|
+
/** Ids this task made published (create/revise publish, merge survivor). */
|
|
76
|
+
published: string[];
|
|
77
|
+
merged: string[];
|
|
78
|
+
needsHuman: GeneNeedsHuman['reason'] | null;
|
|
79
|
+
/** Whether a gene-writing call already took place (a retry needs to know). */
|
|
80
|
+
wrote: boolean;
|
|
81
|
+
}
|
|
82
|
+
export interface ContextSeed {
|
|
83
|
+
proposal: GeneProposal;
|
|
84
|
+
claimed: ClaimedItem;
|
|
85
|
+
evidence: GeneEvidence[];
|
|
86
|
+
evidenceInputs: EvidenceInput[];
|
|
87
|
+
basis: Map<string, number>;
|
|
88
|
+
rebased: boolean;
|
|
89
|
+
}
|
|
90
|
+
export declare function createTaskContext(seed: ContextSeed): CuratorTaskContext;
|
|
91
|
+
/** A tool refusal, or null when the context is a live curator task. Never throws. */
|
|
92
|
+
export declare function assertCuratorContext(ctx: CuratorTaskContext | undefined): ToolResult | null;
|
|
93
|
+
export declare function validationKey(id: string, version: number): string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state of ONE curator task, shared by its tools and its runner (gene-bank spec 9.5, 10.3).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHY A CONTEXT OBJECT. The curator's tools are plain functions the model calls; what makes them
|
|
7
|
+
* safe is what they know about the task they belong to: which proposal, which basis, which
|
|
8
|
+
* candidates THIS task created, what the validators said about each of them. A tool must be able
|
|
9
|
+
* to refuse "publish gs_x" when nothing validated gs_x in this task, and the runner must be able
|
|
10
|
+
* to settle the queue item from what the tools did and not from what the model claims.
|
|
11
|
+
*
|
|
12
|
+
* `assertCuratorContext` IS THE GATE THE SPEC ASKS FOR (9.5): every management tool calls it
|
|
13
|
+
* first. A tool array is only ever built around a context, and the context goes inactive the
|
|
14
|
+
* moment its task ends, so a leaked tool reference (or a foreground agent handed the array by
|
|
15
|
+
* mistake) finds a dead context and gets a refusal instead of a library write.
|
|
16
|
+
*/
|
|
17
|
+
import { errorResult } from '@aragon-agent/core';
|
|
18
|
+
export const FINISH_OUTCOMES = [
|
|
19
|
+
'published',
|
|
20
|
+
'merged',
|
|
21
|
+
'rejected',
|
|
22
|
+
'needs_human',
|
|
23
|
+
'no_change',
|
|
24
|
+
'retry',
|
|
25
|
+
];
|
|
26
|
+
export const CURATOR_CONTEXT_BRAND = Symbol('gene-curator-context');
|
|
27
|
+
export function createTaskContext(seed) {
|
|
28
|
+
return {
|
|
29
|
+
brand: CURATOR_CONTEXT_BRAND,
|
|
30
|
+
active: true,
|
|
31
|
+
proposal: seed.proposal,
|
|
32
|
+
claimed: seed.claimed,
|
|
33
|
+
scope: seed.proposal.scope,
|
|
34
|
+
evidence: seed.evidence,
|
|
35
|
+
evidenceInputs: seed.evidenceInputs,
|
|
36
|
+
evidenceAttached: new Set(),
|
|
37
|
+
basis: seed.basis,
|
|
38
|
+
rebased: seed.rebased,
|
|
39
|
+
staleHits: 0,
|
|
40
|
+
candidates: new Map(),
|
|
41
|
+
validations: new Map(),
|
|
42
|
+
usage: { validation: { in: 0, out: 0 } },
|
|
43
|
+
finish: null,
|
|
44
|
+
abandoned: null,
|
|
45
|
+
published: [],
|
|
46
|
+
merged: [],
|
|
47
|
+
needsHuman: null,
|
|
48
|
+
wrote: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** A tool refusal, or null when the context is a live curator task. Never throws. */
|
|
52
|
+
export function assertCuratorContext(ctx) {
|
|
53
|
+
if (ctx === undefined || ctx.brand !== CURATOR_CONTEXT_BRAND) {
|
|
54
|
+
return errorResult('GENE_PERMISSION_DENIED - this tool belongs to the gene curator only.');
|
|
55
|
+
}
|
|
56
|
+
if (!ctx.active) {
|
|
57
|
+
return errorResult('GENE_PERMISSION_DENIED - the curator task this tool belonged to has ended.');
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
export function validationKey(id, version) {
|
|
62
|
+
return `${id}@${version}`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { GeneEvidence, GeneProposal } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
import type { EvidenceInput } from '../commit-types.js';
|
|
3
|
+
import type { ClaimedItem, GeneQueue, QueueFailure } from '../queue.js';
|
|
4
|
+
import type { QueueResult } from '../queue-record.js';
|
|
5
|
+
import { type CuratorModelPort } from './agent.js';
|
|
6
|
+
import type { CircuitBreaker, CuratorBudget } from './budget.js';
|
|
7
|
+
import type { CuratorToolDeps } from './tool-support.js';
|
|
8
|
+
import type { HubScheduler } from '../hub.js';
|
|
9
|
+
export type TaskOutcome = {
|
|
10
|
+
kind: 'complete';
|
|
11
|
+
result: QueueResult;
|
|
12
|
+
detail: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'fail';
|
|
15
|
+
failure: QueueFailure;
|
|
16
|
+
infra: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'release';
|
|
19
|
+
reason: string;
|
|
20
|
+
notBefore?: number;
|
|
21
|
+
}
|
|
22
|
+
/** The proposal's source project is switched off: settle it with its text stripped (I3-5). */
|
|
23
|
+
| {
|
|
24
|
+
kind: 'drop_excluded';
|
|
25
|
+
};
|
|
26
|
+
export interface ModelBlock {
|
|
27
|
+
reason: 'no_fast_tier' | 'curator_failing' | 'daily_budget';
|
|
28
|
+
/** When the item may be looked at again. */
|
|
29
|
+
until: number;
|
|
30
|
+
}
|
|
31
|
+
export interface TaskRunnerDeps {
|
|
32
|
+
queue: Pick<GeneQueue, 'enqueue' | 'isCancelled'>;
|
|
33
|
+
toolDeps: CuratorToolDeps;
|
|
34
|
+
model: CuratorModelPort;
|
|
35
|
+
budget: CuratorBudget;
|
|
36
|
+
breaker: CircuitBreaker;
|
|
37
|
+
random(n: number): number;
|
|
38
|
+
scheduler?: Pick<HubScheduler, 'after'>;
|
|
39
|
+
/** Why model work cannot start right now, or null. Deterministic work is never blocked. */
|
|
40
|
+
modelBlocked(): ModelBlock | null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The proposal's evidence with refs minted ONCE: the validators' corpus (redacted exactly as the
|
|
44
|
+
* commit will store it) and the inputs every commit carries, so a ref cited in a draft is the ref
|
|
45
|
+
* on disk.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mintEvidence(proposal: GeneProposal, options: {
|
|
48
|
+
secrets: readonly string[];
|
|
49
|
+
now: number;
|
|
50
|
+
random: (n: number) => number;
|
|
51
|
+
}): {
|
|
52
|
+
evidence: GeneEvidence[];
|
|
53
|
+
inputs: EvidenceInput[];
|
|
54
|
+
};
|
|
55
|
+
/** Decide one claimed item. Never throws; the host turns an unexpected failure into a retry. */
|
|
56
|
+
export declare function runClaimedTask(deps: TaskRunnerDeps, claimed: ClaimedItem, signal: AbortSignal): Promise<TaskOutcome>;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One claimed queue item, from claim to verdict (gene-bank spec 10.3, 10.5.5, 10.6).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* `runClaimedTask` is the curator's whole decision procedure for one item and RETURNS what should
|
|
7
|
+
* happen to the queue file (`TaskOutcome`); the host does the queue call. Keeping the two apart
|
|
8
|
+
* means this function can be tested with a scripted model and a real library, and the host's loop
|
|
9
|
+
* can be tested with a stub runner.
|
|
10
|
+
*
|
|
11
|
+
* 1 checkpoint one of three: the user's switches, read now (stricter of live and persisted)
|
|
12
|
+
* 2 `planTask`: the deterministic skeleton, no model
|
|
13
|
+
* 3 settle / release / direct execution when the plan says so
|
|
14
|
+
* 4 otherwise the model task: ONE agent, the three always-on tools, the proposal as data,
|
|
15
|
+
* the per-task limits enforced around it
|
|
16
|
+
* 5 the verdict is taken from FACTS on the task context (what was published, merged, flagged),
|
|
17
|
+
* not from the model's summary: `gene_finish` records a claim, the facts settle the item
|
|
18
|
+
*
|
|
19
|
+
* A TASK THAT ENDS WITHOUT `gene_finish` IS A RETRY (10.3). A task that ran out of tokens or turns
|
|
20
|
+
* is a retry too, and counts as an attempt so a proposal that always overruns reaches `dead/`
|
|
21
|
+
* instead of looping; a deadline or a model error is an INFRASTRUCTURE failure and is what the
|
|
22
|
+
* circuit breaker counts. A daily-budget stop is not the item's fault and costs no attempt.
|
|
23
|
+
*/
|
|
24
|
+
import { mintEvidenceRef } from '@aragon-agent/tui/model/gene/ids';
|
|
25
|
+
import { redactSecrets } from '../secrets.js';
|
|
26
|
+
import { assembleCuratorAgent, runCuratorAgent } from './agent.js';
|
|
27
|
+
import { planTask } from './deterministic.js';
|
|
28
|
+
import { executeDirect } from './executors.js';
|
|
29
|
+
import { buildTaskPrompt, CURATOR_SYSTEM_PROMPT } from './prompt.js';
|
|
30
|
+
import { createTaskContext } from './task-context.js';
|
|
31
|
+
import { createCuratorToolkit } from './tools.js';
|
|
32
|
+
import { settleLeftovers } from './tools-release.js';
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Evidence
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
function defaultTrust(kind) {
|
|
37
|
+
if (kind === 'user_statement')
|
|
38
|
+
return 'user';
|
|
39
|
+
return kind === 'url' ? 'untrusted' : 'agent';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The proposal's evidence with refs minted ONCE: the validators' corpus (redacted exactly as the
|
|
43
|
+
* commit will store it) and the inputs every commit carries, so a ref cited in a draft is the ref
|
|
44
|
+
* on disk.
|
|
45
|
+
*/
|
|
46
|
+
export function mintEvidence(proposal, options) {
|
|
47
|
+
const evidence = [];
|
|
48
|
+
const inputs = [];
|
|
49
|
+
const taken = new Set();
|
|
50
|
+
for (const item of proposal.evidence) {
|
|
51
|
+
let ref = mintEvidenceRef(options.random);
|
|
52
|
+
while (taken.has(ref))
|
|
53
|
+
ref = mintEvidenceRef(options.random);
|
|
54
|
+
taken.add(ref);
|
|
55
|
+
const trust = item.trust ?? defaultTrust(item.kind);
|
|
56
|
+
const scrubbed = redactSecrets(item.text, options.secrets);
|
|
57
|
+
evidence.push({
|
|
58
|
+
schema: 1,
|
|
59
|
+
ref,
|
|
60
|
+
geneId: '',
|
|
61
|
+
capturedAt: options.now,
|
|
62
|
+
kind: item.kind,
|
|
63
|
+
trust,
|
|
64
|
+
source: item.source ?? {},
|
|
65
|
+
text: scrubbed.text,
|
|
66
|
+
redacted: scrubbed.redacted,
|
|
67
|
+
});
|
|
68
|
+
inputs.push({ ...item, trust, ref });
|
|
69
|
+
}
|
|
70
|
+
return { evidence, inputs };
|
|
71
|
+
}
|
|
72
|
+
function newContext(deps, claimed, seed) {
|
|
73
|
+
const minted = mintEvidence(claimed.item.proposal, {
|
|
74
|
+
secrets: deps.toolDeps.knownSecrets(),
|
|
75
|
+
now: deps.toolDeps.now(),
|
|
76
|
+
random: deps.random,
|
|
77
|
+
});
|
|
78
|
+
return createTaskContext({
|
|
79
|
+
proposal: claimed.item.proposal,
|
|
80
|
+
claimed,
|
|
81
|
+
evidence: minted.evidence,
|
|
82
|
+
evidenceInputs: minted.inputs,
|
|
83
|
+
basis: seed.basis,
|
|
84
|
+
rebased: seed.rebased,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// Outcomes
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
function scopeFields(proposal) {
|
|
91
|
+
return { proposalId: proposal.id, scope: proposal.scope };
|
|
92
|
+
}
|
|
93
|
+
async function settleOutcome(deps, proposal, plan) {
|
|
94
|
+
await deps.toolDeps.events.emit(plan.event, { ...scopeFields(proposal), detail: plan.detail });
|
|
95
|
+
return { kind: 'complete', result: plan.result, detail: plan.detail };
|
|
96
|
+
}
|
|
97
|
+
async function directOutcome(deps, proposal, res) {
|
|
98
|
+
if (res.failure !== undefined) {
|
|
99
|
+
deps.breaker.recordInfraFailure(res.failure.kind === 'transient' ? res.failure.error : 'executor');
|
|
100
|
+
return { kind: 'fail', failure: res.failure, infra: true };
|
|
101
|
+
}
|
|
102
|
+
if (res.event !== undefined) {
|
|
103
|
+
await deps.toolDeps.events.emit(res.event, {
|
|
104
|
+
...scopeFields(proposal),
|
|
105
|
+
...(res.geneId === undefined ? {} : { geneId: res.geneId }),
|
|
106
|
+
detail: res.detail,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return { kind: 'complete', result: res.result, detail: res.detail };
|
|
110
|
+
}
|
|
111
|
+
async function abandonOutcome(deps, proposal, reason) {
|
|
112
|
+
if (reason === 'redteam' || reason === 'disabled')
|
|
113
|
+
return { kind: 'release', reason };
|
|
114
|
+
if (reason === 'project_excluded') {
|
|
115
|
+
await deps.toolDeps.events.emit('skipped', { ...scopeFields(proposal), detail: 'project_excluded' });
|
|
116
|
+
return { kind: 'drop_excluded' };
|
|
117
|
+
}
|
|
118
|
+
const result = reason === 'forgotten' ? 'forgotten' : 'superseded';
|
|
119
|
+
const event = reason === 'forgotten' ? 'skipped' : 'superseded';
|
|
120
|
+
await deps.toolDeps.events.emit(event, { ...scopeFields(proposal), detail: reason });
|
|
121
|
+
return { kind: 'complete', result, detail: reason };
|
|
122
|
+
}
|
|
123
|
+
/** What the facts on the context already decide, or null when they are silent. */
|
|
124
|
+
async function factualOutcome(deps, env) {
|
|
125
|
+
const { ctx } = env;
|
|
126
|
+
if (ctx.published.length > 0) {
|
|
127
|
+
await settleLeftovers(env, 'reject_all');
|
|
128
|
+
return { kind: 'complete', result: 'published', detail: 'published' };
|
|
129
|
+
}
|
|
130
|
+
if (ctx.merged.length > 0)
|
|
131
|
+
return { kind: 'complete', result: 'merged', detail: 'merged' };
|
|
132
|
+
if (ctx.needsHuman === null)
|
|
133
|
+
return null;
|
|
134
|
+
return { kind: 'complete', result: 'needs_human', detail: ctx.needsHuman };
|
|
135
|
+
}
|
|
136
|
+
/** The model decided nothing needed doing (or that the proposal was wrong): clean up and say so. */
|
|
137
|
+
async function declinedOutcome(deps, env, rejected) {
|
|
138
|
+
await settleLeftovers(env, 'reject_all');
|
|
139
|
+
if (!rejected || env.ctx.candidates.size === 0) {
|
|
140
|
+
await deps.toolDeps.events.emit(rejected ? 'rejected' : 'skipped', {
|
|
141
|
+
...scopeFields(env.ctx.proposal),
|
|
142
|
+
detail: rejected ? 'no_candidate' : 'no_change',
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const result = rejected ? 'rejected' : 'no_change';
|
|
146
|
+
return { kind: 'complete', result, detail: rejected ? 'curator_decision' : 'no_change' };
|
|
147
|
+
}
|
|
148
|
+
/** What the facts say happened, falling back to the model's own claim only when they are silent. */
|
|
149
|
+
async function finishedOutcome(deps, env, finish) {
|
|
150
|
+
const factual = await factualOutcome(deps, env);
|
|
151
|
+
if (factual !== null)
|
|
152
|
+
return factual;
|
|
153
|
+
if (finish.outcome === 'needs_human') {
|
|
154
|
+
await deps.toolDeps.events.emit('needs_human', { ...scopeFields(env.ctx.proposal), detail: 'curator' });
|
|
155
|
+
return { kind: 'complete', result: 'needs_human', detail: 'curator' };
|
|
156
|
+
}
|
|
157
|
+
if (finish.outcome === 'retry') {
|
|
158
|
+
await settleLeftovers(env, 'reject_failed');
|
|
159
|
+
return { kind: 'fail', failure: { kind: 'transient', error: 'model_retry' }, infra: false };
|
|
160
|
+
}
|
|
161
|
+
return declinedOutcome(deps, env, finish.outcome === 'rejected');
|
|
162
|
+
}
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
// The model task
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
async function modelOutcome(deps, env, summary) {
|
|
167
|
+
const { ctx } = env;
|
|
168
|
+
if (ctx.abandoned !== null)
|
|
169
|
+
return abandonOutcome(deps, ctx.proposal, ctx.abandoned);
|
|
170
|
+
if (summary.stop === 'aborted')
|
|
171
|
+
return { kind: 'release', reason: 'released' };
|
|
172
|
+
if (summary.stop === 'error' || summary.stop === 'timeout') {
|
|
173
|
+
const error = summary.stop === 'timeout' ? 'task_timeout' : (summary.error?.errorType ?? 'model_error');
|
|
174
|
+
deps.breaker.recordInfraFailure(error);
|
|
175
|
+
await settleLeftovers(env, 'reject_failed');
|
|
176
|
+
return { kind: 'fail', failure: { kind: 'transient', error }, infra: true };
|
|
177
|
+
}
|
|
178
|
+
deps.breaker.recordSuccess();
|
|
179
|
+
if (ctx.finish !== null)
|
|
180
|
+
return finishedOutcome(deps, env, ctx.finish);
|
|
181
|
+
await settleLeftovers(env, 'reject_failed');
|
|
182
|
+
const error = summary.stop === 'tokens' || summary.stop === 'turns' ? 'task_budget' : 'no_finish';
|
|
183
|
+
return { kind: 'fail', failure: { kind: 'transient', error }, infra: false };
|
|
184
|
+
}
|
|
185
|
+
async function runModelTask(deps, claimed, plan, signal) {
|
|
186
|
+
const proposal = claimed.item.proposal;
|
|
187
|
+
const blocked = deps.modelBlocked();
|
|
188
|
+
if (blocked !== null)
|
|
189
|
+
return { kind: 'release', reason: blocked.reason, notBefore: blocked.until };
|
|
190
|
+
const config = await deps.toolDeps.switches.effective();
|
|
191
|
+
const daily = await deps.budget.daily(config);
|
|
192
|
+
if (daily.exhausted) {
|
|
193
|
+
const resetAt = daily.resetAt ?? deps.toolDeps.now() + 60 * 60 * 1000;
|
|
194
|
+
return { kind: 'fail', failure: { kind: 'budget', resetAt }, infra: false };
|
|
195
|
+
}
|
|
196
|
+
const ctx = newContext(deps, claimed, { basis: plan.basis, rebased: plan.rebased });
|
|
197
|
+
const env = { ctx, deps: deps.toolDeps };
|
|
198
|
+
const handle = assembleCuratorAgent(deps.model, CURATOR_SYSTEM_PROMPT, createCuratorToolkit(env));
|
|
199
|
+
try {
|
|
200
|
+
await deps.toolDeps.events.emit('distilling', {
|
|
201
|
+
...scopeFields(proposal),
|
|
202
|
+
...(proposal.type === undefined ? {} : { type: proposal.type }),
|
|
203
|
+
detail: `kind=${proposal.kind}`,
|
|
204
|
+
});
|
|
205
|
+
const summary = await runCuratorAgent({
|
|
206
|
+
handle,
|
|
207
|
+
prompt: buildTaskPrompt({
|
|
208
|
+
proposal,
|
|
209
|
+
evidence: ctx.evidence,
|
|
210
|
+
heads: plan.heads.map((read) => ({ head: read.head })),
|
|
211
|
+
rebased: plan.rebased,
|
|
212
|
+
}),
|
|
213
|
+
limits: deps.budget.taskLimits(config),
|
|
214
|
+
signal,
|
|
215
|
+
shouldStop: () => ctx.finish !== null || ctx.abandoned !== null,
|
|
216
|
+
onUsage: (usage) => deps.toolDeps.ledger.add('curator', usage),
|
|
217
|
+
...(deps.scheduler === undefined ? {} : { scheduler: deps.scheduler }),
|
|
218
|
+
});
|
|
219
|
+
return await modelOutcome(deps, env, summary);
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
ctx.active = false;
|
|
223
|
+
handle.dispose();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
// Entry point
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
/** Decide one claimed item. Never throws; the host turns an unexpected failure into a retry. */
|
|
230
|
+
export async function runClaimedTask(deps, claimed, signal) {
|
|
231
|
+
const proposal = claimed.item.proposal;
|
|
232
|
+
const { events, switches, library, isForgotten } = deps.toolDeps;
|
|
233
|
+
const verdict = await switches.check();
|
|
234
|
+
await events.emit('claimed', {
|
|
235
|
+
...scopeFields(proposal),
|
|
236
|
+
...(proposal.type === undefined ? {} : { type: proposal.type }),
|
|
237
|
+
detail: `kind=${proposal.kind}`,
|
|
238
|
+
});
|
|
239
|
+
const detDeps = { library, isForgotten, isCancelled: (c) => deps.queue.isCancelled(c) };
|
|
240
|
+
const plan = await planTask(detDeps, claimed, verdict);
|
|
241
|
+
if (plan.mode === 'settle')
|
|
242
|
+
return settleOutcome(deps, proposal, plan);
|
|
243
|
+
if (plan.mode === 'release')
|
|
244
|
+
return { kind: 'release', reason: plan.reason };
|
|
245
|
+
if (plan.mode === 'model')
|
|
246
|
+
return runModelTask(deps, claimed, plan, signal);
|
|
247
|
+
const ctx = newContext(deps, claimed, { basis: new Map(), rebased: false });
|
|
248
|
+
const env = { ctx, deps: deps.toolDeps };
|
|
249
|
+
const config = await switches.effective();
|
|
250
|
+
try {
|
|
251
|
+
const result = await executeDirect({ env, queue: deps.queue, random: deps.random, capPerType: config.capPerType }, plan.action);
|
|
252
|
+
return await directOutcome(deps, proposal, result);
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
ctx.active = false;
|
|
256
|
+
}
|
|
257
|
+
}
|