@aragon-agent/cli 0.6.63 → 0.6.64
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 +70 -2
- package/README.md +44 -20
- package/dist/agent/controller.d.ts +66 -14
- package/dist/agent/controller.js +291 -81
- package/dist/agent/headless.d.ts +16 -0
- package/dist/agent/headless.js +44 -3
- package/dist/agent/team-notices.d.ts +57 -7
- package/dist/agent/team-notices.js +93 -10
- package/dist/app/App.js +199 -77
- package/dist/cli.js +4 -1
- package/dist/config/cli-commands.d.ts +1 -1
- package/dist/config/cli-commands.js +11 -0
- package/dist/exec/index.js +2 -0
- package/dist/exec/runner.js +10 -1
- package/dist/gene/commit-prepare.js +27 -1
- package/dist/gene/curator/curator.d.ts +15 -0
- package/dist/gene/curator/curator.js +26 -2
- package/dist/gene/curator/scripted-lane.d.ts +12 -0
- package/dist/gene/curator/scripted-lane.js +101 -0
- package/dist/gene/curator/task-context.d.ts +21 -0
- package/dist/gene/curator/task-context.js +33 -0
- package/dist/gene/curator/task-runner.d.ts +10 -1
- package/dist/gene/curator/task-runner.js +39 -4
- package/dist/gene/curator/tool-support.js +11 -4
- package/dist/gene/curator/toolkit.d.ts +13 -0
- package/dist/gene/curator/toolkit.js +23 -1
- package/dist/gene/curator/tools-verify.js +2 -2
- package/dist/gene/curator/tools-write.js +6 -1
- package/dist/gene/curator/validate/evidence-tokens.js +133 -22
- package/dist/gene/curator/validate/knowledge.d.ts +41 -1
- package/dist/gene/curator/validate/knowledge.js +74 -11
- package/dist/gene/curator/validate/prompts.d.ts +10 -2
- package/dist/gene/curator/validate/prompts.js +2 -2
- package/dist/gene/learn/draft-guard.d.ts +17 -0
- package/dist/gene/learn/draft-guard.js +113 -0
- package/dist/gene/learn/learn-prompt.d.ts +22 -1
- package/dist/gene/learn/learn-prompt.js +27 -2
- package/dist/gene/learn/learner.js +20 -2
- package/dist/gene/queue.d.ts +16 -0
- package/dist/gene/queue.js +44 -1
- package/dist/governance/store/run-store.d.ts +20 -0
- package/dist/governance/store/run-store.js +54 -8
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/host/interaction.d.ts +8 -17
- package/dist/host/interaction.js +50 -72
- package/dist/host/team-wake-driver.d.ts +90 -0
- package/dist/host/team-wake-driver.js +114 -0
- package/dist/logging/install.d.ts +32 -1
- package/dist/logging/install.js +15 -0
- package/dist/team/console-tools.d.ts +12 -0
- package/dist/team/console-tools.js +20 -3
- package/dist/team/console-view.js +11 -1
- package/dist/team/notices.d.ts +81 -4
- package/dist/team/notices.js +187 -22
- package/dist/team/prompt.js +1 -1
- package/dist/team/runtime.d.ts +67 -24
- package/dist/team/runtime.js +250 -31
- package/dist/team/stall-watch.d.ts +54 -0
- package/dist/team/stall-watch.js +119 -0
- package/dist/team/task-tool.js +2 -2
- package/dist/team/wake.d.ts +176 -0
- package/dist/team/wake.js +444 -0
- package/package.json +81 -81
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
import { defineCuratorTool, receipt, refuse } from './tool-support.js';
|
|
2
2
|
export const TOOL_GROUP_NAMES = ['author', 'maintain', 'verify', 'release'];
|
|
3
3
|
export const ALWAYS_VISIBLE = ['gene_search', 'gene_read', 'gene_toolkit'];
|
|
4
|
+
/**
|
|
5
|
+
* What a draft must carry, by type (gene-bank-never-publishes-3, R-2). The validators refuse a draft
|
|
6
|
+
* that lacks any of it, and 17 of 17 skill drafts the reviewer wrote lacked all of it: the model had
|
|
7
|
+
* only the six section NAMES (prompt.ts) and a payload described as "kind, claims, exec, requires or
|
|
8
|
+
* preference". ASCII, and every enum is the validator's own (`validate-payload.ts`).
|
|
9
|
+
*/
|
|
10
|
+
export const AUTHOR_GUIDE = [
|
|
11
|
+
'Contract - a refused draft lists every problem at once, so fix them all in one rewrite:',
|
|
12
|
+
'- knowledge: payload { kind: fact|constraint|resolution|preference, claims?: up to 8',
|
|
13
|
+
' { text, evidence: an ev_ ref or "" } }. kind preference ALSO needs payload.preference',
|
|
14
|
+
' { horizon: long_term|project|temporary, statedBy: user|inferred, confirmed: true|false };',
|
|
15
|
+
' an inferred preference stays confirmed:false.',
|
|
16
|
+
'- skill: body has six non-empty headings written as "## Trigger", "## Preconditions",',
|
|
17
|
+
' "## Steps" (a numbered list, "1. ..."), "## Branches", "## Acceptance", "## Fallback".',
|
|
18
|
+
' payload { requires: [] or up to 12 { id: a gene id, interface?: number } - list every',
|
|
19
|
+
' [[gene id]] the body mentions; acceptance: 1-8 single-line checks; fallback: one sentence }.',
|
|
20
|
+
'- tool: payload needs exec, inputSchema, outputSchema, examples (each with expect) and',
|
|
21
|
+
' permissions; a refusal names each missing field.',
|
|
22
|
+
].join('\n');
|
|
4
23
|
export const TOOL_GROUPS = {
|
|
5
24
|
author: {
|
|
6
25
|
tools: ['gene_create_candidate', 'gene_revise'],
|
|
7
26
|
summary: 'Draft: gene_create_candidate writes a new candidate gene and gene_revise writes a candidate ' +
|
|
8
27
|
'revision of an existing one. Neither publishes anything; agents cannot see candidates.',
|
|
28
|
+
guide: AUTHOR_GUIDE,
|
|
9
29
|
},
|
|
10
30
|
maintain: {
|
|
11
31
|
tools: ['gene_merge', 'gene_archive', 'gene_restore', 'gene_set_health'],
|
|
@@ -93,7 +113,9 @@ export class CuratorToolkit {
|
|
|
93
113
|
return receipt(`Group ${group} is already loaded.`);
|
|
94
114
|
this.loadedGroups.add(group);
|
|
95
115
|
this.changed();
|
|
96
|
-
|
|
116
|
+
const { tools, guide } = TOOL_GROUPS[group];
|
|
117
|
+
const loaded = `Loaded ${group}: ${tools.join(', ')}. Available from your next step.`;
|
|
118
|
+
return receipt(guide === undefined ? loaded : `${loaded}\n${guide}`);
|
|
97
119
|
}
|
|
98
120
|
unload(group) {
|
|
99
121
|
if (!this.loadedGroups.delete(group))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { autoProbe } from './probe.js';
|
|
2
|
-
import { validationKey } from './task-context.js';
|
|
2
|
+
import { describeTaskStats, validationKey } from './task-context.js';
|
|
3
3
|
import { validateCandidateDetailed } from './validate/index.js';
|
|
4
4
|
import { repairLines, resolveEvidence } from './validate/knowledge.js';
|
|
5
5
|
import { CURATOR_ACTOR, asString, defineCuratorTool, receipt, refuse, switchGate, } from './tool-support.js';
|
|
@@ -200,7 +200,7 @@ async function validateCandidate(env, params) {
|
|
|
200
200
|
version: v.n,
|
|
201
201
|
scope: head.scope,
|
|
202
202
|
type: head.type,
|
|
203
|
-
detail: `name=${head.brief.name}`,
|
|
203
|
+
detail: `name=${head.brief.name}${describeTaskStats(env.ctx.stats)}`,
|
|
204
204
|
});
|
|
205
205
|
const advice = await actOnVerdict(env, head, outcome);
|
|
206
206
|
const fix = await fixAdvice(env, head, v, outcome);
|
|
@@ -45,7 +45,12 @@ const CONTENT_PARAM = {
|
|
|
45
45
|
},
|
|
46
46
|
applicability: APPLICABILITY_PARAM,
|
|
47
47
|
roles: { type: 'array', items: { type: 'string', enum: ['main', 'subagent', 'reviewer'] } },
|
|
48
|
-
payload: {
|
|
48
|
+
payload: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
description: 'knowledge: kind, claims, and preference { horizon, statedBy, confirmed } when kind is preference. ' +
|
|
51
|
+
'skill: requires, acceptance (1-8 lines), fallback. tool: exec, inputSchema, outputSchema, ' +
|
|
52
|
+
'examples, permissions. Load the author group for the full contract.',
|
|
53
|
+
},
|
|
49
54
|
},
|
|
50
55
|
};
|
|
51
56
|
function candidateNote(outcome, warnings) {
|
|
@@ -37,6 +37,22 @@
|
|
|
37
37
|
* AND the words inside it are never re-scanned - re-pairing the marks is what turned one
|
|
38
38
|
* over-long span into three invented "symbols" on a real candidate.
|
|
39
39
|
*
|
|
40
|
+
* FIVE MORE, FOR SHAPES THAT ARE NOT FACTS EITHER (gene-bank-never-publishes-3, R-7'). Replaying
|
|
41
|
+
* the 15 stored candidates showed about one in five rejected tokens was our extractor reading
|
|
42
|
+
* grammar or prose as a path or a symbol - which is how `/dev/null` alone vetoed a gene ABOUT
|
|
43
|
+
* `/dev/null`:
|
|
44
|
+
* 8. a device path or a redirection (`/dev/null`, `2>/dev/null`, `>nul`, `2>&1`);
|
|
45
|
+
* 9. a PROSE alternative: `deploy/update/roll`, or CJK words joined by slashes. With no
|
|
46
|
+
* extension, no anchor and no backticks it is "and/or", not a location - a backticked
|
|
47
|
+
* `packages/cli/src` is still a path;
|
|
48
|
+
* 10. a COMMAND LINE inside backticks (`git status --short`, `cd X && python y.py`,
|
|
49
|
+
* `timeout /t 90 /nobreak >nul`, a CJK sentence): it is read WORD BY WORD, so the path or file
|
|
50
|
+
* name inside it is still checked, but the exact command string is not demanded verbatim;
|
|
51
|
+
* 11. a placeholder or a glob (`aragon-YYYY-MM-DD.log`, `patch-NN.txt`, `sessions/<id>.json`,
|
|
52
|
+
* `.../core/dist`, `aragon-*.log`), and a path word that still carries a quote, `=` or `|`;
|
|
53
|
+
* 12. a doubled path separator: a JSON-escaped `C:\\a\\b` compares equal to `C:\a\b`.
|
|
54
|
+
* None of these weakens the check for an invented path, symbol, error code or number.
|
|
55
|
+
*
|
|
40
56
|
* A MISS WE CAUSED OURSELVES IS NOT THE DRAFT'S FAULT. Evidence is clipped with a trailing `...`
|
|
41
57
|
* on its way into the prompt, so a token our own clip explains is reported as `clipped`, not
|
|
42
58
|
* `missing` (RV-13): both when the evidence cut the token's tail and (RC-7) when the draft says
|
|
@@ -81,13 +97,40 @@ const UNIT_WORDS = new Set([
|
|
|
81
97
|
'kb', 'mb', 'gb', 'tb', 'px', '%',
|
|
82
98
|
]);
|
|
83
99
|
/** `--help`, `-x`, `/d`: a command switch, which is neither a path nor a value. */
|
|
84
|
-
const FLAG_RE = /^(?:--?[A-Za-z][\w-]
|
|
100
|
+
const FLAG_RE = /^(?:--?[A-Za-z][\w-]*(?:=\S*)?|\/[A-Za-z0-9]:?)$/;
|
|
85
101
|
/** `&&`, `||`, `|`, `>`, `>>`, `<`, `;`: shell grammar. */
|
|
86
102
|
const SHELL_OPERATOR_RE = /^(?:&&|\|\||[|&;<>]|>>|<<|\$\(|\$\?)$/;
|
|
87
103
|
/** `!errorlevel!`, `%errorlevel%`: a batch variable the shell expands. */
|
|
88
104
|
const BATCH_VAR_RE = /^(?:![A-Za-z_]\w*!?|%[A-Za-z_]\w*%?)$/;
|
|
89
105
|
/** `EXITCODE=0`: an assignment whose right-hand side is whatever the run happened to print. */
|
|
90
106
|
const ENV_ASSIGN_RE = /^[A-Z][A-Z0-9_]*=[A-Za-z0-9_%.\\/:-]*$/;
|
|
107
|
+
/** `/dev/null`, `2>/dev/null`: a device belongs to the shell, not to the project (RC-3 item 8). */
|
|
108
|
+
const DEVICE_PATH_RE = /^(?:\d{0,2}>>?)?\/dev\/(?:null|zero|full|random|urandom|tty|stdin|stdout|stderr|fd\/\d+)$/;
|
|
109
|
+
/** `>nul`, `2>&1`, `>>out.log`, `<in.txt`: a redirection and its target, which the shell resolves. */
|
|
110
|
+
const REDIRECT_RE = /^(?:\d{0,2}>>?|<<?)(?:&\d|[\w.\/-]*)$/;
|
|
111
|
+
/** `/nobreak`: a switch only INSIDE a command line - a lone `/tmp` stays a path. */
|
|
112
|
+
const COMMAND_SWITCH_RE = /^\/[A-Za-z][A-Za-z0-9?]*$/;
|
|
113
|
+
/** `YYYY`, `NN`, `HH` standing alone in a name: a pattern the author spelled out, not a file. */
|
|
114
|
+
const PLACEHOLDER_TOKEN_RE = /(?:^|[^A-Za-z])(?:YYYY|MM|DD|HH|SS|NN+|XX+)(?![A-Za-z])/;
|
|
115
|
+
/** A glob metacharacter. */
|
|
116
|
+
const GLOB_CHAR_RE = /[*?]/;
|
|
117
|
+
/** A path word that still carries one of these is a broken span, a glob or shell - not a location. */
|
|
118
|
+
const NOT_A_PATH_CHAR_RE = /["'<>|;=*?]/;
|
|
119
|
+
/**
|
|
120
|
+
* The first word of a backticked span that makes it a COMMAND LINE. An enumerable list on purpose:
|
|
121
|
+
* the same discipline as the other shape rules - a new shape is a new line here, not a heuristic.
|
|
122
|
+
*/
|
|
123
|
+
const COMMAND_HEADS = new Set([
|
|
124
|
+
'cd', 'ls', 'dir', 'cp', 'mv', 'rm', 'del', 'cat', 'echo', 'set', 'type', 'copy', 'move', 'mkdir',
|
|
125
|
+
'rmdir', 'robocopy', 'xcopy', 'git', 'npm', 'npx', 'pnpm', 'yarn', 'node', 'python', 'python3', 'py',
|
|
126
|
+
'pip', 'pytest', 'vitest', 'tsc', 'curl', 'ssh', 'scp', 'sudo', 'systemctl', 'journalctl', 'ping',
|
|
127
|
+
'timeout', 'taskkill', 'tasklist', 'powershell', 'pwsh', 'cmd', 'bash', 'sh', 'make', 'cargo', 'go',
|
|
128
|
+
'docker', 'kubectl', 'grep', 'rg', 'find', 'sed', 'awk', 'chmod', 'chown', 'kill', 'start',
|
|
129
|
+
]);
|
|
130
|
+
/** CJK ideographs, kana and full-width forms, built from code points so this file stays ASCII-only. */
|
|
131
|
+
const CJK_RE = new RegExp(`[${String.fromCodePoint(0x3040)}-${String.fromCodePoint(0x30ff)}` +
|
|
132
|
+
`${String.fromCodePoint(0x3400)}-${String.fromCodePoint(0x9fff)}` +
|
|
133
|
+
`${String.fromCodePoint(0xff00)}-${String.fromCodePoint(0xffef)}]`);
|
|
91
134
|
function trimWord(word) {
|
|
92
135
|
let out = word.replace(/^[("'[{<`]+/, '').replace(/[)"'\]}>,;:!?`]+$/, '');
|
|
93
136
|
// A sentence-ending dot is not part of the token; a dot inside a name is.
|
|
@@ -98,11 +141,22 @@ function trimWord(word) {
|
|
|
98
141
|
function isNumericOnly(segments) {
|
|
99
142
|
return segments.every((s) => /^\d+$/.test(s));
|
|
100
143
|
}
|
|
101
|
-
/**
|
|
102
|
-
function
|
|
144
|
+
/** An elided prefix, a `<placeholder>` or a `YYYY`/`NN` slot: the author named a shape (RC-3 item 11). */
|
|
145
|
+
function isPlaceholderWord(word) {
|
|
146
|
+
return PLACEHOLDER_RE.test(word) || PLACEHOLDER_TOKEN_RE.test(word);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Does a slash-bearing word look like a path rather than "and/or"?
|
|
150
|
+
*
|
|
151
|
+
* `inCode` is true for a backticked span and for a word read out of a backticked command line:
|
|
152
|
+
* the author marked it as code, so a bare `packages/cli/src` is a location. The same three
|
|
153
|
+
* segments in running prose (`deploy/update/roll`) are alternatives, and CJK words joined by
|
|
154
|
+
* slashes never are a location unless something else (an extension, an anchor) says so.
|
|
155
|
+
*/
|
|
156
|
+
function looksLikePath(word, inCode) {
|
|
103
157
|
if (URL_RE.test(word))
|
|
104
158
|
return true;
|
|
105
|
-
if (!/[\\/]/.test(word))
|
|
159
|
+
if (!/[\\/]/.test(word) || NOT_A_PATH_CHAR_RE.test(word) || isPlaceholderWord(word))
|
|
106
160
|
return false;
|
|
107
161
|
const segments = word.split(/[\\/]/).filter((s) => s.length > 0);
|
|
108
162
|
if (segments.length === 0 || isNumericOnly(segments))
|
|
@@ -111,33 +165,39 @@ function looksLikePath(word) {
|
|
|
111
165
|
const hasExtension = /\.[A-Za-z0-9]{1,8}$/.test(last);
|
|
112
166
|
const anchored = /^(?:\.{1,2}[\\/]|[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(word);
|
|
113
167
|
const directory = /[\\/]$/.test(word);
|
|
114
|
-
|
|
168
|
+
if (hasExtension || anchored || directory)
|
|
169
|
+
return true;
|
|
170
|
+
return inCode && segments.length >= 3 && !CJK_RE.test(word);
|
|
115
171
|
}
|
|
116
172
|
/** A quoted span that asserts nothing: a placeholder, a wildcard pattern, or one plain word. */
|
|
117
173
|
function isEmphasisOnly(span) {
|
|
118
174
|
return PLACEHOLDER_RE.test(span) || WILDCARD_SEGMENT_RE.test(span) || PLAIN_WORD_RE.test(span);
|
|
119
175
|
}
|
|
120
|
-
/** Shell grammar rather than a fact the run produced (RC-3
|
|
176
|
+
/** Shell grammar rather than a fact the run produced (RC-3 items 6 and 8). */
|
|
121
177
|
function isShellSyntax(word) {
|
|
122
|
-
return FLAG_RE.test(word) ||
|
|
178
|
+
return (FLAG_RE.test(word) ||
|
|
179
|
+
SHELL_OPERATOR_RE.test(word) ||
|
|
180
|
+
BATCH_VAR_RE.test(word) ||
|
|
181
|
+
ENV_ASSIGN_RE.test(word) ||
|
|
182
|
+
DEVICE_PATH_RE.test(word) ||
|
|
183
|
+
REDIRECT_RE.test(word));
|
|
123
184
|
}
|
|
124
185
|
/** One digit with no unit beside it is a count ("step 2"), not a measurement ("2 s"). */
|
|
125
186
|
function isBareCount(word, unitAdjacent) {
|
|
126
187
|
return !unitAdjacent && BARE_DIGIT_RE.test(word);
|
|
127
188
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (quoted && isEmphasisOnly(word))
|
|
132
|
-
return null;
|
|
133
|
-
if (isShellSyntax(word))
|
|
134
|
-
return null;
|
|
135
|
-
if (isBareCount(word, unitAdjacent))
|
|
189
|
+
/** A location the author may have invented: a path shape or a bare file name, and not a placeholder. */
|
|
190
|
+
function asPath(word, inCode) {
|
|
191
|
+
if (!looksLikePath(word, inCode) && !FILE_NAME_RE.test(word))
|
|
136
192
|
return null;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
193
|
+
return isPlaceholderWord(word) ? null : { kind: 'path', text: word };
|
|
194
|
+
}
|
|
195
|
+
/** `logs/aragon-*.log`: a pattern over many files, not one the run touched. */
|
|
196
|
+
function isGlobPath(word) {
|
|
197
|
+
return (word.includes('/') || word.includes('\\')) && GLOB_CHAR_RE.test(word);
|
|
198
|
+
}
|
|
199
|
+
/** The non-path kinds a word can be. `null`: it asserts nothing we can check. */
|
|
200
|
+
function asValue(word) {
|
|
141
201
|
if (ERRNO_RE.test(word) || UPPER_SNAKE_RE.test(word) || COMPILER_CODE_RE.test(word)) {
|
|
142
202
|
return { kind: 'error_code', text: word };
|
|
143
203
|
}
|
|
@@ -148,6 +208,28 @@ function classify(word, quoted, unitAdjacent = false) {
|
|
|
148
208
|
}
|
|
149
209
|
return null;
|
|
150
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Turn one word into at most one checkable token. `origin` is where it came from: a whole
|
|
213
|
+
* backticked `span` keeps its text as a symbol when nothing else fits; a word read out of a backticked
|
|
214
|
+
* `command` line is judged like prose except that a bare directory path counts as a path; plain
|
|
215
|
+
* `prose` needs a stronger shape (an extension, an anchor) to be called a location.
|
|
216
|
+
*/
|
|
217
|
+
function classify(word, origin, unitAdjacent = false) {
|
|
218
|
+
if (SYSTEM_MINTED_ID_RE.test(word))
|
|
219
|
+
return null;
|
|
220
|
+
if (origin === 'span' && isEmphasisOnly(word))
|
|
221
|
+
return null;
|
|
222
|
+
if (isShellSyntax(word) || (origin === 'command' && COMMAND_SWITCH_RE.test(word)))
|
|
223
|
+
return null;
|
|
224
|
+
if (isBareCount(word, unitAdjacent))
|
|
225
|
+
return null;
|
|
226
|
+
const path = asPath(word, origin !== 'prose');
|
|
227
|
+
if (path !== null)
|
|
228
|
+
return path;
|
|
229
|
+
if (origin === 'span')
|
|
230
|
+
return isPlaceholderWord(word) || isGlobPath(word) ? null : { kind: 'symbol', text: word };
|
|
231
|
+
return asValue(word);
|
|
232
|
+
}
|
|
151
233
|
/**
|
|
152
234
|
* Split a line into its backticked spans and the text between them. Pairing is POSITIONAL - the
|
|
153
235
|
* leftmost mark with the next one - so a span's LENGTH can never move a mark into a different
|
|
@@ -189,6 +271,33 @@ function pushUnique(out, seen, token) {
|
|
|
189
271
|
seen.add(key);
|
|
190
272
|
out.push(token);
|
|
191
273
|
}
|
|
274
|
+
/** Is this word shell grammar that only a command line contains (RC-3 item 10)? */
|
|
275
|
+
function isCommandGrammar(word) {
|
|
276
|
+
// A bare `<` or `>` is a comparison in code as often as a redirection: it proves nothing alone.
|
|
277
|
+
return (isShellSyntax(word) && !/^[<>]+$/.test(word)) || COMMAND_SWITCH_RE.test(word);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Is a backticked span a COMMAND LINE or a sentence rather than one citation? Any span with CJK
|
|
281
|
+
* is (a localized system message or a sentence wearing backticks, RC-3 item 10); otherwise it has
|
|
282
|
+
* several words and either starts with a known command or carries shell grammar (a switch, an
|
|
283
|
+
* operator, a redirection). A span of one non-CJK word is one citation.
|
|
284
|
+
*/
|
|
285
|
+
function isCommandLine(span, words) {
|
|
286
|
+
if (CJK_RE.test(span))
|
|
287
|
+
return true;
|
|
288
|
+
if (words.length < 2)
|
|
289
|
+
return false;
|
|
290
|
+
if (COMMAND_HEADS.has((words[0] ?? '').toLowerCase()))
|
|
291
|
+
return true;
|
|
292
|
+
return words.some(isCommandGrammar);
|
|
293
|
+
}
|
|
294
|
+
/** The tokens of one backticked span: its words when it is a command line, itself otherwise. */
|
|
295
|
+
function spanTokens(span) {
|
|
296
|
+
const words = span.split(/\s+/).map(trimWord).filter((w) => w.length > 0);
|
|
297
|
+
if (!isCommandLine(span, words))
|
|
298
|
+
return [classify(span, 'span')];
|
|
299
|
+
return words.map((word, i) => classify(word, 'command', unitNeighbour(words[i + 1])));
|
|
300
|
+
}
|
|
192
301
|
/** The checkable specifics of `text`, at most 96, in order of first appearance. */
|
|
193
302
|
export function extractVerbatimTokens(text) {
|
|
194
303
|
const out = [];
|
|
@@ -196,17 +305,19 @@ export function extractVerbatimTokens(text) {
|
|
|
196
305
|
for (const rawLine of String(text ?? '').split(/\r?\n/)) {
|
|
197
306
|
const { rest, spans } = quotedSpans(rawLine.replace(LIST_MARKER_RE, ''));
|
|
198
307
|
for (const span of spans)
|
|
199
|
-
|
|
308
|
+
for (const token of spanTokens(span))
|
|
309
|
+
pushUnique(out, seen, token);
|
|
200
310
|
const words = rest.split(/\s+/).map(trimWord);
|
|
201
|
-
words.forEach((word, i) => pushUnique(out, seen, classify(word,
|
|
311
|
+
words.forEach((word, i) => pushUnique(out, seen, classify(word, 'prose', unitNeighbour(words[i + 1]))));
|
|
202
312
|
}
|
|
203
313
|
return out;
|
|
204
314
|
}
|
|
205
315
|
function escapeRegExp(text) {
|
|
206
316
|
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
207
317
|
}
|
|
318
|
+
/** One separator, once: a JSON-escaped `C:\\a` and a plain `C:\a` are the same path (RC-3 item 12). */
|
|
208
319
|
function slashNormal(text) {
|
|
209
|
-
return text.replace(
|
|
320
|
+
return text.replace(/[\\/]+/g, '/');
|
|
210
321
|
}
|
|
211
322
|
/** A number is a whole token: `2` must not be satisfied by `1234` or `2.5`. */
|
|
212
323
|
function numberAppearsIn(text, corpus) {
|
|
@@ -30,7 +30,33 @@ export interface SourceResult {
|
|
|
30
30
|
checks: GeneValidationCheck[];
|
|
31
31
|
/** Misses that OUR clipping explains. The gene may pass, but only on probation (RV-13). */
|
|
32
32
|
clipped: VerbatimToken[];
|
|
33
|
+
/**
|
|
34
|
+
* Specifics the evidence does not contain, in a draft where they are the MINORITY. The gene may
|
|
35
|
+
* pass, but only on probation: it is visible, double-weighted and revoked after it misleads twice.
|
|
36
|
+
*/
|
|
37
|
+
unverified: VerbatimToken[];
|
|
33
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* When is "the evidence does not contain it" a veto? Only when MOST of what the draft states cannot
|
|
41
|
+
* be found, or so many specifics cannot that probation is the wrong tool.
|
|
42
|
+
*
|
|
43
|
+
* WHY NOT ANY MISS. The evidence a curator sees is the reviewer's one-line quote of each call (about
|
|
44
|
+
* 300 characters against a draft three times as long), so a true specific the quote never carried
|
|
45
|
+
* looked exactly like an invented one: 12 of 15 stored candidates died on it (gene-bank-never-
|
|
46
|
+
* publishes-3, RC-3). The cost of being wrong in the lenient direction is bounded - probation is
|
|
47
|
+
* the library's own risk model - and the cost in the strict direction was an empty bank.
|
|
48
|
+
*
|
|
49
|
+
* THE KNOBS LIVE HERE, NOT IN `GENE_LIMITS`: that table is structure, and says so. Set
|
|
50
|
+
* `maxUnverifiedShare` to 0 to get the old "any miss vetoes" behaviour back.
|
|
51
|
+
*/
|
|
52
|
+
export declare const K2_POLICY: {
|
|
53
|
+
/** A veto when MORE than this share of the checkable specifics is not in the evidence. */
|
|
54
|
+
readonly maxUnverifiedShare: 0.5;
|
|
55
|
+
/** A veto when MORE than this many specifics are not in the evidence, whatever the share. */
|
|
56
|
+
readonly maxUnverifiedSpecifics: 8;
|
|
57
|
+
};
|
|
58
|
+
/** Is `missing` of `checked` specifics too many to publish on probation? One of one always is. */
|
|
59
|
+
export declare function isMostlyUnverified(missing: number, checked: number): boolean;
|
|
34
60
|
/**
|
|
35
61
|
* The CURATOR-ONLY repair line for a failing K2 (RV-17, B3): the missing tokens, verbatim, so the
|
|
36
62
|
* model can cite them or take them out of its draft in the same task.
|
|
@@ -41,6 +67,20 @@ export interface SourceResult {
|
|
|
41
67
|
* and its own evidence, and exists only in that one tool answer.
|
|
42
68
|
*/
|
|
43
69
|
export declare function repairLines(content: GeneContent, corpus: string): string[];
|
|
44
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* K2, reusable by `recheck` (10.9). Returns the K2 check and, when run, the live_check record.
|
|
72
|
+
*
|
|
73
|
+
* `recheck` calls THIS function, so the "mostly unverified" rule lives here and nowhere else: a
|
|
74
|
+
* gene published under the relaxed rule must keep passing its own recheck, or every probation gene
|
|
75
|
+
* would be marked `recheck` and then `broken` by deterministic code on its first two runs.
|
|
76
|
+
*/
|
|
45
77
|
export declare function checkSource(input: SourceInput): Promise<SourceResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Would K2 and K3 - the two checks that need no model - let this knowledge draft through? The
|
|
80
|
+
* scripted create lane asks this BEFORE it writes a candidate, because a failed validation is a
|
|
81
|
+
* verdict (the candidate is rejected and the proposal is never retried), so there is no "create it
|
|
82
|
+
* and fall back" once it exists. It calls the very functions `validateKnowledge` runs - never a
|
|
83
|
+
* second copy of either rule.
|
|
84
|
+
*/
|
|
85
|
+
export declare function passesDeterministicChecks(ctx: CandidateContext): Promise<boolean>;
|
|
46
86
|
export declare function validateKnowledge(ctx: CandidateContext, report: StaticReport): Promise<TypeResult>;
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* and its absence is recorded, never a failure. A miss that OUR OWN clipping
|
|
11
11
|
* explains does not fail the candidate: it puts it on probation (RV-13), and the
|
|
12
12
|
* missing tokens are handed to the curator as repair instructions (RV-17).
|
|
13
|
+
* A specific the evidence merely does not CONTAIN is a veto only when most of the
|
|
14
|
+
* draft's specifics are in that state (`K2_POLICY`); a minority is recorded as
|
|
15
|
+
* `KNOWLEDGE_EVIDENCE_UNVERIFIED` and the gene goes in on probation, like K4.
|
|
13
16
|
* K3 scope a temporary preference only in the task scope; a specific path or a project
|
|
14
17
|
* name cannot live in the user scope; environment-bound claims carry applicability
|
|
15
18
|
* K4 supported model: do the evidence texts support the draft? (skipped when a user said it)
|
|
@@ -123,6 +126,33 @@ async function liveCheck(ports, scope, corpus, at) {
|
|
|
123
126
|
const detail = result.status === 'passed' ? 'passed' : `failed: ${result.failed} of ${result.checked}`;
|
|
124
127
|
return { check: okCheck('live_check', at, detail), failed: result.failed };
|
|
125
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* When is "the evidence does not contain it" a veto? Only when MOST of what the draft states cannot
|
|
131
|
+
* be found, or so many specifics cannot that probation is the wrong tool.
|
|
132
|
+
*
|
|
133
|
+
* WHY NOT ANY MISS. The evidence a curator sees is the reviewer's one-line quote of each call (about
|
|
134
|
+
* 300 characters against a draft three times as long), so a true specific the quote never carried
|
|
135
|
+
* looked exactly like an invented one: 12 of 15 stored candidates died on it (gene-bank-never-
|
|
136
|
+
* publishes-3, RC-3). The cost of being wrong in the lenient direction is bounded - probation is
|
|
137
|
+
* the library's own risk model - and the cost in the strict direction was an empty bank.
|
|
138
|
+
*
|
|
139
|
+
* THE KNOBS LIVE HERE, NOT IN `GENE_LIMITS`: that table is structure, and says so. Set
|
|
140
|
+
* `maxUnverifiedShare` to 0 to get the old "any miss vetoes" behaviour back.
|
|
141
|
+
*/
|
|
142
|
+
export const K2_POLICY = {
|
|
143
|
+
/** A veto when MORE than this share of the checkable specifics is not in the evidence. */
|
|
144
|
+
maxUnverifiedShare: 0.5,
|
|
145
|
+
/** A veto when MORE than this many specifics are not in the evidence, whatever the share. */
|
|
146
|
+
maxUnverifiedSpecifics: 8,
|
|
147
|
+
};
|
|
148
|
+
/** Is `missing` of `checked` specifics too many to publish on probation? One of one always is. */
|
|
149
|
+
export function isMostlyUnverified(missing, checked) {
|
|
150
|
+
if (missing <= 0)
|
|
151
|
+
return false;
|
|
152
|
+
if (missing > K2_POLICY.maxUnverifiedSpecifics)
|
|
153
|
+
return true;
|
|
154
|
+
return missing > checked * K2_POLICY.maxUnverifiedShare;
|
|
155
|
+
}
|
|
126
156
|
/**
|
|
127
157
|
* The CURATOR-ONLY repair line for a failing K2 (RV-17, B3): the missing tokens, verbatim, so the
|
|
128
158
|
* model can cite them or take them out of its draft in the same task.
|
|
@@ -139,15 +169,22 @@ export function repairLines(content, corpus) {
|
|
|
139
169
|
const tokens = report.missing.map((t) => `${t.kind} ${t.text}`).join(', ');
|
|
140
170
|
return [`these tokens are not in the evidence: ${tokens} - quote them verbatim or remove them`];
|
|
141
171
|
}
|
|
142
|
-
function evidenceProblems(unresolved, report) {
|
|
172
|
+
function evidenceProblems(unresolved, report, vetoed) {
|
|
143
173
|
const problems = [];
|
|
144
174
|
if (unresolved > 0)
|
|
145
175
|
problems.push(`${unresolved} cited ref(s) unresolved`);
|
|
146
|
-
if (
|
|
147
|
-
problems.push(`not in evidence: ${summarizeMissing(report.missing)}`);
|
|
176
|
+
if (vetoed) {
|
|
177
|
+
problems.push(`not in evidence: ${summarizeMissing(report.missing)} (${report.missing.length} of ${report.checked} specifics)`);
|
|
178
|
+
}
|
|
148
179
|
return problems;
|
|
149
180
|
}
|
|
150
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* K2, reusable by `recheck` (10.9). Returns the K2 check and, when run, the live_check record.
|
|
183
|
+
*
|
|
184
|
+
* `recheck` calls THIS function, so the "mostly unverified" rule lives here and nowhere else: a
|
|
185
|
+
* gene published under the relaxed rule must keep passing its own recheck, or every probation gene
|
|
186
|
+
* would be marked `recheck` and then `broken` by deterministic code on its first two runs.
|
|
187
|
+
*/
|
|
151
188
|
export async function checkSource(input) {
|
|
152
189
|
const at = input.ports.now();
|
|
153
190
|
const { corpus, unresolved } = input.resolved ??
|
|
@@ -156,20 +193,28 @@ export async function checkSource(input) {
|
|
|
156
193
|
return {
|
|
157
194
|
checks: [failCheck('KNOWLEDGE_EVIDENCE_UNRESOLVED', at, 'K2 the proposal carries no evidence')],
|
|
158
195
|
clipped: [],
|
|
196
|
+
unverified: [],
|
|
159
197
|
};
|
|
160
198
|
}
|
|
161
199
|
const report = findUnsupportedTokens(draftedTexts(input.content), corpus.map((e) => e.text).join('\n'));
|
|
162
|
-
const
|
|
200
|
+
const vetoed = isMostlyUnverified(report.missing.length, report.checked);
|
|
201
|
+
const problems = evidenceProblems(unresolved, report, vetoed);
|
|
163
202
|
const live = await liveCheck(input.ports, input.scope, corpus, at);
|
|
164
203
|
if (live.failed > 0)
|
|
165
204
|
problems.push(`${live.failed} evidence item(s) no longer match the project`);
|
|
205
|
+
const unverified = problems.length === 0 ? report.missing : [];
|
|
206
|
+
const found = report.checked - unverified.length;
|
|
166
207
|
const main = problems.length > 0
|
|
167
208
|
? failCheck('KNOWLEDGE_EVIDENCE_UNRESOLVED', at, `K2 ${problems.join('; ')}`)
|
|
168
|
-
: okCheck('K2', at, `${
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
209
|
+
: okCheck('K2', at, `${found} specific(s) found in evidence`);
|
|
210
|
+
const checks = [main];
|
|
211
|
+
if (unverified.length > 0) {
|
|
212
|
+
const count = summarizeMissing(unverified);
|
|
213
|
+
checks.push(okCheck('KNOWLEDGE_EVIDENCE_UNVERIFIED', at, `K2 ${count} not in evidence (${unverified.length} of ${report.checked} specifics)`));
|
|
214
|
+
}
|
|
215
|
+
if (live.check !== undefined)
|
|
216
|
+
checks.push(live.check);
|
|
217
|
+
return { checks, clipped: report.clipped, unverified };
|
|
173
218
|
}
|
|
174
219
|
// ---------------------------------------------------------------------------
|
|
175
220
|
// K3 - scope fit
|
|
@@ -225,6 +270,24 @@ function checkScope(ctx, at) {
|
|
|
225
270
|
out.push(failCheck('KNOWLEDGE_SCOPE_MISFIT', at, `K3 ${problems.join('; ')}`));
|
|
226
271
|
return out.length > 0 ? out : [okCheck('K3', at)];
|
|
227
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Would K2 and K3 - the two checks that need no model - let this knowledge draft through? The
|
|
275
|
+
* scripted create lane asks this BEFORE it writes a candidate, because a failed validation is a
|
|
276
|
+
* verdict (the candidate is rejected and the proposal is never retried), so there is no "create it
|
|
277
|
+
* and fall back" once it exists. It calls the very functions `validateKnowledge` runs - never a
|
|
278
|
+
* second copy of either rule.
|
|
279
|
+
*/
|
|
280
|
+
export async function passesDeterministicChecks(ctx) {
|
|
281
|
+
const at = ctx.ports.now();
|
|
282
|
+
const source = await checkSource({
|
|
283
|
+
ports: ctx.ports,
|
|
284
|
+
scope: ctx.scope,
|
|
285
|
+
content: ctx.content,
|
|
286
|
+
evidence: ctx.evidence,
|
|
287
|
+
...(ctx.geneId === undefined ? {} : { geneId: ctx.geneId }),
|
|
288
|
+
});
|
|
289
|
+
return source.checks.every((c) => c.ok) && checkScope(ctx, at).every((c) => c.ok);
|
|
290
|
+
}
|
|
228
291
|
async function checkSupported(ctx, corpus, usage) {
|
|
229
292
|
const at = ctx.ports.now();
|
|
230
293
|
if (corpus.some((e) => e.kind === 'user_statement' && e.trust !== 'untrusted')) {
|
|
@@ -288,7 +351,7 @@ export async function validateKnowledge(ctx, report) {
|
|
|
288
351
|
const trust = trustCheck(ctx.evidence, at);
|
|
289
352
|
checks.push(trust.check);
|
|
290
353
|
const needsHuman = trust.needsHuman ?? (conflict.decision.action === 'needs_human' ? conflict.decision.reason : undefined);
|
|
291
|
-
const probation = source.clipped.length > 0 || support.forceProbation;
|
|
354
|
+
const probation = source.clipped.length > 0 || source.unverified.length > 0 || support.forceProbation;
|
|
292
355
|
return {
|
|
293
356
|
checks,
|
|
294
357
|
conflict: conflict.decision,
|
|
@@ -12,9 +12,17 @@ export type ModelAnswer = {
|
|
|
12
12
|
in: number;
|
|
13
13
|
out: number;
|
|
14
14
|
};
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Why there is no answer: `no_model` (no port), `no_answer` (the port returned null - no key, or a
|
|
18
|
+
* reply that was not JSON, which the port contract folds into null) or `threw` (the call itself
|
|
19
|
+
* failed). The last two were both `unavailable`, so a validator whose call failed looked the same
|
|
20
|
+
* as one the port declined to run (gene-bank-never-publishes-3, R-6'). Telling `bad_json` apart
|
|
21
|
+
* from `no_key` needs the port contract widened; that is deferred, and K4 is not a veto any more.
|
|
22
|
+
*/
|
|
23
|
+
| {
|
|
16
24
|
ok: false;
|
|
17
|
-
reason: 'no_model' | '
|
|
25
|
+
reason: 'no_model' | 'no_answer' | 'threw';
|
|
18
26
|
};
|
|
19
27
|
/** Ask the validator model; absent port, a null answer or a thrown call all mean "skipped". */
|
|
20
28
|
export declare function askModel(ports: ValidatorPorts, system: string, user: string): Promise<ModelAnswer>;
|
|
@@ -25,7 +25,7 @@ export async function askModel(ports, system, user) {
|
|
|
25
25
|
try {
|
|
26
26
|
const answer = await ports.modelJson({ system, user, ...MODEL_CALL });
|
|
27
27
|
if (answer === null)
|
|
28
|
-
return { ok: false, reason: '
|
|
28
|
+
return { ok: false, reason: 'no_answer' };
|
|
29
29
|
const done = { ok: true, json: answer.json, durationMs: Math.max(0, ports.now() - started) };
|
|
30
30
|
if (answer.model !== undefined)
|
|
31
31
|
done.model = answer.model;
|
|
@@ -34,7 +34,7 @@ export async function askModel(ports, system, user) {
|
|
|
34
34
|
return done;
|
|
35
35
|
}
|
|
36
36
|
catch {
|
|
37
|
-
return { ok: false, reason: '
|
|
37
|
+
return { ok: false, reason: 'threw' };
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
const SYSTEM_BASE = [
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GeneContent, GeneProposal, GeneType } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
export interface DraftVerdict {
|
|
3
|
+
creatable: boolean;
|
|
4
|
+
/** Field paths that block creation, at most `MAX_PATHS`, no `[n]` indexes, no text. */
|
|
5
|
+
paths: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function isDraftGuardEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
8
|
+
/** The content the curator would assemble from this proposal's draft. */
|
|
9
|
+
export declare function contentOfDraft(proposal: GeneProposal, type: GeneType, now: number): GeneContent;
|
|
10
|
+
/**
|
|
11
|
+
* Is `proposal` a create whose draft the static contract accepts? Anything that is not a reviewer's
|
|
12
|
+
* `create` (a revise, a merge, an import, a maintenance proposal) is `creatable` here: the guard
|
|
13
|
+
* speaks only about the one shape that failed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkDraftCreatable(proposal: GeneProposal, knownSecrets: readonly string[], now: number): DraftVerdict;
|
|
16
|
+
/** The run-log / queue detail for a refused draft: `draft_not_creatable:<path,path>`. */
|
|
17
|
+
export declare function draftRefusalDetail(verdict: DraftVerdict): string;
|