@aragon-agent/cli 0.6.63 → 0.6.66
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 +131 -2
- package/README.md +98 -21
- package/dist/agent/controller.d.ts +119 -14
- package/dist/agent/controller.js +385 -82
- package/dist/agent/headless.d.ts +16 -0
- package/dist/agent/headless.js +68 -6
- package/dist/agent/reconnect-memory.d.ts +68 -0
- package/dist/agent/reconnect-memory.js +82 -0
- package/dist/agent/team-notices.d.ts +57 -7
- package/dist/agent/team-notices.js +93 -10
- package/dist/app/App.js +284 -78
- package/dist/cli.js +4 -1
- package/dist/commands/builtins.js +8 -72
- package/dist/commands/catalog.js +1 -1
- package/dist/commands/retry-command.d.ts +52 -0
- package/dist/commands/retry-command.js +225 -0
- package/dist/config/cli-commands.d.ts +1 -1
- package/dist/config/cli-commands.js +39 -0
- package/dist/exec/events.d.ts +12 -0
- package/dist/exec/index.js +2 -0
- package/dist/exec/runner.js +16 -1
- package/dist/gene/cli-commands.js +30 -1
- package/dist/gene/command-report.js +5 -1
- package/dist/gene/commit-prepare.js +27 -1
- package/dist/gene/curator/budget.d.ts +24 -1
- package/dist/gene/curator/budget.js +67 -14
- package/dist/gene/curator/curator.d.ts +25 -0
- package/dist/gene/curator/curator.js +61 -7
- 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 +29 -0
- package/dist/gene/curator/task-context.js +43 -0
- package/dist/gene/curator/task-runner.d.ts +10 -1
- package/dist/gene/curator/task-runner.js +52 -6
- 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/hub.js +5 -0
- package/dist/gene/import-plan.js +8 -5
- 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 +27 -5
- package/dist/gene/queue.d.ts +24 -0
- package/dist/gene/queue.js +80 -1
- package/dist/governance/store/run-store.d.ts +20 -0
- package/dist/governance/store/run-store.js +54 -8
- package/dist/host/controller-factory.js +6 -0
- 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 +35 -1
- package/dist/logging/install.js +23 -0
- package/dist/session/persist.js +8 -1
- package/dist/session/validate-session.js +15 -5
- 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
|
@@ -18,8 +18,10 @@
|
|
|
18
18
|
*
|
|
19
19
|
* A TASK THAT ENDS WITHOUT `gene_finish` IS A RETRY (10.3). A task that ran out of tokens or turns
|
|
20
20
|
* is a retry too, and counts as an attempt so a proposal that always overruns reaches `dead/`
|
|
21
|
-
* instead of looping; a
|
|
22
|
-
* circuit breaker counts. A
|
|
21
|
+
* instead of looping; a model error, or a deadline that found the task doing nothing, is an
|
|
22
|
+
* INFRASTRUCTURE failure and is what the circuit breaker counts. A deadline that cut off a task that
|
|
23
|
+
* was working is the task's own overrun (`task_wallclock`), not a sick provider. A daily-budget stop
|
|
24
|
+
* exists only while the budget is enforced (`budget.ts`); it is not the item's fault and costs no attempt.
|
|
23
25
|
*/
|
|
24
26
|
import { mintEvidenceRef } from '@aragon-agent/tui/model/gene/ids';
|
|
25
27
|
import { redactSecrets } from '../secrets.js';
|
|
@@ -27,7 +29,8 @@ import { assembleCuratorAgent, runCuratorAgent } from './agent.js';
|
|
|
27
29
|
import { planTask } from './deterministic.js';
|
|
28
30
|
import { executeDirect } from './executors.js';
|
|
29
31
|
import { buildTaskPrompt, CURATOR_SYSTEM_PROMPT } from './prompt.js';
|
|
30
|
-
import {
|
|
32
|
+
import { isScriptedLaneEnabled, isScriptedShape, writeScriptedCandidate } from './scripted-lane.js';
|
|
33
|
+
import { createTaskContext, describeTaskStats, madeProgress, } from './task-context.js';
|
|
31
34
|
import { createCuratorToolkit } from './tools.js';
|
|
32
35
|
import { settleLeftovers } from './tools-release.js';
|
|
33
36
|
// ---------------------------------------------------------------------------
|
|
@@ -165,15 +168,25 @@ async function finishedOutcome(deps, env, finish) {
|
|
|
165
168
|
// ---------------------------------------------------------------------------
|
|
166
169
|
async function modelOutcome(deps, env, summary) {
|
|
167
170
|
const { ctx } = env;
|
|
171
|
+
ctx.stats.turns = summary.turns;
|
|
168
172
|
if (ctx.abandoned !== null)
|
|
169
173
|
return abandonOutcome(deps, ctx.proposal, ctx.abandoned);
|
|
170
174
|
if (summary.stop === 'aborted')
|
|
171
175
|
return { kind: 'release', reason: 'released' };
|
|
176
|
+
if (summary.stop === 'timeout' && madeProgress(ctx.stats)) {
|
|
177
|
+
// Without the per-task token valve a working task can outlast the wall clock. That is the task
|
|
178
|
+
// outgrowing its ceiling, like `task_tokens` did, not the provider failing: it must not trip the
|
|
179
|
+
// breaker (three of these would stop the curator for 30 minutes) and it gets the overrun retry limit.
|
|
180
|
+
deps.breaker.recordSuccess();
|
|
181
|
+
await settleLeftovers(env, 'reject_failed');
|
|
182
|
+
const stats = describeTaskStats(ctx.stats);
|
|
183
|
+
return { kind: 'fail', failure: { kind: 'transient', error: 'task_wallclock' }, infra: false, stats };
|
|
184
|
+
}
|
|
172
185
|
if (summary.stop === 'error' || summary.stop === 'timeout') {
|
|
173
186
|
const error = summary.stop === 'timeout' ? 'task_timeout' : (summary.error?.errorType ?? 'model_error');
|
|
174
187
|
deps.breaker.recordInfraFailure(error);
|
|
175
188
|
await settleLeftovers(env, 'reject_failed');
|
|
176
|
-
return { kind: 'fail', failure: { kind: 'transient', error }, infra: true };
|
|
189
|
+
return { kind: 'fail', failure: { kind: 'transient', error }, infra: true, stats: describeTaskStats(ctx.stats) };
|
|
177
190
|
}
|
|
178
191
|
deps.breaker.recordSuccess();
|
|
179
192
|
if (ctx.finish !== null)
|
|
@@ -183,7 +196,7 @@ async function modelOutcome(deps, env, summary) {
|
|
|
183
196
|
// `task_tokens` means raise `gene.curatorTaskTokens`, `task_turns` means the task is doing too
|
|
184
197
|
// many small steps (RC-6). One `task_budget` name used to hide that from the run log.
|
|
185
198
|
const error = summary.stop === 'tokens' ? 'task_tokens' : summary.stop === 'turns' ? 'task_turns' : 'no_finish';
|
|
186
|
-
return { kind: 'fail', failure: { kind: 'transient', error }, infra: false };
|
|
199
|
+
return { kind: 'fail', failure: { kind: 'transient', error }, infra: false, stats: describeTaskStats(ctx.stats) };
|
|
187
200
|
}
|
|
188
201
|
async function runModelTask(deps, claimed, plan, signal) {
|
|
189
202
|
const proposal = claimed.item.proposal;
|
|
@@ -227,6 +240,39 @@ async function runModelTask(deps, claimed, plan, signal) {
|
|
|
227
240
|
}
|
|
228
241
|
}
|
|
229
242
|
// ---------------------------------------------------------------------------
|
|
243
|
+
// The scripted create lane (F2)
|
|
244
|
+
// ---------------------------------------------------------------------------
|
|
245
|
+
/**
|
|
246
|
+
* A reviewer's complete knowledge draft that K1-K3 would accept is written and validated by code,
|
|
247
|
+
* with no agent (`scripted-lane.ts` has the why). `null` hands the proposal to the agent loop
|
|
248
|
+
* untouched; the decision to decline is always made BEFORE a candidate exists.
|
|
249
|
+
*/
|
|
250
|
+
async function runScriptedLane(deps, claimed, plan) {
|
|
251
|
+
const proposal = claimed.item.proposal;
|
|
252
|
+
if (!isScriptedLaneEnabled() || !isScriptedShape(proposal) || deps.scriptedLaneAvailable?.() === false)
|
|
253
|
+
return null;
|
|
254
|
+
const config = await deps.toolDeps.switches.effective();
|
|
255
|
+
// An exhausted budget (only possible while it is enforced, or when `dailyTokens` is 0) is the agent
|
|
256
|
+
// path's to report - a `budget` failure that waits for the reset - not the lane's to ignore.
|
|
257
|
+
if ((await deps.budget.daily(config)).exhausted)
|
|
258
|
+
return null;
|
|
259
|
+
const ctx = newContext(deps, claimed, { basis: plan.basis, rebased: plan.rebased });
|
|
260
|
+
const env = { ctx, deps: deps.toolDeps };
|
|
261
|
+
try {
|
|
262
|
+
const written = await writeScriptedCandidate(env);
|
|
263
|
+
if (written === 'abandoned')
|
|
264
|
+
return ctx.abandoned === null ? null : await abandonOutcome(deps, proposal, ctx.abandoned);
|
|
265
|
+
if (written === null)
|
|
266
|
+
return null;
|
|
267
|
+
await deps.toolDeps.events.emit('distilling', { ...scopeFields(proposal), type: 'knowledge', detail: 'scripted' });
|
|
268
|
+
const result = await executeDirect({ env, queue: deps.queue, random: deps.random, capPerType: config.capPerType }, { kind: 'resume_validation', candidate: written });
|
|
269
|
+
return await directOutcome(deps, proposal, result);
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
ctx.active = false;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// ---------------------------------------------------------------------------
|
|
230
276
|
// Entry point
|
|
231
277
|
// ---------------------------------------------------------------------------
|
|
232
278
|
/** Decide one claimed item. Never throws; the host turns an unexpected failure into a retry. */
|
|
@@ -246,7 +292,7 @@ export async function runClaimedTask(deps, claimed, signal) {
|
|
|
246
292
|
if (plan.mode === 'release')
|
|
247
293
|
return { kind: 'release', reason: plan.reason };
|
|
248
294
|
if (plan.mode === 'model')
|
|
249
|
-
return runModelTask(deps, claimed, plan, signal);
|
|
295
|
+
return (await runScriptedLane(deps, claimed, plan)) ?? runModelTask(deps, claimed, plan, signal);
|
|
250
296
|
const ctx = newContext(deps, claimed, { basis: new Map(), rebased: false });
|
|
251
297
|
const env = { ctx, deps: deps.toolDeps };
|
|
252
298
|
const config = await switches.effective();
|
|
@@ -23,7 +23,7 @@ import { GENE_LIMITS } from '@aragon-agent/tui/model/gene/limits';
|
|
|
23
23
|
import { normalizeApplicability, } from '@aragon-agent/tui/model/gene/validate';
|
|
24
24
|
import { GeneStoreError } from '../gene-errors.js';
|
|
25
25
|
import { geneLooksLikeSecret } from '../secrets.js';
|
|
26
|
-
import { assertCuratorContext } from './task-context.js';
|
|
26
|
+
import { assertCuratorContext, noteToolCall } from './task-context.js';
|
|
27
27
|
import { syncSkillDeps } from './validate/skill.js';
|
|
28
28
|
export const CURATOR_ACTOR = { kind: 'curator', label: 'gene-curator' };
|
|
29
29
|
export function paramsOf(raw) {
|
|
@@ -54,7 +54,11 @@ export function refuse(tool, code, message) {
|
|
|
54
54
|
}
|
|
55
55
|
export function failureResult(tool, failure) {
|
|
56
56
|
const code = failure.detail === undefined ? failure.code : `${failure.code}:${failure.detail}`;
|
|
57
|
-
|
|
57
|
+
const copy = describeGeneError(failure.code, failure.detail);
|
|
58
|
+
// Only a content refusal carries its own explanation: `issuesToFailure` builds it from the
|
|
59
|
+
// validators' closed vocabulary. Every other code's `message` is unaudited prose, so it stays out.
|
|
60
|
+
const fix = failure.code === 'GENE_INVALID_CONTENT' && failure.message.length > 0 ? ` To fix: ${failure.message}` : '';
|
|
61
|
+
return refuse(tool, code, `${copy}${fix}`);
|
|
58
62
|
}
|
|
59
63
|
/** A refusal that ends the task is recorded on the context; the answer still reaches the model. */
|
|
60
64
|
export function applyFailureEffects(ctx, failure) {
|
|
@@ -120,13 +124,16 @@ export function defineCuratorTool(env, spec) {
|
|
|
120
124
|
const denied = assertCuratorContext(env.ctx);
|
|
121
125
|
if (denied !== null)
|
|
122
126
|
return denied;
|
|
127
|
+
let result;
|
|
123
128
|
try {
|
|
124
|
-
|
|
129
|
+
result = await spec.run(paramsOf(raw), callId);
|
|
125
130
|
}
|
|
126
131
|
catch (error) {
|
|
127
132
|
const detail = error instanceof GeneStoreError ? error.code : 'GENE_UNAVAILABLE';
|
|
128
|
-
|
|
133
|
+
result = refuse(spec.name, detail, 'The library could not complete that. Try once more or finish retry.');
|
|
129
134
|
}
|
|
135
|
+
noteToolCall(env.ctx, spec.name, result);
|
|
136
|
+
return result;
|
|
130
137
|
},
|
|
131
138
|
});
|
|
132
139
|
}
|
|
@@ -27,7 +27,20 @@ export declare const ALWAYS_VISIBLE: readonly string[];
|
|
|
27
27
|
export interface ToolGroupSpec {
|
|
28
28
|
tools: readonly string[];
|
|
29
29
|
summary: string;
|
|
30
|
+
/**
|
|
31
|
+
* Said ONCE, in the receipt of `gene_toolkit load <group>`. Never in the system prompt (that is
|
|
32
|
+
* re-sent on every one of the loop's turns) and never in `summary` (400 characters, read by
|
|
33
|
+
* `list`). It is where a contract too long for a tool description belongs.
|
|
34
|
+
*/
|
|
35
|
+
guide?: string;
|
|
30
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* What a draft must carry, by type (gene-bank-never-publishes-3, R-2). The validators refuse a draft
|
|
39
|
+
* that lacks any of it, and 17 of 17 skill drafts the reviewer wrote lacked all of it: the model had
|
|
40
|
+
* only the six section NAMES (prompt.ts) and a payload described as "kind, claims, exec, requires or
|
|
41
|
+
* preference". ASCII, and every enum is the validator's own (`validate-payload.ts`).
|
|
42
|
+
*/
|
|
43
|
+
export declare const AUTHOR_GUIDE: string;
|
|
31
44
|
export declare const TOOL_GROUPS: Readonly<Record<ToolGroupName, ToolGroupSpec>>;
|
|
32
45
|
export declare const GROUP_SUMMARY_MAX = 400;
|
|
33
46
|
export declare class CuratorToolkit implements ToolkitBinding {
|
|
@@ -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>;
|