@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,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge-gene validation K1-K6 (gene-bank spec 10.7.1, 10.8; RV-10; TH-1).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* K1 static the shared content check, minus the preference-horizon rule K3 owns
|
|
7
|
+
* K2 source >= 1 evidence; every cited ref resolves; every path / symbol / error code /
|
|
8
|
+
* number of the draft appears VERBATIM in the evidence texts that were
|
|
9
|
+
* snapshotted at enqueue. The live re-check against the project tree is optional
|
|
10
|
+
* and its absence is recorded, never a failure. A miss that OUR OWN clipping
|
|
11
|
+
* explains does not fail the candidate: it puts it on probation (RV-13), and the
|
|
12
|
+
* missing tokens are handed to the curator as repair instructions (RV-17).
|
|
13
|
+
* K3 scope a temporary preference only in the task scope; a specific path or a project
|
|
14
|
+
* name cannot live in the user scope; environment-bound claims carry applicability
|
|
15
|
+
* K4 supported model: do the evidence texts support the draft? (skipped when a user said it)
|
|
16
|
+
* K5 conflict neighbour relations (see `conflicts.ts`)
|
|
17
|
+
* K6 trust all-untrusted evidence waits for a person (TH-1)
|
|
18
|
+
*
|
|
19
|
+
* Every function returns plain data. A failing detail names fields and counts, never text.
|
|
20
|
+
*/
|
|
21
|
+
import { promises as nodeFs } from 'node:fs';
|
|
22
|
+
import { preferenceHorizonFitsScope, normalizedApplicabilityOf } from '@aragon-agent/tui/model/gene/validate';
|
|
23
|
+
import { runConflictCheck } from '../conflicts.js';
|
|
24
|
+
import { addUsage, failCheck, okCheck, skippedCheck, splitIssues, staticCheck, trustCheck, } from './common.js';
|
|
25
|
+
import { extractVerbatimTokens, findUnsupportedTokens, summarizeMissing, } from './evidence-tokens.js';
|
|
26
|
+
import { liveCheckEvidence } from './live-check.js';
|
|
27
|
+
import { askModel, buildSupportPrompt, parseSupportAnswer } from './prompts.js';
|
|
28
|
+
function payloadOf(content) {
|
|
29
|
+
const raw = content.payload;
|
|
30
|
+
return typeof raw === 'object' && raw !== null ? raw : {};
|
|
31
|
+
}
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// K2 - source
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/** The refs a draft cites: its `evidence` list and each claim's `evidence`. */
|
|
36
|
+
export function citedRefs(content) {
|
|
37
|
+
const refs = new Set(Array.isArray(content.evidence) ? content.evidence : []);
|
|
38
|
+
for (const claim of payloadOf(content).claims ?? []) {
|
|
39
|
+
if (typeof claim?.evidence === 'string' && claim.evidence.length > 0)
|
|
40
|
+
refs.add(claim.evidence);
|
|
41
|
+
}
|
|
42
|
+
return [...refs];
|
|
43
|
+
}
|
|
44
|
+
/** Resolve cited refs from the snapshot first, then through `readEvidence` (a revise cites old ones). */
|
|
45
|
+
export async function resolveEvidence(ports, scope, geneId, content, snapshot) {
|
|
46
|
+
const byRef = new Map(snapshot.map((e) => [e.ref, e]));
|
|
47
|
+
let unresolved = 0;
|
|
48
|
+
for (const ref of citedRefs(content)) {
|
|
49
|
+
if (byRef.has(ref))
|
|
50
|
+
continue;
|
|
51
|
+
const found = geneId === undefined ? null : await ports.readEvidence(scope, geneId, ref).catch(() => null);
|
|
52
|
+
if (found === null)
|
|
53
|
+
unresolved += 1;
|
|
54
|
+
else
|
|
55
|
+
byRef.set(ref, found);
|
|
56
|
+
}
|
|
57
|
+
return { corpus: [...byRef.values()], unresolved };
|
|
58
|
+
}
|
|
59
|
+
function draftedTexts(content) {
|
|
60
|
+
const claims = (payloadOf(content).claims ?? []).map((c) => String(c?.text ?? ''));
|
|
61
|
+
return [String(content.body ?? ''), ...claims];
|
|
62
|
+
}
|
|
63
|
+
async function rootIsDirectory(root) {
|
|
64
|
+
const stat = await nodeFs.stat(root).catch(() => null);
|
|
65
|
+
return stat !== null && stat.isDirectory();
|
|
66
|
+
}
|
|
67
|
+
/** The optional live check. Returns the info check to record and whether it failed. */
|
|
68
|
+
async function liveCheck(ports, scope, corpus, at) {
|
|
69
|
+
const checkable = corpus.filter((e) => e.kind !== 'user_statement');
|
|
70
|
+
if (checkable.length === 0)
|
|
71
|
+
return { failed: 0 };
|
|
72
|
+
const root = ports.projectRoot?.(scope);
|
|
73
|
+
if (root === undefined || !(await rootIsDirectory(root))) {
|
|
74
|
+
return { check: okCheck('live_check', at, 'skipped_root_unavailable'), failed: 0 };
|
|
75
|
+
}
|
|
76
|
+
const result = await liveCheckEvidence(root, checkable);
|
|
77
|
+
if (result.status === 'nothing_to_check')
|
|
78
|
+
return { failed: 0 };
|
|
79
|
+
if (result.status === 'skipped_budget')
|
|
80
|
+
return { check: okCheck('live_check', at, 'skipped_budget'), failed: 0 };
|
|
81
|
+
const detail = result.status === 'passed' ? 'passed' : `failed: ${result.failed} of ${result.checked}`;
|
|
82
|
+
return { check: okCheck('live_check', at, detail), failed: result.failed };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The CURATOR-ONLY repair line for a failing K2 (RV-17, B3): the missing tokens, verbatim, so the
|
|
86
|
+
* model can cite them or take them out of its draft in the same task.
|
|
87
|
+
*
|
|
88
|
+
* WHY IT IS NOT ON THE OUTCOME. `CandidateOutcome` is logged and stored, and a stored detail may
|
|
89
|
+
* never echo gene or evidence text (I-19) - the `poison-untrusted` case fails the moment a token
|
|
90
|
+
* leaves through it. This string is built at the tool boundary instead, from the model's own draft
|
|
91
|
+
* and its own evidence, and exists only in that one tool answer.
|
|
92
|
+
*/
|
|
93
|
+
export function repairLines(content, corpus) {
|
|
94
|
+
const report = findUnsupportedTokens(draftedTexts(content), corpus);
|
|
95
|
+
if (report.missing.length === 0)
|
|
96
|
+
return [];
|
|
97
|
+
const tokens = report.missing.map((t) => `${t.kind} ${t.text}`).join(', ');
|
|
98
|
+
return [`these tokens are not in the evidence: ${tokens} - quote them verbatim or remove them`];
|
|
99
|
+
}
|
|
100
|
+
function evidenceProblems(unresolved, report) {
|
|
101
|
+
const problems = [];
|
|
102
|
+
if (unresolved > 0)
|
|
103
|
+
problems.push(`${unresolved} cited ref(s) unresolved`);
|
|
104
|
+
if (report.missing.length > 0)
|
|
105
|
+
problems.push(`not in evidence: ${summarizeMissing(report.missing)}`);
|
|
106
|
+
return problems;
|
|
107
|
+
}
|
|
108
|
+
/** K2, reusable by `recheck` (10.9). Returns the K2 check and, when run, the live_check record. */
|
|
109
|
+
export async function checkSource(input) {
|
|
110
|
+
const at = input.ports.now();
|
|
111
|
+
const { corpus, unresolved } = input.resolved ??
|
|
112
|
+
(await resolveEvidence(input.ports, input.scope, input.geneId, input.content, input.evidence));
|
|
113
|
+
if (corpus.length === 0) {
|
|
114
|
+
return {
|
|
115
|
+
checks: [failCheck('KNOWLEDGE_EVIDENCE_UNRESOLVED', at, 'K2 the proposal carries no evidence')],
|
|
116
|
+
clipped: [],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const report = findUnsupportedTokens(draftedTexts(input.content), corpus.map((e) => e.text).join('\n'));
|
|
120
|
+
const problems = evidenceProblems(unresolved, report);
|
|
121
|
+
const live = await liveCheck(input.ports, input.scope, corpus, at);
|
|
122
|
+
if (live.failed > 0)
|
|
123
|
+
problems.push(`${live.failed} evidence item(s) no longer match the project`);
|
|
124
|
+
const main = problems.length > 0
|
|
125
|
+
? failCheck('KNOWLEDGE_EVIDENCE_UNRESOLVED', at, `K2 ${problems.join('; ')}`)
|
|
126
|
+
: okCheck('K2', at, `${report.checked} specific(s) found in evidence`);
|
|
127
|
+
return {
|
|
128
|
+
checks: live.check === undefined ? [main] : [main, live.check],
|
|
129
|
+
clipped: report.clipped,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
// K3 - scope fit
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
const OS_WORDS = /\b(?:windows|win32|macos|darwin|linux|powershell)\b/i;
|
|
136
|
+
function hasSpecificPath(texts) {
|
|
137
|
+
return texts.some((text) => extractVerbatimTokens(text).some((t) => {
|
|
138
|
+
if (t.kind !== 'path' || /^https?:/i.test(t.text))
|
|
139
|
+
return false;
|
|
140
|
+
const segments = t.text.split(/[\\/]/).filter((s) => s.length > 0);
|
|
141
|
+
return segments.length >= 2 || /^(?:[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(t.text);
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
function mentionsProject(texts, labels) {
|
|
145
|
+
const haystack = texts.join('\n').toLowerCase();
|
|
146
|
+
return labels.some((label) => {
|
|
147
|
+
const needle = label.trim().toLowerCase();
|
|
148
|
+
if (needle.length < 3)
|
|
149
|
+
return false;
|
|
150
|
+
const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
151
|
+
return new RegExp(`(?<![a-z0-9])${escaped}(?![a-z0-9])`).test(haystack);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function applicabilityEmpty(content) {
|
|
155
|
+
// The SAME normalisation the write path applied (RC-2, RV-16): a legacy or imported block that
|
|
156
|
+
// spells `platform` is an environment filter, not an absent one.
|
|
157
|
+
const a = normalizedApplicabilityOf(content);
|
|
158
|
+
return !a.os?.length && !a.envStamp && !a.projectKinds?.length && !a.fileGlobs?.length && !a.requiresTools?.length;
|
|
159
|
+
}
|
|
160
|
+
function scopeProblems(ctx) {
|
|
161
|
+
const c = ctx.content;
|
|
162
|
+
const texts = [c.name, c.purpose, c.trigger, c.body].map((t) => String(t ?? ''));
|
|
163
|
+
const problems = [];
|
|
164
|
+
if (ctx.scope.kind === 'user' && hasSpecificPath(texts))
|
|
165
|
+
problems.push('a specific path in the user scope');
|
|
166
|
+
if (ctx.scope.kind === 'user' && mentionsProject(texts, ctx.ports.projectLabels ?? [])) {
|
|
167
|
+
problems.push('a project name in the user scope');
|
|
168
|
+
}
|
|
169
|
+
const isPreference = payloadOf(c).kind === 'preference';
|
|
170
|
+
if (!isPreference && OS_WORDS.test(texts.join('\n')) && applicabilityEmpty(c)) {
|
|
171
|
+
problems.push('an environment-bound statement without applicability');
|
|
172
|
+
}
|
|
173
|
+
return problems;
|
|
174
|
+
}
|
|
175
|
+
function checkScope(ctx, at) {
|
|
176
|
+
const out = [];
|
|
177
|
+
const horizon = payloadOf(ctx.content).preference?.horizon;
|
|
178
|
+
if (horizon !== undefined && !preferenceHorizonFitsScope(horizon, ctx.scope.kind)) {
|
|
179
|
+
out.push(failCheck('PREF_HORIZON_SCOPE', at, `K3 a ${horizon} preference cannot live in the ${ctx.scope.kind} scope`));
|
|
180
|
+
}
|
|
181
|
+
const problems = scopeProblems(ctx);
|
|
182
|
+
if (problems.length > 0)
|
|
183
|
+
out.push(failCheck('KNOWLEDGE_SCOPE_MISFIT', at, `K3 ${problems.join('; ')}`));
|
|
184
|
+
return out.length > 0 ? out : [okCheck('K3', at)];
|
|
185
|
+
}
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
// K4 - supported by the evidence
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
async function checkSupported(ctx, corpus, usage) {
|
|
190
|
+
const at = ctx.ports.now();
|
|
191
|
+
if (corpus.some((e) => e.kind === 'user_statement' && e.trust !== 'untrusted')) {
|
|
192
|
+
return okCheck('K4', at, 'a user statement is sufficient');
|
|
193
|
+
}
|
|
194
|
+
const prompt = buildSupportPrompt(draftedTexts(ctx.content).join('\n'), corpus.map((e) => e.text));
|
|
195
|
+
const answer = await askModel(ctx.ports, prompt.system, prompt.user);
|
|
196
|
+
if (!answer.ok)
|
|
197
|
+
return skippedCheck('K4', at, answer.reason);
|
|
198
|
+
addUsage(usage, answer.usage);
|
|
199
|
+
const supported = parseSupportAnswer(answer.json);
|
|
200
|
+
if (supported === null)
|
|
201
|
+
return skippedCheck('K4', at, 'bad_model_output');
|
|
202
|
+
const extras = { by: 'model', ...(answer.model ? { model: answer.model } : {}), durationMs: answer.durationMs };
|
|
203
|
+
return supported
|
|
204
|
+
? okCheck('K4', at, undefined, extras)
|
|
205
|
+
: failCheck('KNOWLEDGE_UNSUPPORTED', at, 'K4 the evidence does not support the draft', extras);
|
|
206
|
+
}
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// Entry point
|
|
209
|
+
// ---------------------------------------------------------------------------
|
|
210
|
+
/** K1 owns every static issue except the preference-horizon rule, which is K3's. */
|
|
211
|
+
function isK3Issue(issue) {
|
|
212
|
+
return issue.path === 'payload.preference.horizon';
|
|
213
|
+
}
|
|
214
|
+
export async function validateKnowledge(ctx, report) {
|
|
215
|
+
const at = ctx.ports.now();
|
|
216
|
+
const usage = { in: 0, out: 0 };
|
|
217
|
+
const { rest } = splitIssues(report.issues, isK3Issue);
|
|
218
|
+
const checks = [staticCheck(rest, at)];
|
|
219
|
+
const resolved = await resolveEvidence(ctx.ports, ctx.scope, ctx.geneId, ctx.content, ctx.evidence);
|
|
220
|
+
const source = await checkSource({
|
|
221
|
+
ports: ctx.ports,
|
|
222
|
+
scope: ctx.scope,
|
|
223
|
+
content: ctx.content,
|
|
224
|
+
evidence: ctx.evidence,
|
|
225
|
+
resolved,
|
|
226
|
+
...(ctx.geneId === undefined ? {} : { geneId: ctx.geneId }),
|
|
227
|
+
});
|
|
228
|
+
checks.push(...source.checks);
|
|
229
|
+
if (source.clipped.length > 0) {
|
|
230
|
+
// The gene may still be right: the evidence we held was cut, not wrong. It goes in on probation
|
|
231
|
+
// (visible, double-weighted, revoked after it misleads twice) instead of dying here (RV-13).
|
|
232
|
+
const count = summarizeMissing(source.clipped);
|
|
233
|
+
checks.push(okCheck('KNOWLEDGE_EVIDENCE_CLIPPED', at, `K2 ${count} only missing because the evidence was clipped`));
|
|
234
|
+
}
|
|
235
|
+
checks.push(...checkScope(ctx, at));
|
|
236
|
+
checks.push(await checkSupported(ctx, resolved.corpus, usage));
|
|
237
|
+
const conflict = await runConflictCheck(ctx.ports, {
|
|
238
|
+
type: 'knowledge',
|
|
239
|
+
scope: ctx.scope,
|
|
240
|
+
content: ctx.content,
|
|
241
|
+
...(ctx.geneId === undefined ? {} : { geneId: ctx.geneId }),
|
|
242
|
+
});
|
|
243
|
+
checks.push(...conflict.checks);
|
|
244
|
+
addUsage(usage, conflict.usage);
|
|
245
|
+
const trust = trustCheck(ctx.evidence, at);
|
|
246
|
+
checks.push(trust.check);
|
|
247
|
+
const needsHuman = trust.needsHuman ?? (conflict.decision.action === 'needs_human' ? conflict.decision.reason : undefined);
|
|
248
|
+
return {
|
|
249
|
+
checks,
|
|
250
|
+
conflict: conflict.decision,
|
|
251
|
+
usage,
|
|
252
|
+
...(needsHuman === undefined ? {} : { needsHuman }),
|
|
253
|
+
...(source.clipped.length > 0 ? { forceProbation: true } : {}),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GeneEvidence } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
export type LiveCheckStatus = 'passed' | 'failed' | 'nothing_to_check' | 'skipped_budget';
|
|
3
|
+
export interface LiveCheckResult {
|
|
4
|
+
status: LiveCheckStatus;
|
|
5
|
+
checked: number;
|
|
6
|
+
failed: number;
|
|
7
|
+
}
|
|
8
|
+
export interface LiveCheckOptions {
|
|
9
|
+
/** Wall clock, injected so the grep budget is testable. */
|
|
10
|
+
clock?: () => number;
|
|
11
|
+
grepBudgetMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Re-check `file` and `symbol` evidence against the live project tree. Never throws. */
|
|
14
|
+
export declare function liveCheckEvidence(root: string, evidence: readonly GeneEvidence[], options?: LiveCheckOptions): Promise<LiveCheckResult>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OPTIONAL live evidence check of K2 (gene-bank spec 10.7.1 K2, RV-10).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* It runs only when the evidence's project root is reachable on THIS machine. The curator lease
|
|
7
|
+
* holder may be a process in a different project, with no access to the directory the evidence
|
|
8
|
+
* came from, so "cannot check" is a normal outcome and is NEVER a failure: the deterministic
|
|
9
|
+
* verbatim-token check does not depend on this module at all.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IT CHECKS. `file` evidence: the file still exists under the root, its hash (when the
|
|
12
|
+
* evidence recorded one) still matches, otherwise the quoted first line is still in it.
|
|
13
|
+
* `symbol` evidence: a bounded walk finds the symbol (at most 2 s, 3000 files). Every other
|
|
14
|
+
* evidence kind (user statements, transcripts, tool output, urls) has nothing to re-read.
|
|
15
|
+
*
|
|
16
|
+
* ALL PATHS STAY INSIDE THE ROOT. An evidence `path` is data a model wrote down; a `..` in it
|
|
17
|
+
* must not make the curator read outside the project. Such evidence is "not verifiable", which
|
|
18
|
+
* is a skip, not a pass and not a failure.
|
|
19
|
+
*/
|
|
20
|
+
import { createHash } from 'node:crypto';
|
|
21
|
+
import { promises as nodeFs } from 'node:fs';
|
|
22
|
+
import { isAbsolute, join } from 'node:path';
|
|
23
|
+
import { unescapeGeneEntities } from '@aragon-agent/tui/model/gene/escape';
|
|
24
|
+
import { isInsideRoot } from '../../paths.js';
|
|
25
|
+
const MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
26
|
+
const GREP_FILE_BYTES = 512 * 1024;
|
|
27
|
+
const GREP_MAX_FILES = 3000;
|
|
28
|
+
const GREP_BUDGET_MS = 2000;
|
|
29
|
+
const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'build', 'target', '.next', '.venv', '__pycache__']);
|
|
30
|
+
const TEXT_FILE_RE = /\.(?:ts|tsx|js|jsx|mjs|cjs|json|md|py|rs|go|java|cs|sh|ps1|cmd|bat|txt|css|html|xml|yml|yaml|toml)$/i;
|
|
31
|
+
function digestMatches(bytes, recorded) {
|
|
32
|
+
const want = recorded.trim().toLowerCase();
|
|
33
|
+
if (!/^[0-9a-f]{7,64}$/.test(want))
|
|
34
|
+
return false;
|
|
35
|
+
const sha1 = createHash('sha1').update(bytes).digest('hex');
|
|
36
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
37
|
+
return sha1.startsWith(want) || sha256.startsWith(want);
|
|
38
|
+
}
|
|
39
|
+
function quoteNeedle(text) {
|
|
40
|
+
const line = text.split(/\r?\n/).map((l) => l.trim()).find((l) => l.length >= 8);
|
|
41
|
+
return (line ?? '').slice(0, 120);
|
|
42
|
+
}
|
|
43
|
+
async function checkFileEvidence(root, evidence) {
|
|
44
|
+
const rel = evidence.source.path;
|
|
45
|
+
if (typeof rel !== 'string' || rel.length === 0)
|
|
46
|
+
return 'unverifiable';
|
|
47
|
+
const path = isAbsolute(rel) ? rel : join(root, rel);
|
|
48
|
+
if (!isInsideRoot(root, path))
|
|
49
|
+
return 'unverifiable';
|
|
50
|
+
let stat;
|
|
51
|
+
try {
|
|
52
|
+
stat = await nodeFs.stat(path);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return 'failed';
|
|
56
|
+
}
|
|
57
|
+
if (!stat.isFile())
|
|
58
|
+
return 'failed';
|
|
59
|
+
if (stat.size > MAX_FILE_BYTES)
|
|
60
|
+
return 'unverifiable';
|
|
61
|
+
const bytes = await nodeFs.readFile(path).catch(() => null);
|
|
62
|
+
if (bytes === null)
|
|
63
|
+
return 'failed';
|
|
64
|
+
const recorded = evidence.source.hash;
|
|
65
|
+
if (typeof recorded === 'string' && recorded.length > 0) {
|
|
66
|
+
return digestMatches(bytes, recorded) ? 'ok' : 'failed';
|
|
67
|
+
}
|
|
68
|
+
const needle = quoteNeedle(evidence.text);
|
|
69
|
+
if (needle.length === 0)
|
|
70
|
+
return 'ok';
|
|
71
|
+
const text = bytes.toString('utf8').replace(/\r\n/g, '\n');
|
|
72
|
+
if (text.includes(needle))
|
|
73
|
+
return 'ok';
|
|
74
|
+
// A quote captured from an escaped prompt holds entities the file never had: compare the
|
|
75
|
+
// unescaped forms too, so "the file still says it" means the same thing in every check (RV-20).
|
|
76
|
+
return unescapeGeneEntities(text).includes(unescapeGeneEntities(needle)) ? 'ok' : 'failed';
|
|
77
|
+
}
|
|
78
|
+
async function grepFile(path, symbol, state) {
|
|
79
|
+
if (!TEXT_FILE_RE.test(path))
|
|
80
|
+
return;
|
|
81
|
+
state.files += 1;
|
|
82
|
+
const stat = await nodeFs.stat(path).catch(() => null);
|
|
83
|
+
if (stat === null || stat.size > GREP_FILE_BYTES)
|
|
84
|
+
return;
|
|
85
|
+
const text = await nodeFs.readFile(path, 'utf8').catch(() => '');
|
|
86
|
+
if (text.includes(symbol))
|
|
87
|
+
state.found = true;
|
|
88
|
+
}
|
|
89
|
+
async function grepSymbol(root, symbol, opts) {
|
|
90
|
+
const started = opts.clock();
|
|
91
|
+
const state = { found: false, files: 0 };
|
|
92
|
+
const queue = [root];
|
|
93
|
+
while (queue.length > 0 && !state.found) {
|
|
94
|
+
if (opts.clock() - started > opts.grepBudgetMs || state.files >= GREP_MAX_FILES)
|
|
95
|
+
return 'budget';
|
|
96
|
+
const dir = queue.shift();
|
|
97
|
+
const entries = await nodeFs.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
98
|
+
for (const entry of entries) {
|
|
99
|
+
const full = join(dir, entry.name);
|
|
100
|
+
if (entry.isDirectory()) {
|
|
101
|
+
if (!SKIP_DIRS.has(entry.name))
|
|
102
|
+
queue.push(full);
|
|
103
|
+
}
|
|
104
|
+
else if (entry.isFile() && !state.found) {
|
|
105
|
+
await grepFile(full, symbol, state);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return state.found ? 'found' : 'missing';
|
|
110
|
+
}
|
|
111
|
+
/** Re-check `file` and `symbol` evidence against the live project tree. Never throws. */
|
|
112
|
+
export async function liveCheckEvidence(root, evidence, options = {}) {
|
|
113
|
+
const opts = {
|
|
114
|
+
clock: options.clock ?? Date.now,
|
|
115
|
+
grepBudgetMs: options.grepBudgetMs ?? GREP_BUDGET_MS,
|
|
116
|
+
};
|
|
117
|
+
let checked = 0;
|
|
118
|
+
let failed = 0;
|
|
119
|
+
let budget = false;
|
|
120
|
+
for (const item of evidence) {
|
|
121
|
+
try {
|
|
122
|
+
if (item.kind === 'file') {
|
|
123
|
+
const verdict = await checkFileEvidence(root, item);
|
|
124
|
+
if (verdict === 'unverifiable')
|
|
125
|
+
continue;
|
|
126
|
+
checked += 1;
|
|
127
|
+
if (verdict === 'failed')
|
|
128
|
+
failed += 1;
|
|
129
|
+
}
|
|
130
|
+
else if (item.kind === 'symbol' && typeof item.source.symbol === 'string') {
|
|
131
|
+
const verdict = await grepSymbol(root, item.source.symbol, opts);
|
|
132
|
+
if (verdict === 'budget')
|
|
133
|
+
budget = true;
|
|
134
|
+
else {
|
|
135
|
+
checked += 1;
|
|
136
|
+
if (verdict === 'missing')
|
|
137
|
+
failed += 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
budget = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (failed > 0)
|
|
146
|
+
return { status: 'failed', checked, failed };
|
|
147
|
+
if (checked === 0)
|
|
148
|
+
return { status: budget ? 'skipped_budget' : 'nothing_to_check', checked, failed };
|
|
149
|
+
return { status: 'passed', checked, failed };
|
|
150
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seams the curator's validators reach the outside world through
|
|
3
|
+
* (gene-bank spec 10.7, 10.9; RV-1; I-6, I-25).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`. TYPES ONLY.
|
|
6
|
+
*
|
|
7
|
+
* WHY PORTS AND NOT IMPORTS. The validators decide whether a candidate may be published, so the
|
|
8
|
+
* code that decides must be runnable (and testable) with nothing else in the process: no
|
|
9
|
+
* version service, no queue, no model provider. Every fact about the library, the model and
|
|
10
|
+
* the machine arrives through `ValidatorPorts`, and every result leaves as plain data
|
|
11
|
+
* (`GeneValidation`, a decision record). That also makes the safety property checkable: a
|
|
12
|
+
* validator that cannot reach a writer cannot write.
|
|
13
|
+
*
|
|
14
|
+
* `modelJson` ABSENT OR RETURNING `null` MEANS "NO MODEL ANSWER". The model checks (K4, K5, S3,
|
|
15
|
+
* S4) are then SKIPPED AND RECORDED AS SKIPPED (`SKIPPED_<id>`); a check that was not run is
|
|
16
|
+
* never reported as passed.
|
|
17
|
+
*/
|
|
18
|
+
import type { EnvFingerprint, GeneBrief, GeneEvidence, GeneHead, GeneIndexRow, GeneScope, GeneType, GeneVersion } from '@aragon-agent/tui/model/gene/types';
|
|
19
|
+
import type { GeneConfig } from '@aragon-agent/tui/model/config/schema';
|
|
20
|
+
export interface ModelJsonRequest {
|
|
21
|
+
/** English. Gene text is data; the system text says so. */
|
|
22
|
+
system: string;
|
|
23
|
+
user: string;
|
|
24
|
+
maxTokens: number;
|
|
25
|
+
timeoutMs: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ModelJsonResponse {
|
|
28
|
+
/** The model's answer already parsed as JSON. `unknown`: it is untrusted until guarded. */
|
|
29
|
+
json: unknown;
|
|
30
|
+
usage?: {
|
|
31
|
+
in: number;
|
|
32
|
+
out: number;
|
|
33
|
+
};
|
|
34
|
+
model?: string;
|
|
35
|
+
}
|
|
36
|
+
/** A published gene as the validators need it: its head and its served (current) version. */
|
|
37
|
+
export interface GeneLookup {
|
|
38
|
+
head: GeneHead;
|
|
39
|
+
version: GeneVersion;
|
|
40
|
+
}
|
|
41
|
+
export interface ValidatorPorts {
|
|
42
|
+
now(): number;
|
|
43
|
+
/** null / absent => model checks are skipped and recorded as skipped, never faked. */
|
|
44
|
+
modelJson?(req: ModelJsonRequest): Promise<ModelJsonResponse | null>;
|
|
45
|
+
readEvidence(scope: GeneScope, geneId: string, ref: string): Promise<GeneEvidence | null>;
|
|
46
|
+
/** The head and the served version of a gene, from ANY scope the caller may see. */
|
|
47
|
+
lookupGene(id: string): Promise<GeneLookup | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Same-type neighbours of `brief` within `scope` (k nearest). `brief.vec` is filled when the
|
|
50
|
+
* validator could embed the candidate; an implementation may use it or ignore it.
|
|
51
|
+
*/
|
|
52
|
+
neighbours(scope: GeneScope, type: GeneType, brief: GeneBrief, k: number): Promise<GeneIndexRow[]>;
|
|
53
|
+
/** The project's root directory, for the OPTIONAL live evidence check; undefined = unreachable. */
|
|
54
|
+
projectRoot?(scope: GeneScope): string | undefined;
|
|
55
|
+
config: Pick<GeneConfig, 'toolsAllowNetwork' | 'probeMode'>;
|
|
56
|
+
env: EnvFingerprint;
|
|
57
|
+
/** `true` when `cmd` resolves on PATH. Absent => the environment check is skipped. */
|
|
58
|
+
commandOnPath?(cmd: string): boolean;
|
|
59
|
+
/** Provider API keys, passed to the secret screen (RV-18). */
|
|
60
|
+
knownSecrets?: readonly string[];
|
|
61
|
+
/** The host's built-in tool names a composite may call (T7). Absent => T7 fails closed. */
|
|
62
|
+
hostToolNames?: readonly string[];
|
|
63
|
+
/** Parameter schema of a built-in tool, when known (T7 argument check). */
|
|
64
|
+
hostToolSchema?(name: string): unknown;
|
|
65
|
+
/** Labels of the user's known projects, for the "project name in a user-scope gene" rule (K3). */
|
|
66
|
+
projectLabels?: readonly string[];
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ValidatorPorts } from './ports.js';
|
|
2
|
+
export declare const MODEL_CALL: {
|
|
3
|
+
readonly maxTokens: 600;
|
|
4
|
+
readonly timeoutMs: 20000;
|
|
5
|
+
};
|
|
6
|
+
export type ModelAnswer = {
|
|
7
|
+
ok: true;
|
|
8
|
+
json: unknown;
|
|
9
|
+
model?: string;
|
|
10
|
+
durationMs: number;
|
|
11
|
+
usage?: {
|
|
12
|
+
in: number;
|
|
13
|
+
out: number;
|
|
14
|
+
};
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
reason: 'no_model' | 'unavailable';
|
|
18
|
+
};
|
|
19
|
+
/** Ask the validator model; absent port, a null answer or a thrown call all mean "skipped". */
|
|
20
|
+
export declare function askModel(ports: ValidatorPorts, system: string, user: string): Promise<ModelAnswer>;
|
|
21
|
+
export interface PromptPair {
|
|
22
|
+
system: string;
|
|
23
|
+
user: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function buildSupportPrompt(draft: string, evidence: readonly string[]): PromptPair;
|
|
26
|
+
export declare function parseSupportAnswer(json: unknown): boolean | null;
|
|
27
|
+
export type NeighbourRelation = 'duplicate' | 'refines' | 'contradicts' | 'unrelated';
|
|
28
|
+
export declare const RELATIONS: readonly NeighbourRelation[];
|
|
29
|
+
export interface BriefText {
|
|
30
|
+
name: string;
|
|
31
|
+
purpose: string;
|
|
32
|
+
trigger: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function buildRelationPrompt(candidate: BriefText & {
|
|
35
|
+
body: string;
|
|
36
|
+
}, neighbours: readonly BriefText[]): PromptPair;
|
|
37
|
+
export declare function parseRelationAnswer(json: unknown, count: number): Array<NeighbourRelation | null> | null;
|
|
38
|
+
export declare function buildTriggerPrompt(trigger: string, tasks: readonly string[]): PromptPair;
|
|
39
|
+
export declare function parseTriggerAnswer(json: unknown, count: number): Array<boolean | null> | null;
|
|
40
|
+
export declare function buildAcceptancePrompt(lines: readonly string[]): PromptPair;
|
|
41
|
+
export declare function parseAcceptanceAnswer(json: unknown, count: number): Array<boolean | null> | null;
|