@aragon-agent/cli 0.6.55 → 0.6.57
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 +2935 -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 +104 -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 +206 -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 +243 -0
- package/dist/gene/curator/tools-write.d.ts +26 -0
- package/dist/gene/curator/tools-write.js +434 -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 +24 -0
- package/dist/gene/curator/validate/evidence-tokens.js +217 -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 +41 -0
- package/dist/gene/curator/validate/knowledge.js +255 -0
- package/dist/gene/curator/validate/live-check.d.ts +14 -0
- package/dist/gene/curator/validate/live-check.js +150 -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 +165 -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 +116 -0
- package/dist/gene/learn/learn-call.js +165 -0
- package/dist/gene/learn/learn-prompt.d.ts +58 -0
- package/dist/gene/learn/learn-prompt.js +254 -0
- package/dist/gene/learn/learner.d.ts +187 -0
- package/dist/gene/learn/learner.js +448 -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 +207 -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 +84 -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,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The release group: `gene_publish`, `gene_revoke`, `gene_rollback`, `gene_finish`
|
|
3
|
+
* (gene-bank spec 9.5, 10.7.4, 16.2), and the functions the deterministic executors share with them.
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* `publishCandidate` is the only path from "candidate" to "current" for the curator. It asks the
|
|
8
|
+
* publish gate (`evaluatePublishGate`) and commits only on `ok`; a refusal is turned into the
|
|
9
|
+
* right fate for the task - dropped as superseded, parked for a person, or fixable by the model -
|
|
10
|
+
* on the context, where the runner reads it. The commit itself is the version service's, with the
|
|
11
|
+
* basis it was read at, so a gene that moved a millisecond after the gate is refused there too and
|
|
12
|
+
* never overwritten (I-10).
|
|
13
|
+
*
|
|
14
|
+
* `revokeGene` and `rollbackGene` are DETERMINISTIC: no model is involved in deciding that a
|
|
15
|
+
* harmful gene is withdrawn or that a failed probation returns to the previous version. The tools
|
|
16
|
+
* wrap them for the model; the probation sweep and the revoke executor call them directly.
|
|
17
|
+
*
|
|
18
|
+
* `gene_finish` IS THE ONLY WAY TO END A TASK, and it only RECORDS the model's claim. The runner
|
|
19
|
+
* settles the queue item from what happened (published ids, merged ids, flags), and
|
|
20
|
+
* `gene_finish` refuses a claim the facts contradict ("published" with nothing published) so a
|
|
21
|
+
* confident wrong summary cannot mark an item done.
|
|
22
|
+
*/
|
|
23
|
+
import type { AgentTool } from '@aragon-agent/core';
|
|
24
|
+
import type { GeneHead, GeneResult, GeneScope } from '@aragon-agent/tui/model/gene/types';
|
|
25
|
+
import type { CommitOutcome } from '../commit-types.js';
|
|
26
|
+
import type { CuratorLibrary } from './library.js';
|
|
27
|
+
import { type ToolEnv } from './tool-support.js';
|
|
28
|
+
export type PublishResult = {
|
|
29
|
+
kind: 'published';
|
|
30
|
+
version: number;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'needs_human';
|
|
33
|
+
code: string;
|
|
34
|
+
message: string;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'refused';
|
|
37
|
+
code: string;
|
|
38
|
+
message: string;
|
|
39
|
+
};
|
|
40
|
+
/** Make a validated candidate current. Never throws. */
|
|
41
|
+
export declare function publishCandidate(env: ToolEnv, request: {
|
|
42
|
+
id: string;
|
|
43
|
+
expectedVersion?: number;
|
|
44
|
+
}): Promise<PublishResult>;
|
|
45
|
+
/** What revoke and rollback need; the probation sweep has no task, so it cannot supply a context. */
|
|
46
|
+
export interface ReleaseEnv {
|
|
47
|
+
service: ToolEnv['deps']['service'];
|
|
48
|
+
library: Pick<CuratorLibrary, 'readHead' | 'listVersionNumbers' | 'readVersion'>;
|
|
49
|
+
scope: GeneScope;
|
|
50
|
+
/** The version each gene was at when the work began; the commit refuses a moved head. */
|
|
51
|
+
basis?: ReadonlyMap<string, number>;
|
|
52
|
+
}
|
|
53
|
+
export declare function releaseEnvOf(env: ToolEnv): ReleaseEnv;
|
|
54
|
+
export declare function revokeGene(env: ReleaseEnv, request: {
|
|
55
|
+
id: string;
|
|
56
|
+
reason: string;
|
|
57
|
+
harmful?: boolean;
|
|
58
|
+
}): Promise<GeneResult<CommitOutcome>>;
|
|
59
|
+
/** The newest version before the current one that was once published, or null. */
|
|
60
|
+
export declare function previousPublishedVersion(library: Pick<CuratorLibrary, 'listVersionNumbers' | 'readVersion'>, head: GeneHead): Promise<number | null>;
|
|
61
|
+
export declare function rollbackGene(env: ReleaseEnv, request: {
|
|
62
|
+
id: string;
|
|
63
|
+
toVersion?: number;
|
|
64
|
+
}): Promise<GeneResult<CommitOutcome>>;
|
|
65
|
+
export declare function releaseTools(env: ToolEnv): AgentTool[];
|
|
66
|
+
/**
|
|
67
|
+
* Candidates this task created and did not publish. A VALIDATION VERDICT is final, so a candidate
|
|
68
|
+
* that failed is rejected with the verdict on record (the manager shows why); an unvalidated one is
|
|
69
|
+
* kept when the task will be retried (it is the footprint the retry resumes from, RV-25) and
|
|
70
|
+
* rejected when the model decided there was nothing to keep. A candidate waiting for a person is
|
|
71
|
+
* never touched.
|
|
72
|
+
*/
|
|
73
|
+
export declare function settleLeftovers(env: ToolEnv, mode: 'reject_failed' | 'reject_all'): Promise<void>;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { geneFail } from '../gene-errors.js';
|
|
2
|
+
import { evaluatePublishGate } from './publish.js';
|
|
3
|
+
import { FINISH_OUTCOMES, validationKey, } from './task-context.js';
|
|
4
|
+
import { flagNeedsHuman } from './tools-verify.js';
|
|
5
|
+
import { CURATOR_ACTOR, applyFailureEffects, asInteger, asString, cancelGate, cleanNote, defineCuratorTool, failureResult, noteStale, reasonOf, receipt, refuse, } from './tool-support.js';
|
|
6
|
+
/** Make a validated candidate current. Never throws. */
|
|
7
|
+
export async function publishCandidate(env, request) {
|
|
8
|
+
const { ctx, deps } = env;
|
|
9
|
+
const cancelled = await cancelGate(env, 'gene_publish');
|
|
10
|
+
if (cancelled !== null)
|
|
11
|
+
return { kind: 'refused', code: 'GENE_STALE_BASIS', message: 'The task was cancelled.' };
|
|
12
|
+
const read = await deps.library.readHead(ctx.scope, request.id);
|
|
13
|
+
const candidateVersion = read?.head.candidateVersion ?? null;
|
|
14
|
+
if (read === null || candidateVersion === null) {
|
|
15
|
+
return { kind: 'refused', code: 'GENE_NOT_FOUND', message: 'That gene has no candidate to publish.' };
|
|
16
|
+
}
|
|
17
|
+
const version = await deps.library.readVersion(ctx.scope, request.id, candidateVersion);
|
|
18
|
+
if (version === null)
|
|
19
|
+
return { kind: 'refused', code: 'GENE_NOT_FOUND', message: 'The candidate version is missing.' };
|
|
20
|
+
const verdict = await evaluatePublishGate({ switches: deps.switches, isForgotten: deps.isForgotten }, {
|
|
21
|
+
head: read.head,
|
|
22
|
+
version,
|
|
23
|
+
stored: ctx.validations.get(validationKey(request.id, version.n)),
|
|
24
|
+
expectedVersion: request.expectedVersion ?? read.head.latestVersion,
|
|
25
|
+
mode: 'candidate',
|
|
26
|
+
proposalCreatedAt: ctx.proposal.createdAt,
|
|
27
|
+
originProjectKey: ctx.proposal.origin.projectKey ?? null,
|
|
28
|
+
originSource: ctx.proposal.origin.source,
|
|
29
|
+
});
|
|
30
|
+
if (!verdict.ok)
|
|
31
|
+
return refusalOf(env, read.head, verdict);
|
|
32
|
+
await deps.events.emit('validating', {
|
|
33
|
+
proposalId: ctx.proposal.id,
|
|
34
|
+
geneId: request.id,
|
|
35
|
+
version: version.n,
|
|
36
|
+
scope: ctx.scope,
|
|
37
|
+
type: read.head.type,
|
|
38
|
+
detail: `stage=publishing name=${read.head.brief.name}`,
|
|
39
|
+
});
|
|
40
|
+
const done = await deps.service.commit({
|
|
41
|
+
op: 'publishCandidate',
|
|
42
|
+
scope: ctx.scope,
|
|
43
|
+
id: request.id,
|
|
44
|
+
reason: 'Validated and published by the curator.',
|
|
45
|
+
validation: verdict.validation,
|
|
46
|
+
proposalId: ctx.proposal.id,
|
|
47
|
+
}, CURATOR_ACTOR, { version: read.head.latestVersion });
|
|
48
|
+
return afterCommit(env, request.id, version, done);
|
|
49
|
+
}
|
|
50
|
+
function afterCommit(env, id, version, done) {
|
|
51
|
+
if (!done.ok) {
|
|
52
|
+
applyFailureEffects(env.ctx, done);
|
|
53
|
+
return { kind: 'refused', code: done.detail ? `${done.code}:${done.detail}` : done.code, message: done.message };
|
|
54
|
+
}
|
|
55
|
+
env.ctx.wrote = true;
|
|
56
|
+
if (done.value.needsHuman === true) {
|
|
57
|
+
env.ctx.needsHuman = 'conflict_with_human';
|
|
58
|
+
return { kind: 'needs_human', code: 'GENE_CONFLICT_WITH_HUMAN', message: 'A person must decide.' };
|
|
59
|
+
}
|
|
60
|
+
env.ctx.published.push(id);
|
|
61
|
+
return { kind: 'published', version: version.n };
|
|
62
|
+
}
|
|
63
|
+
async function refusalOf(env, head, verdict) {
|
|
64
|
+
if (verdict.abandon !== undefined)
|
|
65
|
+
env.ctx.abandoned = verdict.abandon;
|
|
66
|
+
if (verdict.stale === true)
|
|
67
|
+
noteStale(env.ctx);
|
|
68
|
+
if (verdict.needsHuman !== undefined) {
|
|
69
|
+
await flagNeedsHuman(env, head, verdict.needsHuman);
|
|
70
|
+
return { kind: 'needs_human', code: verdict.code, message: verdict.message };
|
|
71
|
+
}
|
|
72
|
+
return { kind: 'refused', code: verdict.code, message: verdict.message };
|
|
73
|
+
}
|
|
74
|
+
function publishTool(env) {
|
|
75
|
+
return defineCuratorTool(env, {
|
|
76
|
+
name: 'gene_publish',
|
|
77
|
+
label: 'Publish candidate',
|
|
78
|
+
description: 'Run the publish gate and make a validated candidate current.\n' +
|
|
79
|
+
'It re-checks the switches, the basis, trust, the forgotten list and the tool probe policy ' +
|
|
80
|
+
'before it commits. Pass expectedVersion = the version you validated.',
|
|
81
|
+
parameters: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: { id: { type: 'string' }, version: { type: 'number' }, expectedVersion: { type: 'number' } },
|
|
84
|
+
required: ['id'],
|
|
85
|
+
},
|
|
86
|
+
async run(params) {
|
|
87
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
88
|
+
const result = await publishCandidate(env, {
|
|
89
|
+
id,
|
|
90
|
+
...(typeof params.expectedVersion === 'number' ? { expectedVersion: Math.floor(params.expectedVersion) } : {}),
|
|
91
|
+
});
|
|
92
|
+
if (result.kind === 'published')
|
|
93
|
+
return receipt(`Published ${id} v${result.version}. Next: gene_finish published.`);
|
|
94
|
+
if (result.kind === 'needs_human') {
|
|
95
|
+
return refuse('gene_publish', result.code, `${result.message} Finish needs_human.`);
|
|
96
|
+
}
|
|
97
|
+
return refuse('gene_publish', result.code, result.message);
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export function releaseEnvOf(env) {
|
|
102
|
+
return { service: env.deps.service, library: env.deps.library, scope: env.ctx.scope, basis: env.ctx.basis };
|
|
103
|
+
}
|
|
104
|
+
export async function revokeGene(env, request) {
|
|
105
|
+
const read = await env.library.readHead(env.scope, request.id);
|
|
106
|
+
if (read === null)
|
|
107
|
+
return geneFail('GENE_NOT_FOUND', 'The gene was not found in that state.', 'missing');
|
|
108
|
+
return env.service.commit({
|
|
109
|
+
op: 'revoke',
|
|
110
|
+
scope: env.scope,
|
|
111
|
+
id: request.id,
|
|
112
|
+
reason: request.reason,
|
|
113
|
+
...(request.harmful === true ? { harmful: true } : {}),
|
|
114
|
+
}, CURATOR_ACTOR, { version: env.basis?.get(request.id) ?? read.head.latestVersion });
|
|
115
|
+
}
|
|
116
|
+
/** The newest version before the current one that was once published, or null. */
|
|
117
|
+
export async function previousPublishedVersion(library, head) {
|
|
118
|
+
if (head.currentVersion === null)
|
|
119
|
+
return null;
|
|
120
|
+
const numbers = (await library.listVersionNumbers(head.scope, head.id))
|
|
121
|
+
.filter((n) => n < head.currentVersion)
|
|
122
|
+
.sort((a, b) => b - a);
|
|
123
|
+
for (const n of numbers) {
|
|
124
|
+
if ((await library.readVersion(head.scope, head.id, n))?.state === 'superseded')
|
|
125
|
+
return n;
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
export async function rollbackGene(env, request) {
|
|
130
|
+
const read = await env.library.readHead(env.scope, request.id);
|
|
131
|
+
if (read === null)
|
|
132
|
+
return geneFail('GENE_NOT_FOUND', 'The gene was not found in that state.', 'missing');
|
|
133
|
+
const toVersion = request.toVersion ?? (await previousPublishedVersion(env.library, read.head));
|
|
134
|
+
if (toVersion === null)
|
|
135
|
+
return geneFail('GENE_NOT_FOUND', 'There is no earlier published version.', 'version');
|
|
136
|
+
return env.service.commit({ op: 'rollback', scope: env.scope, id: request.id, toVersion }, CURATOR_ACTOR, { version: read.head.latestVersion });
|
|
137
|
+
}
|
|
138
|
+
function revokeTool(env) {
|
|
139
|
+
return defineCuratorTool(env, {
|
|
140
|
+
name: 'gene_revoke',
|
|
141
|
+
label: 'Revoke gene',
|
|
142
|
+
description: 'Withdraw a harmful or wrong gene so no agent sees it. Deterministic, no model judgement.\n' +
|
|
143
|
+
'A pinned gene is refused (GENE_PINNED). reason is required, at most 200 characters.',
|
|
144
|
+
parameters: {
|
|
145
|
+
type: 'object',
|
|
146
|
+
properties: { id: { type: 'string' }, reason: { type: 'string' }, harmful: { type: 'boolean' } },
|
|
147
|
+
required: ['id', 'reason'],
|
|
148
|
+
},
|
|
149
|
+
async run(params) {
|
|
150
|
+
const reason = reasonOf(env, 'gene_revoke', params.reason);
|
|
151
|
+
if (!reason.ok)
|
|
152
|
+
return reason.result;
|
|
153
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
154
|
+
const done = await revokeGene(releaseEnvOf(env), { id, reason: reason.value, harmful: params.harmful === true });
|
|
155
|
+
if (!done.ok) {
|
|
156
|
+
applyFailureEffects(env.ctx, done);
|
|
157
|
+
return failureResult('gene_revoke', done);
|
|
158
|
+
}
|
|
159
|
+
env.ctx.wrote = true;
|
|
160
|
+
return receipt(`Revoked ${id}.`);
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function rollbackTool(env) {
|
|
165
|
+
return defineCuratorTool(env, {
|
|
166
|
+
name: 'gene_rollback',
|
|
167
|
+
label: 'Roll back gene',
|
|
168
|
+
description: 'Make the content of an earlier published version current again, as a NEW version.\n' +
|
|
169
|
+
'Omit toVersion to return to the previous published version. Deterministic.',
|
|
170
|
+
parameters: {
|
|
171
|
+
type: 'object',
|
|
172
|
+
properties: { id: { type: 'string' }, reason: { type: 'string' }, toVersion: { type: 'number' } },
|
|
173
|
+
required: ['id', 'reason'],
|
|
174
|
+
},
|
|
175
|
+
async run(params) {
|
|
176
|
+
const reason = reasonOf(env, 'gene_rollback', params.reason);
|
|
177
|
+
if (!reason.ok)
|
|
178
|
+
return reason.result;
|
|
179
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
180
|
+
const toVersion = typeof params.toVersion === 'number' ? asInteger(params.toVersion, 0, 1, 1_000_000) : undefined;
|
|
181
|
+
const done = await rollbackGene(releaseEnvOf(env), { id, ...(toVersion === undefined ? {} : { toVersion }) });
|
|
182
|
+
if (!done.ok) {
|
|
183
|
+
applyFailureEffects(env.ctx, done);
|
|
184
|
+
return failureResult('gene_rollback', done);
|
|
185
|
+
}
|
|
186
|
+
if (done.value.needsHuman === true) {
|
|
187
|
+
env.ctx.needsHuman = 'conflict_with_human';
|
|
188
|
+
return refuse('gene_rollback', 'GENE_CONFLICT_WITH_HUMAN', 'A person owns this gene; nothing was changed. Finish needs_human.');
|
|
189
|
+
}
|
|
190
|
+
env.ctx.wrote = true;
|
|
191
|
+
return receipt(`Rolled ${id} back; new version v${done.value.version ?? '?'}.`);
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
// finish
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
function contradiction(env, outcome) {
|
|
199
|
+
const { ctx } = env;
|
|
200
|
+
if (outcome === 'published' && ctx.published.length === 0) {
|
|
201
|
+
return 'nothing was published in this task; finish no_change, rejected, needs_human or retry.';
|
|
202
|
+
}
|
|
203
|
+
if (outcome === 'merged' && ctx.merged.length === 0) {
|
|
204
|
+
return 'nothing was merged in this task; finish with the outcome that matches what happened.';
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
function finishTool(env) {
|
|
209
|
+
return defineCuratorTool(env, {
|
|
210
|
+
name: 'gene_finish',
|
|
211
|
+
label: 'Finish task',
|
|
212
|
+
description: 'End this task. Required: a task that stops without it counts as retry.\n' +
|
|
213
|
+
'outcome is published, merged, rejected, needs_human, no_change or retry. note is at most ' +
|
|
214
|
+
'200 characters and never contains secrets or gene text.',
|
|
215
|
+
parameters: {
|
|
216
|
+
type: 'object',
|
|
217
|
+
properties: {
|
|
218
|
+
outcome: { type: 'string', enum: [...FINISH_OUTCOMES] },
|
|
219
|
+
note: { type: 'string' },
|
|
220
|
+
},
|
|
221
|
+
required: ['outcome'],
|
|
222
|
+
},
|
|
223
|
+
async run(params) {
|
|
224
|
+
const outcome = asString(params.outcome);
|
|
225
|
+
if (!FINISH_OUTCOMES.includes(outcome)) {
|
|
226
|
+
return refuse('gene_finish', 'GENE_ARGS_INVALID', `outcome must be one of ${FINISH_OUTCOMES.join(', ')}.`);
|
|
227
|
+
}
|
|
228
|
+
const claim = outcome;
|
|
229
|
+
const wrong = contradiction(env, claim);
|
|
230
|
+
if (wrong !== null)
|
|
231
|
+
return refuse('gene_finish', 'GENE_ARGS_INVALID', wrong);
|
|
232
|
+
env.ctx.finish = { outcome: claim, note: cleanNote(params.note, env.deps.knownSecrets()) ?? '' };
|
|
233
|
+
return receipt(`Task finished: ${claim}.`);
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
export function releaseTools(env) {
|
|
238
|
+
return [publishTool(env), revokeTool(env), rollbackTool(env), finishTool(env)];
|
|
239
|
+
}
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
// leftovers
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
/**
|
|
244
|
+
* Candidates this task created and did not publish. A VALIDATION VERDICT is final, so a candidate
|
|
245
|
+
* that failed is rejected with the verdict on record (the manager shows why); an unvalidated one is
|
|
246
|
+
* kept when the task will be retried (it is the footprint the retry resumes from, RV-25) and
|
|
247
|
+
* rejected when the model decided there was nothing to keep. A candidate waiting for a person is
|
|
248
|
+
* never touched.
|
|
249
|
+
*/
|
|
250
|
+
export async function settleLeftovers(env, mode) {
|
|
251
|
+
const { ctx, deps } = env;
|
|
252
|
+
for (const ref of ctx.candidates.values()) {
|
|
253
|
+
if (ctx.published.includes(ref.id))
|
|
254
|
+
continue;
|
|
255
|
+
const read = await deps.library.readHead(ref.scope, ref.id).catch(() => null);
|
|
256
|
+
if (read === null || read.head.candidateVersion !== ref.version)
|
|
257
|
+
continue;
|
|
258
|
+
if (read.head.needsHuman !== undefined)
|
|
259
|
+
continue;
|
|
260
|
+
const stored = ctx.validations.get(validationKey(ref.id, ref.version));
|
|
261
|
+
const failed = stored?.outcome.verdict === 'fail';
|
|
262
|
+
if (mode === 'reject_failed' && !failed)
|
|
263
|
+
continue;
|
|
264
|
+
await rejectLeftover(env, { ref, failed, stored, basis: read.head.latestVersion });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async function rejectLeftover(env, leftover) {
|
|
268
|
+
const { ctx, deps } = env;
|
|
269
|
+
const { ref, failed, stored } = leftover;
|
|
270
|
+
const reason = failed ? 'Validation failed; kept for review.' : 'The curator decided not to keep this draft.';
|
|
271
|
+
await deps.service.commit({
|
|
272
|
+
op: 'rejectCandidate',
|
|
273
|
+
scope: ref.scope,
|
|
274
|
+
id: ref.id,
|
|
275
|
+
reason,
|
|
276
|
+
...(stored === undefined ? {} : { validation: stored.outcome.validation }),
|
|
277
|
+
}, CURATOR_ACTOR, { version: leftover.basis });
|
|
278
|
+
if (!failed)
|
|
279
|
+
return;
|
|
280
|
+
await deps.events.emit('validation_failed', {
|
|
281
|
+
proposalId: ctx.proposal.id,
|
|
282
|
+
geneId: ref.id,
|
|
283
|
+
version: ref.version,
|
|
284
|
+
scope: ref.scope,
|
|
285
|
+
type: ref.type,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `gene_validate` and `gene_probe_tool`, and the validation run they share
|
|
3
|
+
* (gene-bank spec 9.5, 10.7, 16.2; I-6, I-25).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* `runCandidateValidation` is the ONE place the curator turns a candidate into a verdict. The
|
|
8
|
+
* `gene_validate` tool, the merge tool (which publishes straight away and so validates inline)
|
|
9
|
+
* and the resume-from-validation executor all call it, so there is one definition of the context
|
|
10
|
+
* handed to the validators: the evidence snapshot with its minted refs, the script text of a
|
|
11
|
+
* script tool, the trigger probe of a skill, the head being replaced.
|
|
12
|
+
*
|
|
13
|
+
* THE VERDICT IS STORED ON THE TASK, KEYED BY VERSION AND CONTENT HASH. `gene_publish` refuses a
|
|
14
|
+
* candidate that has no stored passing verdict for exactly the content it is about to publish, so
|
|
15
|
+
* "edit after validating" cannot slip an unvalidated body through (the hash differs) and "publish
|
|
16
|
+
* without validating" is impossible by construction.
|
|
17
|
+
*
|
|
18
|
+
* `gene_probe_tool` NEVER EXECUTES ANYTHING ON ITS OWN AUTHORITY. It calls `autoProbe`, which
|
|
19
|
+
* spawns only for a read-only whitelisted single command under `probeMode: readonly` and otherwise
|
|
20
|
+
* answers `GENE_PROBE_NEEDS_APPROVAL` with zero spawns; the answer parks the candidate for a
|
|
21
|
+
* person (I-25). The curator never runs a script, a composite or a workspace-writing command.
|
|
22
|
+
*/
|
|
23
|
+
import type { AgentTool } from '@aragon-agent/core';
|
|
24
|
+
import type { GeneClass, GeneContent, GeneHead, GeneScope, GeneType } from '@aragon-agent/tui/model/gene/types';
|
|
25
|
+
import { type StoredValidation } from './task-context.js';
|
|
26
|
+
import { type CandidateOutcome } from './validate/index.js';
|
|
27
|
+
import { type ToolEnv } from './tool-support.js';
|
|
28
|
+
export interface ValidationTarget {
|
|
29
|
+
type: GeneType;
|
|
30
|
+
scope: GeneScope;
|
|
31
|
+
geneId: string;
|
|
32
|
+
version: number;
|
|
33
|
+
contentHash: string;
|
|
34
|
+
content: GeneContent;
|
|
35
|
+
requestedClass?: GeneClass;
|
|
36
|
+
head?: GeneHead;
|
|
37
|
+
headContent?: GeneContent;
|
|
38
|
+
/** Neighbours that must not count as conflicts (the members of a merge). */
|
|
39
|
+
excludeNeighbours?: ReadonlySet<string>;
|
|
40
|
+
}
|
|
41
|
+
/** Validate a candidate and remember the verdict on the task. Never throws past its caller's guard. */
|
|
42
|
+
export declare function runCandidateValidation(env: ToolEnv, target: ValidationTarget): Promise<StoredValidation>;
|
|
43
|
+
/** `K1 ok; K2 FAIL(KNOWLEDGE_EVIDENCE_UNRESOLVED: ...)`: codes and the validators' own details. */
|
|
44
|
+
export declare function summariseChecks(outcome: CandidateOutcome): string;
|
|
45
|
+
/** Flag a candidate for a person; the foreground never sees it (I-6). Best effort. */
|
|
46
|
+
export declare function flagNeedsHuman(env: ToolEnv, head: GeneHead, reason: NonNullable<ToolEnv['ctx']['needsHuman']>): Promise<void>;
|
|
47
|
+
export declare function verifyTools(env: ToolEnv): AgentTool[];
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { autoProbe } from './probe.js';
|
|
2
|
+
import { validationKey } from './task-context.js';
|
|
3
|
+
import { validateCandidateDetailed } from './validate/index.js';
|
|
4
|
+
import { repairLines, resolveEvidence } from './validate/knowledge.js';
|
|
5
|
+
import { CURATOR_ACTOR, asString, defineCuratorTool, receipt, refuse, switchGate, } from './tool-support.js';
|
|
6
|
+
function scriptRefOf(content) {
|
|
7
|
+
const exec = content.payload.exec;
|
|
8
|
+
return exec !== undefined && exec.kind === 'script' ? exec.evidence : undefined;
|
|
9
|
+
}
|
|
10
|
+
async function scriptTextOf(env, target) {
|
|
11
|
+
const ref = scriptRefOf(target.content);
|
|
12
|
+
if (ref === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
const fresh = env.ctx.evidence.find((e) => e.ref === ref);
|
|
15
|
+
if (fresh !== undefined)
|
|
16
|
+
return fresh.text;
|
|
17
|
+
const stored = await env.deps.library.readEvidence(target.scope, target.geneId, ref);
|
|
18
|
+
return stored?.text;
|
|
19
|
+
}
|
|
20
|
+
function portsFor(base, exclude) {
|
|
21
|
+
if (exclude === undefined || exclude.size === 0)
|
|
22
|
+
return base;
|
|
23
|
+
return {
|
|
24
|
+
...base,
|
|
25
|
+
neighbours: async (scope, type, brief, k) => (await base.neighbours(scope, type, brief, k + exclude.size)).filter((r) => !exclude.has(r.id)).slice(0, k),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function evidenceSnapshot(env, geneId) {
|
|
29
|
+
return env.ctx.evidence.map((e) => ({ ...e, geneId }));
|
|
30
|
+
}
|
|
31
|
+
/** Validate a candidate and remember the verdict on the task. Never throws past its caller's guard. */
|
|
32
|
+
export async function runCandidateValidation(env, target) {
|
|
33
|
+
const { ctx, deps } = env;
|
|
34
|
+
const ports = portsFor(await deps.validatorPorts(ctx), target.excludeNeighbours);
|
|
35
|
+
const scriptText = await scriptTextOf(env, target);
|
|
36
|
+
const outcome = await validateCandidateDetailed({
|
|
37
|
+
ports,
|
|
38
|
+
type: target.type,
|
|
39
|
+
scope: target.scope,
|
|
40
|
+
content: target.content,
|
|
41
|
+
evidence: evidenceSnapshot(env, target.geneId),
|
|
42
|
+
geneId: target.geneId,
|
|
43
|
+
...(target.requestedClass === undefined ? {} : { requestedClass: target.requestedClass }),
|
|
44
|
+
...(target.head === undefined
|
|
45
|
+
? {}
|
|
46
|
+
: { target: { head: target.head, ...(target.headContent === undefined ? {} : { content: target.headContent }) } }),
|
|
47
|
+
...(scriptText === undefined ? {} : { scriptText }),
|
|
48
|
+
...(target.type === 'skill' ? { triggerProbe: { positives: [ctx.proposal.origin.goal] } } : {}),
|
|
49
|
+
...(deps.probeDeps === undefined ? {} : { probeDeps: deps.probeDeps }),
|
|
50
|
+
});
|
|
51
|
+
deps.ledger.add('validation', outcome.usage);
|
|
52
|
+
ctx.usage.validation.in += outcome.usage.in;
|
|
53
|
+
ctx.usage.validation.out += outcome.usage.out;
|
|
54
|
+
const stored = { outcome, contentHash: target.contentHash, version: target.version };
|
|
55
|
+
ctx.validations.set(validationKey(target.geneId, target.version), stored);
|
|
56
|
+
return stored;
|
|
57
|
+
}
|
|
58
|
+
/** `K1 ok; K2 FAIL(KNOWLEDGE_EVIDENCE_UNRESOLVED: ...)`: codes and the validators' own details. */
|
|
59
|
+
export function summariseChecks(outcome) {
|
|
60
|
+
return outcome.validation.checks
|
|
61
|
+
.map((c) => (c.ok ? `${c.code} ok` : `${c.code} FAIL${c.detail ? `(${c.detail})` : ''}`))
|
|
62
|
+
.join('; ');
|
|
63
|
+
}
|
|
64
|
+
async function candidateOf(env, id, version) {
|
|
65
|
+
const read = await env.deps.library.readHead(env.ctx.scope, id);
|
|
66
|
+
if (read === null)
|
|
67
|
+
return 'GENE_NOT_FOUND - no live gene with that id in this scope.';
|
|
68
|
+
const wanted = version ?? read.head.candidateVersion;
|
|
69
|
+
if (wanted === null || wanted !== read.head.candidateVersion) {
|
|
70
|
+
return 'GENE_NOT_FOUND - that version is not the gene\'s candidate.';
|
|
71
|
+
}
|
|
72
|
+
const found = await env.deps.library.readVersion(env.ctx.scope, id, wanted);
|
|
73
|
+
return found === null ? 'GENE_NOT_FOUND - that version does not exist.' : { head: read.head, version: found };
|
|
74
|
+
}
|
|
75
|
+
/** Flag a candidate for a person; the foreground never sees it (I-6). Best effort. */
|
|
76
|
+
export async function flagNeedsHuman(env, head, reason) {
|
|
77
|
+
env.ctx.needsHuman = reason;
|
|
78
|
+
const needsHuman = { reason, at: env.deps.now(), proposalId: env.ctx.proposal.id };
|
|
79
|
+
await env.deps.service.commit({ op: 'setNeedsHuman', scope: head.scope, id: head.id, needsHuman }, CURATOR_ACTOR);
|
|
80
|
+
}
|
|
81
|
+
async function rejectConverted(env, head, outcome) {
|
|
82
|
+
if (!env.ctx.candidates.has(head.id) || head.currentVersion !== null)
|
|
83
|
+
return;
|
|
84
|
+
await env.deps.service.commit({
|
|
85
|
+
op: 'rejectCandidate',
|
|
86
|
+
scope: head.scope,
|
|
87
|
+
id: head.id,
|
|
88
|
+
reason: 'Converted to a merge or revise of an existing gene.',
|
|
89
|
+
validation: outcome.validation,
|
|
90
|
+
}, CURATOR_ACTOR, { version: head.latestVersion });
|
|
91
|
+
}
|
|
92
|
+
function conflictAdvice(outcome) {
|
|
93
|
+
const c = outcome.conflict;
|
|
94
|
+
if (c === undefined || c.action === 'proceed')
|
|
95
|
+
return '';
|
|
96
|
+
if (c.action === 'merge')
|
|
97
|
+
return ` Conflict: merge into ${c.into}; use gene_merge.`;
|
|
98
|
+
if (c.action === 'revise')
|
|
99
|
+
return ` Conflict: revise ${c.target}; use gene_revise.`;
|
|
100
|
+
return ` Conflict with a person-owned gene (${c.against}); finish needs_human.`;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The tokens K2 could not find, listed verbatim so the curator can fix the draft instead of
|
|
104
|
+
* ending the task (RV-17, B3). `symbol x8` is a verdict the model cannot act on: the same
|
|
105
|
+
* rejection repeats on every re-proposal and the experience is lost.
|
|
106
|
+
*
|
|
107
|
+
* THIS STRING IS THE TOOL'S ANSWER AND NOTHING ELSE. It is built from the model's own draft and
|
|
108
|
+
* its own evidence, and it never reaches `validation.detail` or the manager UI, which stay redacted
|
|
109
|
+
* to kinds and counts (I-19). The evidence is resolved the same way K2 resolved it, so a ref that
|
|
110
|
+
* lives on disk cannot be reported as missing.
|
|
111
|
+
*/
|
|
112
|
+
async function repairsFor(env, head, content) {
|
|
113
|
+
if (head.type !== 'knowledge')
|
|
114
|
+
return [];
|
|
115
|
+
try {
|
|
116
|
+
const ports = await env.deps.validatorPorts(env.ctx);
|
|
117
|
+
const evidence = evidenceSnapshot(env, head.id);
|
|
118
|
+
const resolved = await resolveEvidence(ports, head.scope, head.id, content, evidence);
|
|
119
|
+
return repairLines(content, resolved.corpus.map((e) => e.text).join('\n'));
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// A library that cannot be read must not turn a verdict into a crash; the redacted detail stays.
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Only K2's miss list is actionable: it names specifics the model itself wrote. Every other code
|
|
128
|
+
* (`GENE_INVALID_CONTENT`, a scope misfit) already names the field to change, so paying for an
|
|
129
|
+
* evidence resolution to print more would be noise.
|
|
130
|
+
*/
|
|
131
|
+
function needsRepair(outcome) {
|
|
132
|
+
return outcome.validation.checks.some((c) => !c.ok && c.code === 'KNOWLEDGE_EVIDENCE_UNRESOLVED');
|
|
133
|
+
}
|
|
134
|
+
/** ` To fix: ...` when the failing checks can be made actionable, otherwise nothing. */
|
|
135
|
+
async function fixAdvice(env, head, version, outcome) {
|
|
136
|
+
if (!needsRepair(outcome))
|
|
137
|
+
return '';
|
|
138
|
+
const lines = await repairsFor(env, head, version.content);
|
|
139
|
+
return lines.length === 0 ? '' : ` To fix: ${lines.join('. ')}`;
|
|
140
|
+
}
|
|
141
|
+
/** What a verdict beyond "pass" or "fail" needs done to the library, and what to tell the model. */
|
|
142
|
+
async function actOnVerdict(env, head, outcome) {
|
|
143
|
+
if (outcome.verdict === 'needs_human') {
|
|
144
|
+
if (outcome.needsHuman !== undefined)
|
|
145
|
+
await flagNeedsHuman(env, head, outcome.needsHuman);
|
|
146
|
+
return ' Finish needs_human.';
|
|
147
|
+
}
|
|
148
|
+
if (outcome.verdict !== 'convert')
|
|
149
|
+
return '';
|
|
150
|
+
await rejectConverted(env, head, outcome);
|
|
151
|
+
return conflictAdvice(outcome);
|
|
152
|
+
}
|
|
153
|
+
async function currentContentOf(env, head) {
|
|
154
|
+
if (head.currentVersion === null)
|
|
155
|
+
return undefined;
|
|
156
|
+
return (await env.deps.library.readVersion(head.scope, head.id, head.currentVersion))?.content;
|
|
157
|
+
}
|
|
158
|
+
/** Run the validation of `params.id`, store the verdict, and act on a verdict that needs more. */
|
|
159
|
+
async function validateCandidate(env, params) {
|
|
160
|
+
const blocked = await switchGate(env, 'gene_validate');
|
|
161
|
+
if (blocked !== null)
|
|
162
|
+
return blocked;
|
|
163
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
164
|
+
const requested = typeof params.version === 'number' ? Math.floor(params.version) : undefined;
|
|
165
|
+
const found = await candidateOf(env, id, requested);
|
|
166
|
+
if (typeof found === 'string') {
|
|
167
|
+
const [code, message] = found.split(' - ');
|
|
168
|
+
return refuse('gene_validate', code, message ?? '');
|
|
169
|
+
}
|
|
170
|
+
const { head, version: v } = found;
|
|
171
|
+
const headContent = await currentContentOf(env, head);
|
|
172
|
+
const requestedClass = env.ctx.candidates.get(id)?.requestedClass;
|
|
173
|
+
const stored = await runCandidateValidation(env, {
|
|
174
|
+
type: head.type,
|
|
175
|
+
scope: head.scope,
|
|
176
|
+
geneId: id,
|
|
177
|
+
version: v.n,
|
|
178
|
+
contentHash: v.contentHash,
|
|
179
|
+
content: v.content,
|
|
180
|
+
head,
|
|
181
|
+
...(headContent === undefined ? {} : { headContent }),
|
|
182
|
+
...(requestedClass === undefined ? {} : { requestedClass }),
|
|
183
|
+
});
|
|
184
|
+
const { outcome } = stored;
|
|
185
|
+
await env.deps.events.emit('validating', {
|
|
186
|
+
proposalId: env.ctx.proposal.id,
|
|
187
|
+
geneId: id,
|
|
188
|
+
version: v.n,
|
|
189
|
+
scope: head.scope,
|
|
190
|
+
type: head.type,
|
|
191
|
+
detail: `name=${head.brief.name}`,
|
|
192
|
+
});
|
|
193
|
+
const advice = await actOnVerdict(env, head, outcome);
|
|
194
|
+
const fix = await fixAdvice(env, head, v, outcome);
|
|
195
|
+
return receipt(`${id} v${v.n}: verdict=${outcome.verdict}. ${summariseChecks(outcome)}.${advice}${fix}`);
|
|
196
|
+
}
|
|
197
|
+
function validateTool(env) {
|
|
198
|
+
return defineCuratorTool(env, {
|
|
199
|
+
name: 'gene_validate',
|
|
200
|
+
label: 'Validate candidate',
|
|
201
|
+
description: 'Run the type-specific validation on a candidate and return every check.\n' +
|
|
202
|
+
'Pass the id of a candidate you created or revised. A pass is required before ' +
|
|
203
|
+
'gene_publish. A conflict verdict tells you to merge or revise instead.',
|
|
204
|
+
parameters: {
|
|
205
|
+
type: 'object',
|
|
206
|
+
properties: { id: { type: 'string' }, version: { type: 'number' } },
|
|
207
|
+
required: ['id'],
|
|
208
|
+
},
|
|
209
|
+
run: (params) => validateCandidate(env, params),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function probeTool(env) {
|
|
213
|
+
return defineCuratorTool(env, {
|
|
214
|
+
name: 'gene_probe_tool',
|
|
215
|
+
label: 'Probe tool gene',
|
|
216
|
+
description: 'Run the examples of a READ-ONLY command tool gene in a sandbox directory.\n' +
|
|
217
|
+
'Anything else (scripts, composites, writes, high risk) is refused with ' +
|
|
218
|
+
'GENE_PROBE_NEEDS_APPROVAL and nothing runs; a person approves those in the manager.',
|
|
219
|
+
parameters: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: { id: { type: 'string' }, version: { type: 'number' } },
|
|
222
|
+
required: ['id'],
|
|
223
|
+
},
|
|
224
|
+
async run(params) {
|
|
225
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
226
|
+
const found = await candidateOf(env, id, typeof params.version === 'number' ? params.version : undefined);
|
|
227
|
+
if (typeof found === 'string')
|
|
228
|
+
return refuse('gene_probe_tool', found.split(' - ')[0], found.split(' - ')[1] ?? '');
|
|
229
|
+
const config = await env.deps.switches.effective();
|
|
230
|
+
const subject = { geneId: id, content: found.version.content };
|
|
231
|
+
const outcome = await autoProbe(subject, config, env.deps.probeDeps ?? {});
|
|
232
|
+
if (!outcome.ok) {
|
|
233
|
+
env.ctx.needsHuman = outcome.needsHuman;
|
|
234
|
+
return refuse('gene_probe_tool', outcome.code, `${outcome.message} Finish needs_human.`);
|
|
235
|
+
}
|
|
236
|
+
const failed = outcome.run.examples.filter((e) => !e.ok).length;
|
|
237
|
+
return receipt(`${id}: probe ${failed === 0 ? 'passed' : 'failed'} (${outcome.run.examples.length} example(s), ${failed} failed).`);
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
export function verifyTools(env) {
|
|
242
|
+
return [validateTool(env), probeTool(env)];
|
|
243
|
+
}
|