@aragon-agent/cli 0.6.54 → 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 -2838
- package/README.md +4226 -4042
- package/dist/agent/controller.d.ts +119 -0
- package/dist/agent/controller.js +365 -2
- package/dist/agent/governance-wiring.js +8 -1
- package/dist/agent/redteam-prompt.d.ts +47 -0
- package/dist/agent/redteam-prompt.js +161 -0
- package/dist/agent/redteam-wiring.d.ts +159 -0
- package/dist/agent/redteam-wiring.js +349 -0
- package/dist/agent/system-prompt.d.ts +39 -0
- package/dist/agent/system-prompt.js +18 -0
- package/dist/app/App.d.ts +10 -1
- package/dist/app/App.js +233 -24
- package/dist/app/use-redteam-mode.d.ts +56 -0
- package/dist/app/use-redteam-mode.js +121 -0
- package/dist/cli.js +82 -4
- package/dist/commands/builtins.js +43 -1
- package/dist/commands/catalog.js +5 -0
- package/dist/commands/index-build.js +2 -1
- package/dist/commands/redteam-command.d.ts +22 -0
- package/dist/commands/redteam-command.js +141 -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 +3 -1
- package/dist/config/env.js +23 -1
- package/dist/config/load.d.ts +22 -0
- package/dist/config/load.js +22 -2
- package/dist/config/redteam-launch.d.ts +77 -0
- package/dist/config/redteam-launch.js +58 -0
- package/dist/config/store.js +21 -1
- package/dist/config/ui-state.d.ts +44 -0
- package/dist/config/ui-state.js +38 -0
- 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/controller-factory.d.ts +8 -0
- package/dist/host/controller-factory.js +7 -0
- 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/session/checkpoint.d.ts +15 -0
- package/dist/session/checkpoint.js +18 -0
- package/dist/session/persist.d.ts +21 -0
- package/dist/session/persist.js +10 -0
- package/dist/session/startup-session.d.ts +11 -2
- package/dist/session/startup-session.js +12 -2
- package/dist/session/validate-session.js +31 -0
- package/dist/team/runtime.d.ts +16 -0
- package/dist/team/runtime.js +29 -0
- package/dist/team/subagent.d.ts +55 -0
- package/dist/team/subagent.js +46 -2
- package/dist/tools/index.d.ts +60 -2
- package/dist/tools/index.js +68 -10
- package/package.json +3 -3
- package/skills/project-indexer/SKILL.md +275 -147
- package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -0
- package/skills/project-indexer/templates/config-template.md +12 -0
- package/skills/project-indexer/templates/index-template.md +4 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { GENE_TYPES } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
import { contentHashOf } from '@aragon-agent/tui/model/gene/validate';
|
|
3
|
+
import { evaluatePublishGate } from './publish.js';
|
|
4
|
+
import { validationKey } from './task-context.js';
|
|
5
|
+
import { flagNeedsHuman, runCandidateValidation, summariseChecks } from './tools-verify.js';
|
|
6
|
+
import { CURATOR_ACTOR, TYPE_NAMES, applyFailureEffects, asObject, asString, asStringList, buildContent, defineCuratorTool, evidenceFor, failureResult, noteStale, reasonOf, receipt, refuse, switchGate, } from './tool-support.js';
|
|
7
|
+
const CONTENT_PARAM = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
description: 'name, purpose, trigger, body, tags, applicability, roles, payload. English prose.',
|
|
10
|
+
};
|
|
11
|
+
function candidateNote(outcome, warnings) {
|
|
12
|
+
const extra = warnings.length > 0 ? ` Warning: ${warnings.join('; ')}.` : '';
|
|
13
|
+
return `Candidate ${outcome.id} v${outcome.version ?? '?'} written.${extra}`
|
|
14
|
+
+ ' Next: load verify, gene_validate.';
|
|
15
|
+
}
|
|
16
|
+
function noteCandidate(env, ref, built) {
|
|
17
|
+
const { ctx } = env;
|
|
18
|
+
ctx.wrote = true;
|
|
19
|
+
ctx.evidenceAttached.add(ref.id);
|
|
20
|
+
ctx.candidates.set(ref.id, {
|
|
21
|
+
id: ref.id,
|
|
22
|
+
scope: ctx.scope,
|
|
23
|
+
type: ref.type,
|
|
24
|
+
version: ref.version,
|
|
25
|
+
...(built.requestedClass === undefined ? {} : { requestedClass: built.requestedClass }),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// create
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
async function createCandidate(env, params) {
|
|
32
|
+
const tool = 'gene_create_candidate';
|
|
33
|
+
const blocked = await switchGate(env, tool);
|
|
34
|
+
if (blocked !== null)
|
|
35
|
+
return blocked;
|
|
36
|
+
const type = asString(params.type);
|
|
37
|
+
const raw = asObject(params.content);
|
|
38
|
+
if (!GENE_TYPES.includes(type) || raw === undefined) {
|
|
39
|
+
return refuse(tool, 'GENE_ARGS_INVALID', 'type and content are required.');
|
|
40
|
+
}
|
|
41
|
+
const reason = reasonOf(env, tool, params.reason);
|
|
42
|
+
if (!reason.ok)
|
|
43
|
+
return reason.result;
|
|
44
|
+
const geneType = type;
|
|
45
|
+
const built = buildContent(env, geneType, raw);
|
|
46
|
+
const done = await env.deps.service.commit({
|
|
47
|
+
op: 'create',
|
|
48
|
+
type: geneType,
|
|
49
|
+
scope: env.ctx.scope,
|
|
50
|
+
content: built.content,
|
|
51
|
+
reason: reason.value,
|
|
52
|
+
class: 'standard',
|
|
53
|
+
proposalId: env.ctx.proposal.id,
|
|
54
|
+
evidence: evidenceFor(env.ctx, null),
|
|
55
|
+
}, CURATOR_ACTOR);
|
|
56
|
+
if (!done.ok) {
|
|
57
|
+
applyFailureEffects(env.ctx, done);
|
|
58
|
+
return failureResult(tool, done);
|
|
59
|
+
}
|
|
60
|
+
noteCandidate(env, { id: done.value.id, type: geneType, version: done.value.version ?? 1 }, built);
|
|
61
|
+
return receipt(candidateNote(done.value, built.warnings));
|
|
62
|
+
}
|
|
63
|
+
function createTool(env) {
|
|
64
|
+
return defineCuratorTool(env, {
|
|
65
|
+
name: 'gene_create_candidate',
|
|
66
|
+
label: 'Create candidate',
|
|
67
|
+
description: 'Write a NEW gene as a candidate. Nothing is published and agents cannot see it yet.\n' +
|
|
68
|
+
'type is knowledge, tool or skill; content carries the English draft; reason says why ' +
|
|
69
|
+
'it is worth keeping. It lands in the proposal scope.',
|
|
70
|
+
parameters: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
type: { type: 'string', enum: [...TYPE_NAMES] },
|
|
74
|
+
content: CONTENT_PARAM,
|
|
75
|
+
reason: { type: 'string' },
|
|
76
|
+
scope: { type: 'object', description: 'Ignored unless it equals the proposal scope.' },
|
|
77
|
+
},
|
|
78
|
+
required: ['type', 'content', 'reason'],
|
|
79
|
+
},
|
|
80
|
+
run: (params) => createCandidate(env, params),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// revise
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
async function servedContentOf(env, head) {
|
|
87
|
+
const n = head.currentVersion ?? head.candidateVersion;
|
|
88
|
+
return n === null ? null : env.deps.library.readVersion(head.scope, head.id, n);
|
|
89
|
+
}
|
|
90
|
+
async function reviseCandidate(env, params) {
|
|
91
|
+
const tool = 'gene_revise';
|
|
92
|
+
const blocked = await switchGate(env, tool);
|
|
93
|
+
if (blocked !== null)
|
|
94
|
+
return blocked;
|
|
95
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
96
|
+
const raw = asObject(params.content);
|
|
97
|
+
const read = await env.deps.library.readHead(env.ctx.scope, id);
|
|
98
|
+
if (read === null || raw === undefined) {
|
|
99
|
+
return refuse(tool, 'GENE_NOT_FOUND', 'No such gene in this scope, or content is missing.');
|
|
100
|
+
}
|
|
101
|
+
const { head } = read;
|
|
102
|
+
if (params.expectedVersion !== head.latestVersion) {
|
|
103
|
+
noteStale(env.ctx);
|
|
104
|
+
return refuse(tool, 'GENE_STALE_BASIS', `The gene is at v${head.latestVersion}; re-read it once.`);
|
|
105
|
+
}
|
|
106
|
+
const reason = reasonOf(env, tool, params.reason);
|
|
107
|
+
if (!reason.ok)
|
|
108
|
+
return reason.result;
|
|
109
|
+
const built = buildContent(env, head.type, raw, (await servedContentOf(env, head))?.content);
|
|
110
|
+
const done = await env.deps.service.commit({
|
|
111
|
+
op: 'revise',
|
|
112
|
+
scope: env.ctx.scope,
|
|
113
|
+
id,
|
|
114
|
+
content: built.content,
|
|
115
|
+
reason: reason.value,
|
|
116
|
+
proposalId: env.ctx.proposal.id,
|
|
117
|
+
evidence: evidenceFor(env.ctx, id),
|
|
118
|
+
}, CURATOR_ACTOR, { version: head.latestVersion });
|
|
119
|
+
if (!done.ok) {
|
|
120
|
+
applyFailureEffects(env.ctx, done);
|
|
121
|
+
return failureResult(tool, done);
|
|
122
|
+
}
|
|
123
|
+
const version = done.value.version ?? head.latestVersion + 1;
|
|
124
|
+
noteCandidate(env, { id, type: head.type, version }, built);
|
|
125
|
+
return receipt(candidateNote(done.value, built.warnings));
|
|
126
|
+
}
|
|
127
|
+
function reviseTool(env) {
|
|
128
|
+
return defineCuratorTool(env, {
|
|
129
|
+
name: 'gene_revise',
|
|
130
|
+
label: 'Revise gene',
|
|
131
|
+
description: 'Write a revision of a gene as a CANDIDATE version; the published one keeps serving.\n' +
|
|
132
|
+
'expectedVersion is the latest version you read. A moved version is refused: re-read ' +
|
|
133
|
+
'once. content may omit fields that stay the same.',
|
|
134
|
+
parameters: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: {
|
|
137
|
+
id: { type: 'string' },
|
|
138
|
+
expectedVersion: { type: 'number' },
|
|
139
|
+
content: CONTENT_PARAM,
|
|
140
|
+
reason: { type: 'string' },
|
|
141
|
+
},
|
|
142
|
+
required: ['id', 'expectedVersion', 'content', 'reason'],
|
|
143
|
+
},
|
|
144
|
+
run: (params) => reviseCandidate(env, params),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// ---------------------------------------------------------------------------
|
|
148
|
+
// merge
|
|
149
|
+
// ---------------------------------------------------------------------------
|
|
150
|
+
async function loadMembers(env, ids) {
|
|
151
|
+
const heads = new Map();
|
|
152
|
+
for (const id of ids) {
|
|
153
|
+
const read = await env.deps.library.readHead(env.ctx.scope, id);
|
|
154
|
+
if (read === null)
|
|
155
|
+
return id;
|
|
156
|
+
heads.set(id, read.head);
|
|
157
|
+
}
|
|
158
|
+
return heads;
|
|
159
|
+
}
|
|
160
|
+
function protectedMember(heads, from) {
|
|
161
|
+
return from.some((id) => heads.get(id)?.pinned === true || heads.get(id)?.class === 'oversight');
|
|
162
|
+
}
|
|
163
|
+
function mergeRefusal(env, gate) {
|
|
164
|
+
if (gate.abandon !== undefined)
|
|
165
|
+
env.ctx.abandoned = gate.abandon;
|
|
166
|
+
if (gate.stale === true)
|
|
167
|
+
noteStale(env.ctx);
|
|
168
|
+
if (gate.needsHuman !== undefined)
|
|
169
|
+
env.ctx.needsHuman = gate.needsHuman;
|
|
170
|
+
return refuse('gene_merge', gate.code, gate.message);
|
|
171
|
+
}
|
|
172
|
+
async function commitMerge(env, merge) {
|
|
173
|
+
const { ctx, deps } = env;
|
|
174
|
+
const basisOf = (id) => ctx.basis.get(id) ?? merge.members.get(id).latestVersion;
|
|
175
|
+
const fromBasis = {};
|
|
176
|
+
for (const id of merge.from)
|
|
177
|
+
fromBasis[id] = basisOf(id);
|
|
178
|
+
const done = await deps.service.commit({
|
|
179
|
+
op: 'merge',
|
|
180
|
+
scope: ctx.scope,
|
|
181
|
+
into: merge.into,
|
|
182
|
+
from: merge.from,
|
|
183
|
+
content: merge.content,
|
|
184
|
+
reason: merge.reason,
|
|
185
|
+
proposalId: ctx.proposal.id,
|
|
186
|
+
fromBasis,
|
|
187
|
+
evidence: evidenceFor(ctx, merge.into),
|
|
188
|
+
}, CURATOR_ACTOR, { version: basisOf(merge.into) });
|
|
189
|
+
if (!done.ok) {
|
|
190
|
+
applyFailureEffects(ctx, done);
|
|
191
|
+
return failureResult('gene_merge', done);
|
|
192
|
+
}
|
|
193
|
+
ctx.wrote = true;
|
|
194
|
+
ctx.evidenceAttached.add(merge.into);
|
|
195
|
+
if (done.value.needsHuman === true) {
|
|
196
|
+
ctx.needsHuman = 'conflict_with_human';
|
|
197
|
+
return refuse('gene_merge', 'GENE_CONFLICT_WITH_HUMAN', 'A person owns the target. Finish needs_human.');
|
|
198
|
+
}
|
|
199
|
+
ctx.merged.push(merge.into);
|
|
200
|
+
return receipt(`Merged ${merge.from.length} gene(s) into ${merge.into}. Next: gene_finish merged.`);
|
|
201
|
+
}
|
|
202
|
+
/** Validate the merged text inline; null when it passes, otherwise the refusal to return. */
|
|
203
|
+
async function validateMerge(env, plan, hash) {
|
|
204
|
+
const intoHead = plan.members.get(plan.into);
|
|
205
|
+
const previous = await servedContentOf(env, intoHead);
|
|
206
|
+
const stored = await runCandidateValidation(env, {
|
|
207
|
+
type: intoHead.type,
|
|
208
|
+
scope: env.ctx.scope,
|
|
209
|
+
geneId: plan.into,
|
|
210
|
+
version: intoHead.latestVersion,
|
|
211
|
+
contentHash: hash,
|
|
212
|
+
content: plan.content,
|
|
213
|
+
head: intoHead,
|
|
214
|
+
...(previous === null ? {} : { headContent: previous.content }),
|
|
215
|
+
excludeNeighbours: new Set(plan.from),
|
|
216
|
+
});
|
|
217
|
+
const { outcome } = stored;
|
|
218
|
+
if (outcome.verdict === 'pass')
|
|
219
|
+
return null;
|
|
220
|
+
if (outcome.verdict === 'needs_human' && outcome.needsHuman !== undefined) {
|
|
221
|
+
await flagNeedsHuman(env, intoHead, outcome.needsHuman);
|
|
222
|
+
}
|
|
223
|
+
return refuse('gene_merge', `GENE_VALIDATION_${outcome.verdict.toUpperCase()}`, summariseChecks(outcome));
|
|
224
|
+
}
|
|
225
|
+
async function mergeGenes(env, params) {
|
|
226
|
+
const { ctx, deps } = env;
|
|
227
|
+
const into = asString(params.into)?.trim() ?? '';
|
|
228
|
+
const from = asStringList(params.from).filter((id) => id !== into);
|
|
229
|
+
const raw = asObject(params.content);
|
|
230
|
+
if (into.length === 0 || from.length === 0 || raw === undefined) {
|
|
231
|
+
return refuse('gene_merge', 'GENE_ARGS_INVALID', 'into, from[] and content are required.');
|
|
232
|
+
}
|
|
233
|
+
const reason = reasonOf(env, 'gene_merge', params.reason);
|
|
234
|
+
if (!reason.ok)
|
|
235
|
+
return reason.result;
|
|
236
|
+
const members = await loadMembers(env, [into, ...from]);
|
|
237
|
+
if (typeof members === 'string') {
|
|
238
|
+
return refuse('gene_merge', 'GENE_NOT_FOUND', `${members} is not a live gene in this scope.`);
|
|
239
|
+
}
|
|
240
|
+
if (protectedMember(members, from)) {
|
|
241
|
+
ctx.needsHuman = 'conflict_with_human';
|
|
242
|
+
return refuse('gene_merge', 'GENE_PINNED', 'A pinned or oversight gene cannot be folded away. Finish needs_human.');
|
|
243
|
+
}
|
|
244
|
+
const intoHead = members.get(into);
|
|
245
|
+
const previous = await servedContentOf(env, intoHead);
|
|
246
|
+
const built = buildContent(env, intoHead.type, raw, previous?.content);
|
|
247
|
+
const plan = { into, from, members, content: built.content, reason: reason.value };
|
|
248
|
+
const hash = contentHashOf(built.content);
|
|
249
|
+
const invalid = await validateMerge(env, plan, hash);
|
|
250
|
+
if (invalid !== null)
|
|
251
|
+
return invalid;
|
|
252
|
+
const gate = await evaluatePublishGate({ switches: deps.switches, isForgotten: deps.isForgotten }, {
|
|
253
|
+
head: intoHead,
|
|
254
|
+
version: { n: intoHead.latestVersion, contentHash: hash, content: built.content },
|
|
255
|
+
stored: ctx.validations.get(validationKey(into, intoHead.latestVersion)),
|
|
256
|
+
expectedVersion: intoHead.latestVersion,
|
|
257
|
+
mode: 'direct',
|
|
258
|
+
proposalCreatedAt: ctx.proposal.createdAt,
|
|
259
|
+
originProjectKey: ctx.proposal.origin.projectKey ?? null,
|
|
260
|
+
originSource: ctx.proposal.origin.source,
|
|
261
|
+
});
|
|
262
|
+
return gate.ok ? commitMerge(env, plan) : mergeRefusal(env, gate);
|
|
263
|
+
}
|
|
264
|
+
function mergeTool(env) {
|
|
265
|
+
return defineCuratorTool(env, {
|
|
266
|
+
name: 'gene_merge',
|
|
267
|
+
label: 'Merge genes',
|
|
268
|
+
description: 'Fold duplicate genes into one survivor; the others are archived.\n' +
|
|
269
|
+
'The survivor keeps its id and gets the merged content. The content is validated and the ' +
|
|
270
|
+
'publish gate runs in this one call. Pinned genes cannot be folded away.',
|
|
271
|
+
parameters: {
|
|
272
|
+
type: 'object',
|
|
273
|
+
properties: {
|
|
274
|
+
into: { type: 'string' },
|
|
275
|
+
from: { type: 'array', items: { type: 'string' } },
|
|
276
|
+
content: CONTENT_PARAM,
|
|
277
|
+
reason: { type: 'string' },
|
|
278
|
+
},
|
|
279
|
+
required: ['into', 'from', 'content', 'reason'],
|
|
280
|
+
},
|
|
281
|
+
async run(params) {
|
|
282
|
+
const blocked = await switchGate(env, 'gene_merge');
|
|
283
|
+
return blocked ?? mergeGenes(env, params);
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
// ---------------------------------------------------------------------------
|
|
288
|
+
// archive / restore / health
|
|
289
|
+
// ---------------------------------------------------------------------------
|
|
290
|
+
function archiveTool(env) {
|
|
291
|
+
return defineCuratorTool(env, {
|
|
292
|
+
name: 'gene_archive',
|
|
293
|
+
label: 'Archive gene',
|
|
294
|
+
description: 'Move a gene out of use into the archive; it can be restored.\n' +
|
|
295
|
+
'A pinned gene is refused (GENE_PINNED). reason is required, at most 200 characters.',
|
|
296
|
+
parameters: {
|
|
297
|
+
type: 'object',
|
|
298
|
+
properties: { id: { type: 'string' }, reason: { type: 'string' } },
|
|
299
|
+
required: ['id', 'reason'],
|
|
300
|
+
},
|
|
301
|
+
async run(params) {
|
|
302
|
+
const blocked = await switchGate(env, 'gene_archive');
|
|
303
|
+
if (blocked !== null)
|
|
304
|
+
return blocked;
|
|
305
|
+
const reason = reasonOf(env, 'gene_archive', params.reason);
|
|
306
|
+
if (!reason.ok)
|
|
307
|
+
return reason.result;
|
|
308
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
309
|
+
const read = await env.deps.library.readHead(env.ctx.scope, id);
|
|
310
|
+
if (read === null)
|
|
311
|
+
return refuse('gene_archive', 'GENE_NOT_FOUND', 'No live gene with that id.');
|
|
312
|
+
const done = await env.deps.service.commit({ op: 'archive', scope: env.ctx.scope, id, reason: reason.value, proposalId: env.ctx.proposal.id }, CURATOR_ACTOR, { version: env.ctx.basis.get(id) ?? read.head.latestVersion });
|
|
313
|
+
if (!done.ok) {
|
|
314
|
+
applyFailureEffects(env.ctx, done);
|
|
315
|
+
return failureResult('gene_archive', done);
|
|
316
|
+
}
|
|
317
|
+
env.ctx.wrote = true;
|
|
318
|
+
return receipt(`Archived ${id}.`);
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
function restoreTool(env) {
|
|
323
|
+
return defineCuratorTool(env, {
|
|
324
|
+
name: 'gene_restore',
|
|
325
|
+
label: 'Restore gene',
|
|
326
|
+
description: 'Bring an archived gene back into use.\nIt re-enters the library under the normal size limit.',
|
|
327
|
+
parameters: {
|
|
328
|
+
type: 'object',
|
|
329
|
+
properties: { id: { type: 'string' }, reason: { type: 'string' } },
|
|
330
|
+
required: ['id', 'reason'],
|
|
331
|
+
},
|
|
332
|
+
async run(params) {
|
|
333
|
+
const blocked = await switchGate(env, 'gene_restore');
|
|
334
|
+
if (blocked !== null)
|
|
335
|
+
return blocked;
|
|
336
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
337
|
+
const archived = await env.deps.library.readArchivedHead(env.ctx.scope, id);
|
|
338
|
+
if (archived === null)
|
|
339
|
+
return refuse('gene_restore', 'GENE_NOT_FOUND', 'No archived gene with that id.');
|
|
340
|
+
const done = await env.deps.service.commit({ op: 'restore', scope: env.ctx.scope, id }, CURATOR_ACTOR, { version: archived.head.latestVersion });
|
|
341
|
+
if (!done.ok) {
|
|
342
|
+
applyFailureEffects(env.ctx, done);
|
|
343
|
+
return failureResult('gene_restore', done);
|
|
344
|
+
}
|
|
345
|
+
env.ctx.wrote = true;
|
|
346
|
+
return receipt(`Restored ${id}.`);
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
const HEALTH_VALUES = ['ok', 'recheck', 'broken'];
|
|
351
|
+
function healthTool(env) {
|
|
352
|
+
return defineCuratorTool(env, {
|
|
353
|
+
name: 'gene_set_health',
|
|
354
|
+
label: 'Set gene health',
|
|
355
|
+
description: 'Mark a gene ok, recheck or broken. Only the mark changes; no content is touched.\n' +
|
|
356
|
+
'A broken tool gene is refused by gene_run; other genes still show with a warning.',
|
|
357
|
+
parameters: {
|
|
358
|
+
type: 'object',
|
|
359
|
+
properties: {
|
|
360
|
+
id: { type: 'string' },
|
|
361
|
+
health: { type: 'string', enum: [...HEALTH_VALUES] },
|
|
362
|
+
reason: { type: 'string' },
|
|
363
|
+
},
|
|
364
|
+
required: ['id', 'health', 'reason'],
|
|
365
|
+
},
|
|
366
|
+
async run(params) {
|
|
367
|
+
const health = asString(params.health);
|
|
368
|
+
if (!HEALTH_VALUES.includes(health ?? '')) {
|
|
369
|
+
return refuse('gene_set_health', 'GENE_ARGS_INVALID', 'health must be ok, recheck or broken.');
|
|
370
|
+
}
|
|
371
|
+
const reason = reasonOf(env, 'gene_set_health', params.reason);
|
|
372
|
+
if (!reason.ok)
|
|
373
|
+
return reason.result;
|
|
374
|
+
const id = asString(params.id)?.trim() ?? '';
|
|
375
|
+
const done = await env.deps.service.commit({
|
|
376
|
+
op: 'setHealth',
|
|
377
|
+
scope: env.ctx.scope,
|
|
378
|
+
id,
|
|
379
|
+
health: health,
|
|
380
|
+
healthReason: reason.value.slice(0, 100),
|
|
381
|
+
}, CURATOR_ACTOR);
|
|
382
|
+
if (!done.ok)
|
|
383
|
+
return failureResult('gene_set_health', done);
|
|
384
|
+
env.ctx.wrote = true;
|
|
385
|
+
return receipt(`Marked ${id} ${health}.`);
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
export function authorTools(env) {
|
|
390
|
+
return [createTool(env), reviseTool(env)];
|
|
391
|
+
}
|
|
392
|
+
export function maintainTools(env) {
|
|
393
|
+
return [mergeTool(env), archiveTool(env), restoreTool(env), healthTool(env)];
|
|
394
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The curator's tool box (gene-bank spec 9.5, 16.2).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* `createCuratorToolkit` builds every curator tool around ONE task context and hands them to a
|
|
7
|
+
* `CuratorToolkit`, which decides which of them the model can see. The tools live in four files by
|
|
8
|
+
* what they do (`tools-read`, `tools-write`, `tools-verify`, `tools-release`); this file is only
|
|
9
|
+
* the assembly, so there is a single answer to "which tools exist" - the registry below - and the
|
|
10
|
+
* toolkit's group table is checked against it.
|
|
11
|
+
*
|
|
12
|
+
* ALL OF THEM CALL `assertCuratorContext` FIRST (via `defineCuratorTool`), and none of them holds
|
|
13
|
+
* any write code: the only writer is `GeneVersionService`. The foreground never receives this
|
|
14
|
+
* array; the tools exist only inside a curator agent's tool list.
|
|
15
|
+
*/
|
|
16
|
+
import type { AgentTool } from '@aragon-agent/core';
|
|
17
|
+
import { CuratorToolkit } from './toolkit.js';
|
|
18
|
+
import type { ToolEnv } from './tool-support.js';
|
|
19
|
+
export { CURATOR_ACTOR } from './tool-support.js';
|
|
20
|
+
export type { CuratorToolDeps, ToolEnv } from './tool-support.js';
|
|
21
|
+
/** Every curator tool by name. */
|
|
22
|
+
export declare function createCuratorRegistry(env: ToolEnv): Map<string, AgentTool>;
|
|
23
|
+
export declare function createCuratorToolkit(env: ToolEnv): CuratorToolkit;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CuratorToolkit } from './toolkit.js';
|
|
2
|
+
import { readTool, searchTool } from './tools-read.js';
|
|
3
|
+
import { releaseTools } from './tools-release.js';
|
|
4
|
+
import { verifyTools } from './tools-verify.js';
|
|
5
|
+
import { authorTools, maintainTools } from './tools-write.js';
|
|
6
|
+
export { CURATOR_ACTOR } from './tool-support.js';
|
|
7
|
+
/** Every curator tool by name. */
|
|
8
|
+
export function createCuratorRegistry(env) {
|
|
9
|
+
const all = [
|
|
10
|
+
searchTool(env),
|
|
11
|
+
readTool(env),
|
|
12
|
+
...authorTools(env),
|
|
13
|
+
...maintainTools(env),
|
|
14
|
+
...verifyTools(env),
|
|
15
|
+
...releaseTools(env),
|
|
16
|
+
];
|
|
17
|
+
return new Map(all.map((tool) => [tool.name, tool]));
|
|
18
|
+
}
|
|
19
|
+
export function createCuratorToolkit(env) {
|
|
20
|
+
return new CuratorToolkit(env, createCuratorRegistry(env));
|
|
21
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks shared by every gene type (gene-bank spec 10.7, 11.3, 11.5; I-12, I-16, TH-1, TH-5).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHAT LIVES HERE: the check builders (one vocabulary for pass / fail / skipped), the static
|
|
7
|
+
* content check (`validateGeneContent` with the secret screen wired in), the oversight demotion,
|
|
8
|
+
* the source-trust gate and the verdict fold. Per-type rules live in `knowledge.ts`, `tool.ts`
|
|
9
|
+
* and `skill.ts`.
|
|
10
|
+
*
|
|
11
|
+
* CHECK CODES. A FAILING check carries the stable code the UI localises (`KNOWLEDGE_*`,
|
|
12
|
+
* `TOOL_*`, `SKILL_*`, or a `GENE_*` error code for static failures). A PASSING check carries its
|
|
13
|
+
* short id (`K1`, `T4`, ...). A check that was NOT RUN carries `SKIPPED_<id>` with `ok: true` and
|
|
14
|
+
* the reason in `detail` - it is recorded, it is not a pass, and `isSkippedCheck` tells them apart.
|
|
15
|
+
*
|
|
16
|
+
* NO DETAIL TEXT MAY CARRY GENE BODY TEXT OR A SECRET (I-19): details name paths of FIELDS, ids of
|
|
17
|
+
* checks and counts, never what the field said.
|
|
18
|
+
*/
|
|
19
|
+
import type { GeneClass, GeneContent, GeneEvidence, GeneNeedsHuman, GeneScope, GeneType, GeneValidation, GeneValidationCheck } from '@aragon-agent/tui/model/gene/types';
|
|
20
|
+
import type { GeneIssue } from '@aragon-agent/tui/model/gene/validate';
|
|
21
|
+
import type { CandidateVerdict } from './types.js';
|
|
22
|
+
export declare const SKIPPED_PREFIX = "SKIPPED_";
|
|
23
|
+
/** Failing codes that mean "a person must decide", not "this candidate is wrong". */
|
|
24
|
+
export declare const NEEDS_HUMAN_CODES: ReadonlySet<string>;
|
|
25
|
+
/** Failing codes that mean "do not create this; route it as a merge or a revise". */
|
|
26
|
+
export declare const CONVERT_CODES: ReadonlySet<string>;
|
|
27
|
+
export interface CheckExtras {
|
|
28
|
+
by?: GeneValidationCheck['by'];
|
|
29
|
+
model?: string;
|
|
30
|
+
durationMs?: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function okCheck(id: string, at: number, detail?: string, extras?: CheckExtras): GeneValidationCheck;
|
|
33
|
+
export declare function failCheck(code: string, at: number, detail: string, extras?: CheckExtras): GeneValidationCheck;
|
|
34
|
+
/** A check that was not run. `ok: true` so it blocks nothing, but never mistaken for a pass. */
|
|
35
|
+
export declare function skippedCheck(id: string, at: number, reason: string): GeneValidationCheck;
|
|
36
|
+
export declare function isSkippedCheck(check: GeneValidationCheck): boolean;
|
|
37
|
+
/** Dotted field paths only - never the offending text (I-19). */
|
|
38
|
+
export declare function describeIssues(issues: readonly GeneIssue[]): string;
|
|
39
|
+
export interface StaticInput {
|
|
40
|
+
type: GeneType;
|
|
41
|
+
content: GeneContent;
|
|
42
|
+
scope: GeneScope;
|
|
43
|
+
/** The class the head has today; `oversight` here means an agent is editing a human-only gene. */
|
|
44
|
+
targetClass?: GeneClass;
|
|
45
|
+
requestedClass?: GeneClass;
|
|
46
|
+
knownSecrets?: readonly string[];
|
|
47
|
+
}
|
|
48
|
+
export interface StaticReport {
|
|
49
|
+
issues: GeneIssue[];
|
|
50
|
+
/** The class the gene will be stored with. */
|
|
51
|
+
storedClass: GeneClass;
|
|
52
|
+
/** The draft asked for `oversight`; it was demoted to `standard` (11.3, a warning not silence). */
|
|
53
|
+
demoted: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Run `validateGeneContent` as the AGENT actor. The one place that decides what an agent may do
|
|
57
|
+
* with `class: 'oversight'`: editing an existing oversight gene is refused (I-12), asking for a
|
|
58
|
+
* NEW one is demoted to `standard` with a warning.
|
|
59
|
+
*/
|
|
60
|
+
export declare function runStaticChecks(input: StaticInput): StaticReport;
|
|
61
|
+
export declare function splitIssues(issues: readonly GeneIssue[], pick: (issue: GeneIssue) => boolean): {
|
|
62
|
+
picked: GeneIssue[];
|
|
63
|
+
rest: GeneIssue[];
|
|
64
|
+
};
|
|
65
|
+
/** The K1 check: every static issue not owned by a type-specific check. */
|
|
66
|
+
export declare function staticCheck(rest: readonly GeneIssue[], at: number): GeneValidationCheck;
|
|
67
|
+
/** Warning check recorded when an agent draft asked for the human-only `oversight` class. */
|
|
68
|
+
export declare function oversightChecks(report: StaticReport, targetClass: GeneClass | undefined, at: number): GeneValidationCheck[];
|
|
69
|
+
/**
|
|
70
|
+
* All evidence `untrusted` and nothing from the user or from a local measurement: the library
|
|
71
|
+
* is not allowed to learn from a web page alone (TH-1). No evidence at all is K2's problem.
|
|
72
|
+
*/
|
|
73
|
+
export declare function untrustedOnly(evidence: readonly GeneEvidence[]): boolean;
|
|
74
|
+
export declare function trustCheck(evidence: readonly GeneEvidence[], at: number): {
|
|
75
|
+
check: GeneValidationCheck;
|
|
76
|
+
needsHuman?: GeneNeedsHuman['reason'];
|
|
77
|
+
};
|
|
78
|
+
export declare function validationOf(checks: readonly GeneValidationCheck[], at: number): GeneValidation;
|
|
79
|
+
/** fail > needs_human > convert > pass. */
|
|
80
|
+
export declare function verdictOf(checks: readonly GeneValidationCheck[]): CandidateVerdict;
|
|
81
|
+
export declare function addUsage(into: {
|
|
82
|
+
in: number;
|
|
83
|
+
out: number;
|
|
84
|
+
}, usage: {
|
|
85
|
+
in: number;
|
|
86
|
+
out: number;
|
|
87
|
+
} | undefined): void;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { validateGeneContent } from '@aragon-agent/tui/model/gene/validate';
|
|
2
|
+
import { geneLooksLikeSecret } from '../../secrets.js';
|
|
3
|
+
export const SKIPPED_PREFIX = 'SKIPPED_';
|
|
4
|
+
/** Failing codes that mean "a person must decide", not "this candidate is wrong". */
|
|
5
|
+
export const NEEDS_HUMAN_CODES = new Set([
|
|
6
|
+
'GENE_PROBE_NEEDS_APPROVAL',
|
|
7
|
+
'GENE_TOOL_HIGH_RISK',
|
|
8
|
+
'KNOWLEDGE_UNTRUSTED_ONLY',
|
|
9
|
+
'CONFLICT_WITH_HUMAN',
|
|
10
|
+
]);
|
|
11
|
+
/** Failing codes that mean "do not create this; route it as a merge or a revise". */
|
|
12
|
+
export const CONVERT_CODES = new Set(['CONFLICT_CONVERT']);
|
|
13
|
+
function build(code, ok, at, detail, extras) {
|
|
14
|
+
const check = { code, ok, by: extras.by ?? 'code', at };
|
|
15
|
+
if (detail !== undefined && detail.length > 0)
|
|
16
|
+
check.detail = detail.slice(0, 240);
|
|
17
|
+
if (extras.model !== undefined)
|
|
18
|
+
check.model = extras.model;
|
|
19
|
+
if (extras.durationMs !== undefined)
|
|
20
|
+
check.durationMs = extras.durationMs;
|
|
21
|
+
return check;
|
|
22
|
+
}
|
|
23
|
+
export function okCheck(id, at, detail, extras = {}) {
|
|
24
|
+
return build(id, true, at, detail, extras);
|
|
25
|
+
}
|
|
26
|
+
export function failCheck(code, at, detail, extras = {}) {
|
|
27
|
+
return build(code, false, at, detail, extras);
|
|
28
|
+
}
|
|
29
|
+
/** A check that was not run. `ok: true` so it blocks nothing, but never mistaken for a pass. */
|
|
30
|
+
export function skippedCheck(id, at, reason) {
|
|
31
|
+
return build(`${SKIPPED_PREFIX}${id}`, true, at, `skipped: ${reason}`, {});
|
|
32
|
+
}
|
|
33
|
+
export function isSkippedCheck(check) {
|
|
34
|
+
return check.code.startsWith(SKIPPED_PREFIX);
|
|
35
|
+
}
|
|
36
|
+
/** Dotted field paths only - never the offending text (I-19). */
|
|
37
|
+
export function describeIssues(issues) {
|
|
38
|
+
const parts = issues.slice(0, 6).map((i) => (i.detail ? `${i.path}:${i.detail}` : i.path));
|
|
39
|
+
const more = issues.length > 6 ? ` (+${issues.length - 6} more)` : '';
|
|
40
|
+
return parts.join(', ') + more;
|
|
41
|
+
}
|
|
42
|
+
/** `class` can also arrive as a stray property of the model's JSON; treat it as a request. */
|
|
43
|
+
function strayClass(content) {
|
|
44
|
+
const raw = content.class;
|
|
45
|
+
return raw === 'oversight' ? 'oversight' : undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Run `validateGeneContent` as the AGENT actor. The one place that decides what an agent may do
|
|
49
|
+
* with `class: 'oversight'`: editing an existing oversight gene is refused (I-12), asking for a
|
|
50
|
+
* NEW one is demoted to `standard` with a warning.
|
|
51
|
+
*/
|
|
52
|
+
export function runStaticChecks(input) {
|
|
53
|
+
const editsOversight = input.targetClass === 'oversight';
|
|
54
|
+
const asked = input.requestedClass === 'oversight' || strayClass(input.content) === 'oversight';
|
|
55
|
+
const demoted = asked && !editsOversight;
|
|
56
|
+
const knownSecrets = input.knownSecrets ?? [];
|
|
57
|
+
const result = validateGeneContent(input.type, input.content, {
|
|
58
|
+
scope: input.scope,
|
|
59
|
+
actor: 'agent',
|
|
60
|
+
class: editsOversight ? 'oversight' : 'standard',
|
|
61
|
+
secretCheck: (text) => geneLooksLikeSecret(text, knownSecrets),
|
|
62
|
+
});
|
|
63
|
+
return { issues: result.issues, storedClass: editsOversight ? 'oversight' : 'standard', demoted };
|
|
64
|
+
}
|
|
65
|
+
export function splitIssues(issues, pick) {
|
|
66
|
+
const picked = [];
|
|
67
|
+
const rest = [];
|
|
68
|
+
for (const issue of issues)
|
|
69
|
+
(pick(issue) ? picked : rest).push(issue);
|
|
70
|
+
return { picked, rest };
|
|
71
|
+
}
|
|
72
|
+
/** The K1 check: every static issue not owned by a type-specific check. */
|
|
73
|
+
export function staticCheck(rest, at) {
|
|
74
|
+
if (rest.length === 0)
|
|
75
|
+
return okCheck('K1', at);
|
|
76
|
+
return failCheck(rest[0].code, at, `K1 ${describeIssues(rest)}`);
|
|
77
|
+
}
|
|
78
|
+
/** Warning check recorded when an agent draft asked for the human-only `oversight` class. */
|
|
79
|
+
export function oversightChecks(report, targetClass, at) {
|
|
80
|
+
const out = [];
|
|
81
|
+
if (report.demoted)
|
|
82
|
+
out.push(okCheck('OVERSIGHT_DEMOTED', at, 'draft asked for class oversight; stored as standard'));
|
|
83
|
+
if (targetClass === 'oversight') {
|
|
84
|
+
out.push(failCheck('GENE_OVERSIGHT_HUMAN_ONLY', at, 'only a person may change an oversight gene'));
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Source trust (K6, TH-1)
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
/**
|
|
92
|
+
* All evidence `untrusted` and nothing from the user or from a local measurement: the library
|
|
93
|
+
* is not allowed to learn from a web page alone (TH-1). No evidence at all is K2's problem.
|
|
94
|
+
*/
|
|
95
|
+
export function untrustedOnly(evidence) {
|
|
96
|
+
if (evidence.length === 0)
|
|
97
|
+
return false;
|
|
98
|
+
return evidence.every((e) => e.trust === 'untrusted');
|
|
99
|
+
}
|
|
100
|
+
export function trustCheck(evidence, at) {
|
|
101
|
+
if (untrustedOnly(evidence)) {
|
|
102
|
+
return {
|
|
103
|
+
check: failCheck('KNOWLEDGE_UNTRUSTED_ONLY', at, `K6 all ${evidence.length} evidence items are untrusted`),
|
|
104
|
+
needsHuman: 'untrusted_origin',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return { check: okCheck('K6', at) };
|
|
108
|
+
}
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// Folding checks into a validation and a verdict
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
export function validationOf(checks, at) {
|
|
113
|
+
return { at, ok: checks.every((c) => c.ok), checks: [...checks] };
|
|
114
|
+
}
|
|
115
|
+
/** fail > needs_human > convert > pass. */
|
|
116
|
+
export function verdictOf(checks) {
|
|
117
|
+
const failing = checks.filter((c) => !c.ok);
|
|
118
|
+
if (failing.length === 0)
|
|
119
|
+
return 'pass';
|
|
120
|
+
const hard = failing.some((c) => !NEEDS_HUMAN_CODES.has(c.code) && !CONVERT_CODES.has(c.code));
|
|
121
|
+
if (hard)
|
|
122
|
+
return 'fail';
|
|
123
|
+
if (failing.some((c) => NEEDS_HUMAN_CODES.has(c.code)))
|
|
124
|
+
return 'needs_human';
|
|
125
|
+
return 'convert';
|
|
126
|
+
}
|
|
127
|
+
export function addUsage(into, usage) {
|
|
128
|
+
if (usage === undefined)
|
|
129
|
+
return;
|
|
130
|
+
into.in += Math.max(0, usage.in);
|
|
131
|
+
into.out += Math.max(0, usage.out);
|
|
132
|
+
}
|