@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.
Files changed (319) hide show
  1. package/CHANGELOG.md +2935 -2864
  2. package/README.md +160 -45
  3. package/dist/agent/controller.d.ts +47 -0
  4. package/dist/agent/controller.js +153 -2
  5. package/dist/agent/governance-wiring.js +8 -1
  6. package/dist/agent/system-prompt.d.ts +26 -0
  7. package/dist/agent/system-prompt.js +11 -0
  8. package/dist/app/App.js +101 -3
  9. package/dist/cli.js +29 -1
  10. package/dist/commands/builtins.js +4 -0
  11. package/dist/commands/catalog.js +1 -0
  12. package/dist/commands/registry.d.ts +8 -0
  13. package/dist/config/app-paths.d.ts +10 -0
  14. package/dist/config/app-paths.js +12 -0
  15. package/dist/config/cli-commands.d.ts +29 -0
  16. package/dist/config/cli-commands.js +76 -1
  17. package/dist/config/env.d.ts +2 -1
  18. package/dist/config/env.js +12 -1
  19. package/dist/config/load.d.ts +10 -0
  20. package/dist/config/load.js +13 -2
  21. package/dist/config/store.js +11 -1
  22. package/dist/exec/bridge/server.d.ts +7 -0
  23. package/dist/exec/bridge/server.js +6 -2
  24. package/dist/exec/cli-commands.js +4 -0
  25. package/dist/exec/index.js +2 -0
  26. package/dist/exec/options.d.ts +11 -0
  27. package/dist/exec/options.js +21 -1
  28. package/dist/gene/block.d.ts +33 -0
  29. package/dist/gene/block.js +51 -0
  30. package/dist/gene/capacity.d.ts +74 -0
  31. package/dist/gene/capacity.js +169 -0
  32. package/dist/gene/catalog-reconcile.d.ts +13 -0
  33. package/dist/gene/catalog-reconcile.js +105 -0
  34. package/dist/gene/catalog-stats.d.ts +27 -0
  35. package/dist/gene/catalog-stats.js +89 -0
  36. package/dist/gene/catalog-sync.d.ts +82 -0
  37. package/dist/gene/catalog-sync.js +324 -0
  38. package/dist/gene/catalog.d.ts +160 -0
  39. package/dist/gene/catalog.js +433 -0
  40. package/dist/gene/cli-commands.d.ts +50 -0
  41. package/dist/gene/cli-commands.js +500 -0
  42. package/dist/gene/command-report.d.ts +40 -0
  43. package/dist/gene/command-report.js +246 -0
  44. package/dist/gene/command.d.ts +29 -0
  45. package/dist/gene/command.js +561 -0
  46. package/dist/gene/commit-apply-types.d.ts +13 -0
  47. package/dist/gene/commit-apply-types.js +1 -0
  48. package/dist/gene/commit-compound.d.ts +34 -0
  49. package/dist/gene/commit-compound.js +212 -0
  50. package/dist/gene/commit-counts.d.ts +41 -0
  51. package/dist/gene/commit-counts.js +70 -0
  52. package/dist/gene/commit-exec.d.ts +42 -0
  53. package/dist/gene/commit-exec.js +134 -0
  54. package/dist/gene/commit-head.d.ts +52 -0
  55. package/dist/gene/commit-head.js +97 -0
  56. package/dist/gene/commit-plan.d.ts +95 -0
  57. package/dist/gene/commit-plan.js +68 -0
  58. package/dist/gene/commit-prepare.d.ts +63 -0
  59. package/dist/gene/commit-prepare.js +159 -0
  60. package/dist/gene/commit-types.d.ts +234 -0
  61. package/dist/gene/commit-types.js +3 -0
  62. package/dist/gene/curator/agent.d.ts +137 -0
  63. package/dist/gene/curator/agent.js +203 -0
  64. package/dist/gene/curator/budget.d.ts +69 -0
  65. package/dist/gene/curator/budget.js +131 -0
  66. package/dist/gene/curator/conflicts.d.ts +54 -0
  67. package/dist/gene/curator/conflicts.js +143 -0
  68. package/dist/gene/curator/curator.d.ts +170 -0
  69. package/dist/gene/curator/curator.js +617 -0
  70. package/dist/gene/curator/deps.d.ts +34 -0
  71. package/dist/gene/curator/deps.js +48 -0
  72. package/dist/gene/curator/deterministic.d.ts +62 -0
  73. package/dist/gene/curator/deterministic.js +287 -0
  74. package/dist/gene/curator/executors.d.ts +36 -0
  75. package/dist/gene/curator/executors.js +379 -0
  76. package/dist/gene/curator/lanes.d.ts +52 -0
  77. package/dist/gene/curator/lanes.js +99 -0
  78. package/dist/gene/curator/lease.d.ts +76 -0
  79. package/dist/gene/curator/lease.js +171 -0
  80. package/dist/gene/curator/library.d.ts +36 -0
  81. package/dist/gene/curator/library.js +169 -0
  82. package/dist/gene/curator/lifecycle.d.ts +52 -0
  83. package/dist/gene/curator/lifecycle.js +109 -0
  84. package/dist/gene/curator/maintenance.d.ts +71 -0
  85. package/dist/gene/curator/maintenance.js +213 -0
  86. package/dist/gene/curator/probation.d.ts +51 -0
  87. package/dist/gene/curator/probation.js +71 -0
  88. package/dist/gene/curator/probe.d.ts +131 -0
  89. package/dist/gene/curator/probe.js +534 -0
  90. package/dist/gene/curator/prompt.d.ts +18 -0
  91. package/dist/gene/curator/prompt.js +128 -0
  92. package/dist/gene/curator/publish.d.ts +64 -0
  93. package/dist/gene/curator/publish.js +113 -0
  94. package/dist/gene/curator/recheck.d.ts +55 -0
  95. package/dist/gene/curator/recheck.js +104 -0
  96. package/dist/gene/curator/run-events.d.ts +63 -0
  97. package/dist/gene/curator/run-events.js +55 -0
  98. package/dist/gene/curator/similarity.d.ts +13 -0
  99. package/dist/gene/curator/similarity.js +46 -0
  100. package/dist/gene/curator/switches.d.ts +78 -0
  101. package/dist/gene/curator/switches.js +146 -0
  102. package/dist/gene/curator/task-context.d.ts +93 -0
  103. package/dist/gene/curator/task-context.js +63 -0
  104. package/dist/gene/curator/task-runner.d.ts +56 -0
  105. package/dist/gene/curator/task-runner.js +257 -0
  106. package/dist/gene/curator/tool-support.d.ts +112 -0
  107. package/dist/gene/curator/tool-support.js +206 -0
  108. package/dist/gene/curator/toolkit.d.ts +49 -0
  109. package/dist/gene/curator/toolkit.js +104 -0
  110. package/dist/gene/curator/tools-read.d.ts +4 -0
  111. package/dist/gene/curator/tools-read.js +177 -0
  112. package/dist/gene/curator/tools-release.d.ts +73 -0
  113. package/dist/gene/curator/tools-release.js +287 -0
  114. package/dist/gene/curator/tools-verify.d.ts +47 -0
  115. package/dist/gene/curator/tools-verify.js +243 -0
  116. package/dist/gene/curator/tools-write.d.ts +26 -0
  117. package/dist/gene/curator/tools-write.js +434 -0
  118. package/dist/gene/curator/tools.d.ts +23 -0
  119. package/dist/gene/curator/tools.js +21 -0
  120. package/dist/gene/curator/validate/common.d.ts +87 -0
  121. package/dist/gene/curator/validate/common.js +132 -0
  122. package/dist/gene/curator/validate/evidence-tokens.d.ts +24 -0
  123. package/dist/gene/curator/validate/evidence-tokens.js +217 -0
  124. package/dist/gene/curator/validate/index.d.ts +23 -0
  125. package/dist/gene/curator/validate/index.js +62 -0
  126. package/dist/gene/curator/validate/knowledge.d.ts +41 -0
  127. package/dist/gene/curator/validate/knowledge.js +255 -0
  128. package/dist/gene/curator/validate/live-check.d.ts +14 -0
  129. package/dist/gene/curator/validate/live-check.js +150 -0
  130. package/dist/gene/curator/validate/ports.d.ts +67 -0
  131. package/dist/gene/curator/validate/ports.js +1 -0
  132. package/dist/gene/curator/validate/prompts.d.ts +41 -0
  133. package/dist/gene/curator/validate/prompts.js +165 -0
  134. package/dist/gene/curator/validate/skill.d.ts +15 -0
  135. package/dist/gene/curator/validate/skill.js +251 -0
  136. package/dist/gene/curator/validate/tool.d.ts +6 -0
  137. package/dist/gene/curator/validate/tool.js +217 -0
  138. package/dist/gene/curator/validate/types.d.ts +90 -0
  139. package/dist/gene/curator/validate/types.js +1 -0
  140. package/dist/gene/curator/validator-ports.d.ts +38 -0
  141. package/dist/gene/curator/validator-ports.js +29 -0
  142. package/dist/gene/diag.d.ts +209 -0
  143. package/dist/gene/diag.js +549 -0
  144. package/dist/gene/env.d.ts +10 -0
  145. package/dist/gene/env.js +214 -0
  146. package/dist/gene/eval-recorder.d.ts +84 -0
  147. package/dist/gene/eval-recorder.js +222 -0
  148. package/dist/gene/explain-transport.d.ts +3 -0
  149. package/dist/gene/explain-transport.js +39 -0
  150. package/dist/gene/explain.d.ts +96 -0
  151. package/dist/gene/explain.js +293 -0
  152. package/dist/gene/fs.d.ts +39 -0
  153. package/dist/gene/fs.js +139 -0
  154. package/dist/gene/fsck.d.ts +68 -0
  155. package/dist/gene/fsck.js +134 -0
  156. package/dist/gene/gc-library-sweeps.d.ts +9 -0
  157. package/dist/gene/gc-library-sweeps.js +220 -0
  158. package/dist/gene/gc-rejected-set.d.ts +15 -0
  159. package/dist/gene/gc-rejected-set.js +63 -0
  160. package/dist/gene/gc-safe.d.ts +12 -0
  161. package/dist/gene/gc-safe.js +74 -0
  162. package/dist/gene/gc-scope-sweeps.d.ts +18 -0
  163. package/dist/gene/gc-scope-sweeps.js +297 -0
  164. package/dist/gene/gc-types.d.ts +55 -0
  165. package/dist/gene/gc-types.js +26 -0
  166. package/dist/gene/gc.d.ts +42 -0
  167. package/dist/gene/gc.js +129 -0
  168. package/dist/gene/gene-errors.d.ts +23 -0
  169. package/dist/gene/gene-errors.js +29 -0
  170. package/dist/gene/hints.d.ts +91 -0
  171. package/dist/gene/hints.js +394 -0
  172. package/dist/gene/hub.d.ts +149 -0
  173. package/dist/gene/hub.js +371 -0
  174. package/dist/gene/import-plan.d.ts +80 -0
  175. package/dist/gene/import-plan.js +294 -0
  176. package/dist/gene/import-proposal.d.ts +23 -0
  177. package/dist/gene/import-proposal.js +101 -0
  178. package/dist/gene/import-skill-port.d.ts +6 -0
  179. package/dist/gene/import-skill-port.js +53 -0
  180. package/dist/gene/import-sources.d.ts +48 -0
  181. package/dist/gene/import-sources.js +140 -0
  182. package/dist/gene/index-writer.d.ts +36 -0
  183. package/dist/gene/index-writer.js +101 -0
  184. package/dist/gene/learn/learn-call.d.ts +116 -0
  185. package/dist/gene/learn/learn-call.js +165 -0
  186. package/dist/gene/learn/learn-prompt.d.ts +58 -0
  187. package/dist/gene/learn/learn-prompt.js +254 -0
  188. package/dist/gene/learn/learner.d.ts +187 -0
  189. package/dist/gene/learn/learner.js +448 -0
  190. package/dist/gene/learn/ledger.d.ts +220 -0
  191. package/dist/gene/learn/ledger.js +394 -0
  192. package/dist/gene/learn/proposal-build.d.ts +83 -0
  193. package/dist/gene/learn/proposal-build.js +207 -0
  194. package/dist/gene/learn/proposal-guard.d.ts +43 -0
  195. package/dist/gene/learn/proposal-guard.js +37 -0
  196. package/dist/gene/learn/signals-port.d.ts +47 -0
  197. package/dist/gene/learn/signals-port.js +86 -0
  198. package/dist/gene/maintenance-paths.d.ts +7 -0
  199. package/dist/gene/maintenance-paths.js +20 -0
  200. package/dist/gene/maintenance-probation.d.ts +33 -0
  201. package/dist/gene/maintenance-probation.js +127 -0
  202. package/dist/gene/maintenance-proposals.d.ts +24 -0
  203. package/dist/gene/maintenance-proposals.js +68 -0
  204. package/dist/gene/maintenance-runner.d.ts +92 -0
  205. package/dist/gene/maintenance-runner.js +262 -0
  206. package/dist/gene/maintenance-tasks.d.ts +37 -0
  207. package/dist/gene/maintenance-tasks.js +95 -0
  208. package/dist/gene/manager-actions.d.ts +12 -0
  209. package/dist/gene/manager-actions.js +279 -0
  210. package/dist/gene/manager-approve.d.ts +29 -0
  211. package/dist/gene/manager-approve.js +84 -0
  212. package/dist/gene/manager-context.d.ts +90 -0
  213. package/dist/gene/manager-context.js +201 -0
  214. package/dist/gene/manager-detail.d.ts +17 -0
  215. package/dist/gene/manager-detail.js +313 -0
  216. package/dist/gene/manager-gc.d.ts +13 -0
  217. package/dist/gene/manager-gc.js +81 -0
  218. package/dist/gene/manager-library.d.ts +39 -0
  219. package/dist/gene/manager-library.js +90 -0
  220. package/dist/gene/manager-list.d.ts +27 -0
  221. package/dist/gene/manager-list.js +170 -0
  222. package/dist/gene/manager-queue.d.ts +16 -0
  223. package/dist/gene/manager-queue.js +124 -0
  224. package/dist/gene/manager-stats.d.ts +28 -0
  225. package/dist/gene/manager-stats.js +53 -0
  226. package/dist/gene/manager-view.d.ts +27 -0
  227. package/dist/gene/manager-view.js +124 -0
  228. package/dist/gene/manager.d.ts +56 -0
  229. package/dist/gene/manager.js +179 -0
  230. package/dist/gene/orphan-scopes.d.ts +37 -0
  231. package/dist/gene/orphan-scopes.js +150 -0
  232. package/dist/gene/paths.d.ts +73 -0
  233. package/dist/gene/paths.js +239 -0
  234. package/dist/gene/plan-content.d.ts +73 -0
  235. package/dist/gene/plan-content.js +522 -0
  236. package/dist/gene/plan-lifecycle.d.ts +29 -0
  237. package/dist/gene/plan-lifecycle.js +310 -0
  238. package/dist/gene/policy.d.ts +71 -0
  239. package/dist/gene/policy.js +313 -0
  240. package/dist/gene/project-learning.d.ts +25 -0
  241. package/dist/gene/project-learning.js +54 -0
  242. package/dist/gene/propagation.d.ts +48 -0
  243. package/dist/gene/propagation.js +45 -0
  244. package/dist/gene/queue-lock.d.ts +22 -0
  245. package/dist/gene/queue-lock.js +99 -0
  246. package/dist/gene/queue-record.d.ts +57 -0
  247. package/dist/gene/queue-record.js +145 -0
  248. package/dist/gene/queue.d.ts +235 -0
  249. package/dist/gene/queue.js +764 -0
  250. package/dist/gene/read.d.ts +61 -0
  251. package/dist/gene/read.js +252 -0
  252. package/dist/gene/runlog.d.ts +101 -0
  253. package/dist/gene/runlog.js +404 -0
  254. package/dist/gene/schema-lite.d.ts +24 -0
  255. package/dist/gene/schema-lite.js +159 -0
  256. package/dist/gene/scope-guard.d.ts +23 -0
  257. package/dist/gene/scope-guard.js +9 -0
  258. package/dist/gene/scope-lock.d.ts +48 -0
  259. package/dist/gene/scope-lock.js +222 -0
  260. package/dist/gene/scope-verify.d.ts +63 -0
  261. package/dist/gene/scope-verify.js +123 -0
  262. package/dist/gene/secrets.d.ts +43 -0
  263. package/dist/gene/secrets.js +161 -0
  264. package/dist/gene/service-context.d.ts +43 -0
  265. package/dist/gene/service-context.js +79 -0
  266. package/dist/gene/service-prepare.d.ts +25 -0
  267. package/dist/gene/service-prepare.js +219 -0
  268. package/dist/gene/service-types.d.ts +196 -0
  269. package/dist/gene/service-types.js +1 -0
  270. package/dist/gene/service-view.d.ts +41 -0
  271. package/dist/gene/service-view.js +69 -0
  272. package/dist/gene/service.d.ts +114 -0
  273. package/dist/gene/service.js +761 -0
  274. package/dist/gene/session-start.d.ts +36 -0
  275. package/dist/gene/session-start.js +212 -0
  276. package/dist/gene/store-port.d.ts +88 -0
  277. package/dist/gene/store-port.js +10 -0
  278. package/dist/gene/store-rows.d.ts +36 -0
  279. package/dist/gene/store-rows.js +72 -0
  280. package/dist/gene/store.d.ts +125 -0
  281. package/dist/gene/store.js +622 -0
  282. package/dist/gene/tombstones.d.ts +47 -0
  283. package/dist/gene/tombstones.js +61 -0
  284. package/dist/gene/tool-runner.d.ts +47 -0
  285. package/dist/gene/tool-runner.js +154 -0
  286. package/dist/gene/tool-screen.d.ts +41 -0
  287. package/dist/gene/tool-screen.js +227 -0
  288. package/dist/gene/tools.d.ts +112 -0
  289. package/dist/gene/tools.js +539 -0
  290. package/dist/gene/transfer.d.ts +85 -0
  291. package/dist/gene/transfer.js +433 -0
  292. package/dist/gene/ui-hints.d.ts +15 -0
  293. package/dist/gene/ui-hints.js +67 -0
  294. package/dist/gene/usage-fold-cursor.d.ts +24 -0
  295. package/dist/gene/usage-fold-cursor.js +115 -0
  296. package/dist/gene/usage-fold.d.ts +49 -0
  297. package/dist/gene/usage-fold.js +397 -0
  298. package/dist/gene/usage.d.ts +67 -0
  299. package/dist/gene/usage.js +231 -0
  300. package/dist/gene/version-service.d.ts +118 -0
  301. package/dist/gene/version-service.js +453 -0
  302. package/dist/gene/wiring-events.d.ts +43 -0
  303. package/dist/gene/wiring-events.js +113 -0
  304. package/dist/gene/wiring-models.d.ts +46 -0
  305. package/dist/gene/wiring-models.js +84 -0
  306. package/dist/gene/wiring.d.ts +200 -0
  307. package/dist/gene/wiring.js +764 -0
  308. package/dist/governance/prompts/orchestrator-block.js +3 -2
  309. package/dist/host/gene.d.ts +26 -0
  310. package/dist/host/gene.js +24 -0
  311. package/dist/host/index.d.ts +1 -0
  312. package/dist/host/index.js +1 -0
  313. package/dist/team/runtime.d.ts +5 -0
  314. package/dist/team/runtime.js +23 -0
  315. package/dist/team/subagent.d.ts +34 -0
  316. package/dist/team/subagent.js +39 -2
  317. package/dist/tools/index.d.ts +36 -2
  318. package/dist/tools/index.js +48 -7
  319. package/package.json +3 -3
@@ -0,0 +1,132 @@
1
+ import { validateGeneContent } from '@aragon-agent/tui/model/gene/validate';
2
+ import { geneLooksLikeSecret } from '../../secrets.js';
3
+ export const SKIPPED_PREFIX = 'SKIPPED_';
4
+ /** Failing codes that mean "a person must decide", not "this candidate is wrong". */
5
+ export const NEEDS_HUMAN_CODES = new Set([
6
+ 'GENE_PROBE_NEEDS_APPROVAL',
7
+ 'GENE_TOOL_HIGH_RISK',
8
+ 'KNOWLEDGE_UNTRUSTED_ONLY',
9
+ 'CONFLICT_WITH_HUMAN',
10
+ ]);
11
+ /** Failing codes that mean "do not create this; route it as a merge or a revise". */
12
+ export const CONVERT_CODES = new Set(['CONFLICT_CONVERT']);
13
+ function build(code, ok, at, detail, extras) {
14
+ const check = { code, ok, by: extras.by ?? 'code', at };
15
+ if (detail !== undefined && detail.length > 0)
16
+ check.detail = detail.slice(0, 240);
17
+ if (extras.model !== undefined)
18
+ check.model = extras.model;
19
+ if (extras.durationMs !== undefined)
20
+ check.durationMs = extras.durationMs;
21
+ return check;
22
+ }
23
+ export function okCheck(id, at, detail, extras = {}) {
24
+ return build(id, true, at, detail, extras);
25
+ }
26
+ export function failCheck(code, at, detail, extras = {}) {
27
+ return build(code, false, at, detail, extras);
28
+ }
29
+ /** A check that was not run. `ok: true` so it blocks nothing, but never mistaken for a pass. */
30
+ export function skippedCheck(id, at, reason) {
31
+ return build(`${SKIPPED_PREFIX}${id}`, true, at, `skipped: ${reason}`, {});
32
+ }
33
+ export function isSkippedCheck(check) {
34
+ return check.code.startsWith(SKIPPED_PREFIX);
35
+ }
36
+ /** Dotted field paths only - never the offending text (I-19). */
37
+ export function describeIssues(issues) {
38
+ const parts = issues.slice(0, 6).map((i) => (i.detail ? `${i.path}:${i.detail}` : i.path));
39
+ const more = issues.length > 6 ? ` (+${issues.length - 6} more)` : '';
40
+ return parts.join(', ') + more;
41
+ }
42
+ /** `class` can also arrive as a stray property of the model's JSON; treat it as a request. */
43
+ function strayClass(content) {
44
+ const raw = content.class;
45
+ return raw === 'oversight' ? 'oversight' : undefined;
46
+ }
47
+ /**
48
+ * Run `validateGeneContent` as the AGENT actor. The one place that decides what an agent may do
49
+ * with `class: 'oversight'`: editing an existing oversight gene is refused (I-12), asking for a
50
+ * NEW one is demoted to `standard` with a warning.
51
+ */
52
+ export function runStaticChecks(input) {
53
+ const editsOversight = input.targetClass === 'oversight';
54
+ const asked = input.requestedClass === 'oversight' || strayClass(input.content) === 'oversight';
55
+ const demoted = asked && !editsOversight;
56
+ const knownSecrets = input.knownSecrets ?? [];
57
+ const result = validateGeneContent(input.type, input.content, {
58
+ scope: input.scope,
59
+ actor: 'agent',
60
+ class: editsOversight ? 'oversight' : 'standard',
61
+ secretCheck: (text) => geneLooksLikeSecret(text, knownSecrets),
62
+ });
63
+ return { issues: result.issues, storedClass: editsOversight ? 'oversight' : 'standard', demoted };
64
+ }
65
+ export function splitIssues(issues, pick) {
66
+ const picked = [];
67
+ const rest = [];
68
+ for (const issue of issues)
69
+ (pick(issue) ? picked : rest).push(issue);
70
+ return { picked, rest };
71
+ }
72
+ /** The K1 check: every static issue not owned by a type-specific check. */
73
+ export function staticCheck(rest, at) {
74
+ if (rest.length === 0)
75
+ return okCheck('K1', at);
76
+ return failCheck(rest[0].code, at, `K1 ${describeIssues(rest)}`);
77
+ }
78
+ /** Warning check recorded when an agent draft asked for the human-only `oversight` class. */
79
+ export function oversightChecks(report, targetClass, at) {
80
+ const out = [];
81
+ if (report.demoted)
82
+ out.push(okCheck('OVERSIGHT_DEMOTED', at, 'draft asked for class oversight; stored as standard'));
83
+ if (targetClass === 'oversight') {
84
+ out.push(failCheck('GENE_OVERSIGHT_HUMAN_ONLY', at, 'only a person may change an oversight gene'));
85
+ }
86
+ return out;
87
+ }
88
+ // ---------------------------------------------------------------------------
89
+ // Source trust (K6, TH-1)
90
+ // ---------------------------------------------------------------------------
91
+ /**
92
+ * All evidence `untrusted` and nothing from the user or from a local measurement: the library
93
+ * is not allowed to learn from a web page alone (TH-1). No evidence at all is K2's problem.
94
+ */
95
+ export function untrustedOnly(evidence) {
96
+ if (evidence.length === 0)
97
+ return false;
98
+ return evidence.every((e) => e.trust === 'untrusted');
99
+ }
100
+ export function trustCheck(evidence, at) {
101
+ if (untrustedOnly(evidence)) {
102
+ return {
103
+ check: failCheck('KNOWLEDGE_UNTRUSTED_ONLY', at, `K6 all ${evidence.length} evidence items are untrusted`),
104
+ needsHuman: 'untrusted_origin',
105
+ };
106
+ }
107
+ return { check: okCheck('K6', at) };
108
+ }
109
+ // ---------------------------------------------------------------------------
110
+ // Folding checks into a validation and a verdict
111
+ // ---------------------------------------------------------------------------
112
+ export function validationOf(checks, at) {
113
+ return { at, ok: checks.every((c) => c.ok), checks: [...checks] };
114
+ }
115
+ /** fail > needs_human > convert > pass. */
116
+ export function verdictOf(checks) {
117
+ const failing = checks.filter((c) => !c.ok);
118
+ if (failing.length === 0)
119
+ return 'pass';
120
+ const hard = failing.some((c) => !NEEDS_HUMAN_CODES.has(c.code) && !CONVERT_CODES.has(c.code));
121
+ if (hard)
122
+ return 'fail';
123
+ if (failing.some((c) => NEEDS_HUMAN_CODES.has(c.code)))
124
+ return 'needs_human';
125
+ return 'convert';
126
+ }
127
+ export function addUsage(into, usage) {
128
+ if (usage === undefined)
129
+ return;
130
+ into.in += Math.max(0, usage.in);
131
+ into.out += Math.max(0, usage.out);
132
+ }
@@ -0,0 +1,24 @@
1
+ export type TokenKind = 'path' | 'symbol' | 'error_code' | 'number';
2
+ export interface VerbatimToken {
3
+ kind: TokenKind;
4
+ text: string;
5
+ }
6
+ /** The checkable specifics of `text`, at most 96, in order of first appearance. */
7
+ export declare function extractVerbatimTokens(text: string): VerbatimToken[];
8
+ /**
9
+ * Is `token` present verbatim in the evidence `corpus`? Both sides are entity-unescaped once: the
10
+ * model read an escaped prompt, so it quotes `&&` for a `&&` the evidence really has.
11
+ */
12
+ export declare function tokenAppearsIn(token: VerbatimToken, corpus: string): boolean;
13
+ export interface TokenReport {
14
+ /** How many tokens the drafted texts contained. */
15
+ checked: number;
16
+ /** Tokens the evidence does not contain and our clipping does not explain: a real miss. */
17
+ missing: VerbatimToken[];
18
+ /** Tokens the evidence only lacks because it was clipped here, not because they are wrong. */
19
+ clipped: VerbatimToken[];
20
+ }
21
+ /** Check every token of `drafted` against `corpus` (all evidence texts joined). */
22
+ export declare function findUnsupportedTokens(drafted: readonly string[], corpus: string): TokenReport;
23
+ /** `path x1, number x2` - kinds and counts only, never the token text (I-19). */
24
+ export declare function summarizeMissing(missing: readonly VerbatimToken[]): string;
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Verbatim-token extraction for the K2 source check (gene-bank spec 10.7.1 K2, RV-10).
3
+ *
4
+ * ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`. PURE.
5
+ *
6
+ * THE RULE THIS IMPLEMENTS. Every path, symbol, error code and number that a draft states must
7
+ * appear VERBATIM in the evidence the proposal carried. A model that "tidies" `src\\a.ts` into
8
+ * `src/a.ts` is fine (paths compare with one separator), a model that invents `src/b.ts` or
9
+ * rounds `1.7 s` to `2 s` is not. This is the deterministic backbone of K2: it needs no
10
+ * filesystem and no model, so it runs even when the evidence's project is not on this machine.
11
+ *
12
+ * WHAT IT IS NOT. It does not decide that the draft is TRUE (that is K4's supported-by-evidence
13
+ * question) and it cannot see a fact the model stated in prose without a token. It is a floor:
14
+ * the specifics that are cheap to check mechanically are checked mechanically.
15
+ *
16
+ * THREE CORRECTIONS LEARNED FROM REAL CANDIDATES (RC-3):
17
+ * 1. an evidence REF (`ev_1a2b3c4d`) is an id this system minted, never a fact, so it is not a
18
+ * token at all - the curator is TOLD to cite refs, so treating one as "must appear in the
19
+ * evidence" is a guaranteed miss (RV-8);
20
+ * 2. both sides of the comparison are entity-unescaped once, because the model was shown an
21
+ * escaped prompt and quotes what it was shown (RV-5, RV-19);
22
+ * 3. a backticked PLACEHOLDER (`python <file>`, `...`), a WILDCARD (`198.18.0.x`) or a plain
23
+ * lower-case word (`desktop`) is emphasis, not an assertion. Narrowing only these three
24
+ * enumerable shapes keeps an invented path or symbol caught (RV-13, B2c).
25
+ *
26
+ * A MISS WE CAUSED OURSELVES IS NOT THE DRAFT'S FAULT. Evidence is clipped with a trailing `...`
27
+ * on its way into the prompt, so a token that is a truncated PREFIX of what the draft says is
28
+ * reported as `clipped`, not `missing` (RV-13). `probation.ts` then keeps the gene out of harm's
29
+ * way instead of the candidate dying over our own truncation.
30
+ *
31
+ * NO FAILURE MESSAGE MAY CARRY A TOKEN (I-19). Callers report counts per kind only - except the
32
+ * curator's own tool answer, which lists them so the model can fix its draft (RV-17, B3).
33
+ */
34
+ import { unescapeGeneEntities } from '@aragon-agent/tui/model/gene/escape';
35
+ const MAX_TOKENS = 96;
36
+ const FILE_EXTENSIONS = 'ts|tsx|js|jsx|mjs|cjs|json|md|yml|yaml|toml|lock|py|rs|go|java|cs|sh|ps1|cmd|bat|txt|log|css|' +
37
+ 'html|xml|sql|ini|cfg|conf|env|exe|dll|so|zip|tgz|gz|map|svg|png|csv';
38
+ const FILE_NAME_RE = new RegExp(`^[\\w@+-]+(?:\\.[\\w@+-]+)*\\.(?:${FILE_EXTENSIONS})$`, 'i');
39
+ const URL_RE = /^https?:\/\/\S+$/i;
40
+ const NUMBER_RE = /^\d+(?:[.,]\d+)*(?:ms|s|sec|min|h|kb|mb|gb|%)?$/i;
41
+ const CAMEL_RE = /^[a-z]+(?:[A-Z][a-z0-9]*)+$/;
42
+ const SNAKE_RE = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)+$/;
43
+ const DOTTED_RE = /^[a-z_][a-z0-9_]{1,30}(?:\.[a-z_][a-z0-9_]{1,30})+$/;
44
+ const CALL_RE = /^([A-Za-z_][\w.]{1,40})\(\)?$/;
45
+ const ERRNO_RE = /^E[A-Z]{2,15}$/;
46
+ const UPPER_SNAKE_RE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/;
47
+ const COMPILER_CODE_RE = /^(?:TS|CS|CE|LNK|E|W)\d{3,5}$/;
48
+ const LIST_MARKER_RE = /^\s*(?:[-*+]|\d+[.)])\s+/;
49
+ const BACKTICK_RE = /`([^`\n]{2,80})`/g;
50
+ /** An evidence ref this system minted (`ids.ts`: `ev_` + 8 chars of [0-9a-z]). */
51
+ const EVIDENCE_REF_RE = /^ev_[0-9a-z]{8}$/;
52
+ /** `python <file>`, `<path>`, `...`: the model is naming a shape, not asserting a value. */
53
+ const PLACEHOLDER_RE = /<[^<>\n]{0,60}>|\.\.\./;
54
+ /** `198.18.0.x`, `src/*.ts`: a pattern, not a fact. */
55
+ const WILDCARD_SEGMENT_RE = /(?:^|[./\\])(?:x|\*|\?)(?=[./\\]|$)/i;
56
+ /** A single lower-case word in backticks (`desktop`) is emphasis. */
57
+ const PLAIN_WORD_RE = /^[a-z]+$/;
58
+ function trimWord(word) {
59
+ let out = word.replace(/^[("'[{<]+/, '').replace(/[)"'\]}>,;:!?]+$/, '');
60
+ // A sentence-ending dot is not part of the token; a dot inside a name is.
61
+ while (out.endsWith('.') && out.length > 1)
62
+ out = out.slice(0, -1);
63
+ return out;
64
+ }
65
+ function isNumericOnly(segments) {
66
+ return segments.every((s) => /^\d+$/.test(s));
67
+ }
68
+ /** Does a slash-bearing word look like a path rather than "and/or"? */
69
+ function looksLikePath(word) {
70
+ if (URL_RE.test(word))
71
+ return true;
72
+ if (!/[\\/]/.test(word))
73
+ return false;
74
+ const segments = word.split(/[\\/]/).filter((s) => s.length > 0);
75
+ if (segments.length === 0 || isNumericOnly(segments))
76
+ return false;
77
+ const last = segments[segments.length - 1] ?? '';
78
+ const hasExtension = /\.[A-Za-z0-9]{1,8}$/.test(last);
79
+ const anchored = /^(?:\.{1,2}[\\/]|[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(word);
80
+ const directory = /[\\/]$/.test(word);
81
+ return hasExtension || anchored || directory || segments.length >= 3;
82
+ }
83
+ /** A quoted span that asserts nothing: a placeholder, a wildcard pattern, or one plain word. */
84
+ function isEmphasisOnly(span) {
85
+ return PLACEHOLDER_RE.test(span) || WILDCARD_SEGMENT_RE.test(span) || PLAIN_WORD_RE.test(span);
86
+ }
87
+ function classify(word, quoted) {
88
+ if (EVIDENCE_REF_RE.test(word))
89
+ return null;
90
+ if (quoted && isEmphasisOnly(word))
91
+ return null;
92
+ if (looksLikePath(word) || FILE_NAME_RE.test(word))
93
+ return { kind: 'path', text: word };
94
+ if (quoted)
95
+ return { kind: 'symbol', text: word };
96
+ if (ERRNO_RE.test(word) || UPPER_SNAKE_RE.test(word) || COMPILER_CODE_RE.test(word)) {
97
+ return { kind: 'error_code', text: word };
98
+ }
99
+ if (NUMBER_RE.test(word))
100
+ return { kind: 'number', text: word };
101
+ if (CAMEL_RE.test(word) || SNAKE_RE.test(word) || DOTTED_RE.test(word) || CALL_RE.test(word)) {
102
+ return { kind: 'symbol', text: word };
103
+ }
104
+ return null;
105
+ }
106
+ function quotedSpans(line) {
107
+ const spans = [];
108
+ const rest = line.replace(BACKTICK_RE, (_whole, inner) => {
109
+ spans.push(inner.trim());
110
+ return ' ';
111
+ });
112
+ return { rest, spans };
113
+ }
114
+ function pushUnique(out, seen, token) {
115
+ if (token === null || token.text.length === 0 || out.length >= MAX_TOKENS)
116
+ return;
117
+ const key = `${token.kind}:${token.text}`;
118
+ if (seen.has(key))
119
+ return;
120
+ seen.add(key);
121
+ out.push(token);
122
+ }
123
+ /** The checkable specifics of `text`, at most 96, in order of first appearance. */
124
+ export function extractVerbatimTokens(text) {
125
+ const out = [];
126
+ const seen = new Set();
127
+ for (const rawLine of String(text ?? '').split(/\r?\n/)) {
128
+ const { rest, spans } = quotedSpans(rawLine.replace(LIST_MARKER_RE, ''));
129
+ for (const span of spans)
130
+ pushUnique(out, seen, classify(span, true));
131
+ for (const raw of rest.split(/\s+/))
132
+ pushUnique(out, seen, classify(trimWord(raw), false));
133
+ }
134
+ return out;
135
+ }
136
+ function escapeRegExp(text) {
137
+ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
138
+ }
139
+ function slashNormal(text) {
140
+ return text.replace(/\\/g, '/');
141
+ }
142
+ /** A number is a whole token: `2` must not be satisfied by `1234` or `2.5`. */
143
+ function numberAppearsIn(text, corpus) {
144
+ const re = new RegExp(`(?<![0-9A-Za-z_.,])${escapeRegExp(text)}(?![0-9A-Za-z_]|[.,]\\d)`);
145
+ return re.test(corpus);
146
+ }
147
+ /** Does `token` appear in the (already unescaped) evidence `corpus`? Paths compare with one separator. */
148
+ function appearsIn(token, corpus) {
149
+ const needle = unescapeGeneEntities(token.text);
150
+ if (token.kind === 'number')
151
+ return numberAppearsIn(needle, corpus);
152
+ if (token.kind === 'path')
153
+ return slashNormal(corpus).includes(slashNormal(needle));
154
+ return corpus.includes(needle);
155
+ }
156
+ /**
157
+ * Is `token` present verbatim in the evidence `corpus`? Both sides are entity-unescaped once: the
158
+ * model read an escaped prompt, so it quotes `&amp;&amp;` for a `&&` the evidence really has.
159
+ */
160
+ export function tokenAppearsIn(token, corpus) {
161
+ return appearsIn(token, unescapeGeneEntities(String(corpus ?? '')));
162
+ }
163
+ /** How many characters of a clipped line's tail we are willing to match against a token. */
164
+ const MAX_CLIP_MATCH = 64;
165
+ /** The longest suffix of `head` that `text` starts with, at least 6 characters or nothing. */
166
+ function sharedSuffixLength(head, text) {
167
+ const max = Math.min(head.length, text.length, MAX_CLIP_MATCH);
168
+ for (let n = max; n >= 6; n -= 1) {
169
+ if (text.startsWith(head.slice(head.length - n)))
170
+ return n;
171
+ }
172
+ return 0;
173
+ }
174
+ /** The text each evidence LINE had before this system clipped it (a clip ends in `...`). */
175
+ function clippedHeads(corpus) {
176
+ return corpus
177
+ .split(/\r?\n/)
178
+ .map((line) => line.trimEnd())
179
+ .filter((line) => line.endsWith('...') && line.length > 6)
180
+ .map((line) => line.slice(0, -3));
181
+ }
182
+ /** Was this miss CAUSED by our own clipping? Only then may it be downgraded (RV-13). */
183
+ function looksClipped(token, heads) {
184
+ const text = unescapeGeneEntities(token);
185
+ return text.length >= 6 && heads.some((head) => sharedSuffixLength(head, text) >= 6);
186
+ }
187
+ /** Check every token of `drafted` against `corpus` (all evidence texts joined). */
188
+ export function findUnsupportedTokens(drafted, corpus) {
189
+ const tokens = [];
190
+ const seen = new Set();
191
+ for (const text of drafted) {
192
+ for (const token of extractVerbatimTokens(text))
193
+ pushUnique(tokens, seen, token);
194
+ }
195
+ const haystack = unescapeGeneEntities(String(corpus ?? ''));
196
+ // The heads come from the UNESCAPED text too: historical evidence holds `&amp;&amp;` where the
197
+ // draft says `&&`, and a clipped `&&`-line would otherwise never be recognised as clipped (RV-20).
198
+ const heads = clippedHeads(haystack);
199
+ const missing = [];
200
+ const clipped = [];
201
+ for (const token of tokens) {
202
+ if (appearsIn(token, haystack))
203
+ continue;
204
+ if (looksClipped(token.text, heads))
205
+ clipped.push(token);
206
+ else
207
+ missing.push(token);
208
+ }
209
+ return { checked: tokens.length, missing, clipped };
210
+ }
211
+ /** `path x1, number x2` - kinds and counts only, never the token text (I-19). */
212
+ export function summarizeMissing(missing) {
213
+ const counts = new Map();
214
+ for (const token of missing)
215
+ counts.set(token.kind, (counts.get(token.kind) ?? 0) + 1);
216
+ return [...counts.entries()].map(([kind, n]) => `${kind} x${n}`).join(', ');
217
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Candidate validation entry point (gene-bank spec 10.7).
3
+ *
4
+ * ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
5
+ *
6
+ * `validateCandidateDetailed` runs the shared static check, the oversight rules and the checks of
7
+ * the candidate's type, and returns the per-check results (`by: code | model | user`) together with
8
+ * the ROUTING the curator must follow: pass, fail, wait for a person, or convert into a merge /
9
+ * revise. `validateCandidate` is the same thing reduced to the `GeneValidation` that goes into the
10
+ * version file.
11
+ *
12
+ * NEVER THROWS, AND A THROWN PORT IS NEVER A PASS. A validator that cannot do its job (a port
13
+ * rejected, a bug) yields a failing `VALIDATOR_ERROR` check, so an outage cannot publish a gene.
14
+ * Nothing here writes: the outcome is data the publish path acts on.
15
+ */
16
+ import type { GeneValidation } from '@aragon-agent/tui/model/gene/types';
17
+ import type { CandidateContext, CandidateOutcome } from './types.js';
18
+ export type { CandidateContext, CandidateOutcome, CandidateVerdict, DerivedTool, TypeResult } from './types.js';
19
+ export type { ValidatorPorts, ModelJsonRequest, ModelJsonResponse, GeneLookup } from './ports.js';
20
+ export { isSkippedCheck, SKIPPED_PREFIX } from './common.js';
21
+ export declare function validateCandidateDetailed(ctx: CandidateContext): Promise<CandidateOutcome>;
22
+ /** The validation record that goes into the version file. Use the detailed form to route. */
23
+ export declare function validateCandidate(ctx: CandidateContext): Promise<GeneValidation>;
@@ -0,0 +1,62 @@
1
+ import { failCheck, oversightChecks, runStaticChecks, validationOf, verdictOf } from './common.js';
2
+ import { validateKnowledge } from './knowledge.js';
3
+ import { validateSkill } from './skill.js';
4
+ import { validateTool } from './tool.js';
5
+ export { isSkippedCheck, SKIPPED_PREFIX } from './common.js';
6
+ async function dispatch(ctx, report) {
7
+ switch (ctx.type) {
8
+ case 'knowledge':
9
+ return validateKnowledge(ctx, report);
10
+ case 'tool':
11
+ return validateTool(ctx, report);
12
+ case 'skill':
13
+ return validateSkill(ctx, report);
14
+ }
15
+ }
16
+ function errorResult(at) {
17
+ const check = failCheck('VALIDATOR_ERROR', at, 'a validator could not complete');
18
+ return { checks: [check], usage: { in: 0, out: 0 } };
19
+ }
20
+ const FALLBACK_REPORT = { issues: [], storedClass: 'standard', demoted: false };
21
+ export async function validateCandidateDetailed(ctx) {
22
+ const at = ctx.ports.now();
23
+ const targetClass = ctx.target?.head.class;
24
+ let report = FALLBACK_REPORT;
25
+ let result;
26
+ try {
27
+ report = runStaticChecks({
28
+ type: ctx.type,
29
+ content: ctx.content,
30
+ scope: ctx.scope,
31
+ ...(targetClass === undefined ? {} : { targetClass }),
32
+ ...(ctx.requestedClass === undefined ? {} : { requestedClass: ctx.requestedClass }),
33
+ ...(ctx.ports.knownSecrets === undefined ? {} : { knownSecrets: ctx.ports.knownSecrets }),
34
+ });
35
+ result = await dispatch(ctx, report);
36
+ }
37
+ catch {
38
+ result = errorResult(at);
39
+ }
40
+ const checks = [...oversightChecks(report, targetClass, at), ...result.checks];
41
+ const outcome = {
42
+ validation: validationOf(checks, at),
43
+ verdict: verdictOf(checks),
44
+ forceProbation: result.forceProbation === true,
45
+ class: report.storedClass,
46
+ autoProbed: result.autoProbed === true,
47
+ usage: result.usage,
48
+ };
49
+ if (result.needsHuman !== undefined)
50
+ outcome.needsHuman = result.needsHuman;
51
+ if (result.conflict !== undefined)
52
+ outcome.conflict = result.conflict;
53
+ if (result.probation !== undefined)
54
+ outcome.probation = result.probation;
55
+ if (result.derived !== undefined)
56
+ outcome.derived = result.derived;
57
+ return outcome;
58
+ }
59
+ /** The validation record that goes into the version file. Use the detailed form to route. */
60
+ export async function validateCandidate(ctx) {
61
+ return (await validateCandidateDetailed(ctx)).validation;
62
+ }
@@ -0,0 +1,41 @@
1
+ import type { GeneContent, GeneEvidence, GeneScope, GeneValidationCheck } from '@aragon-agent/tui/model/gene/types';
2
+ import type { StaticReport } from './common.js';
3
+ import { type VerbatimToken } from './evidence-tokens.js';
4
+ import type { ValidatorPorts } from './ports.js';
5
+ import type { CandidateContext, TypeResult } from './types.js';
6
+ /** The refs a draft cites: its `evidence` list and each claim's `evidence`. */
7
+ export declare function citedRefs(content: GeneContent): string[];
8
+ export interface ResolvedEvidence {
9
+ /** Snapshot evidence plus every cited ref that resolved. Deduplicated by ref. */
10
+ corpus: GeneEvidence[];
11
+ unresolved: number;
12
+ }
13
+ /** Resolve cited refs from the snapshot first, then through `readEvidence` (a revise cites old ones). */
14
+ export declare function resolveEvidence(ports: ValidatorPorts, scope: GeneScope, geneId: string | undefined, content: GeneContent, snapshot: readonly GeneEvidence[]): Promise<ResolvedEvidence>;
15
+ export interface SourceInput {
16
+ ports: ValidatorPorts;
17
+ scope: GeneScope;
18
+ geneId?: string;
19
+ content: GeneContent;
20
+ evidence: readonly GeneEvidence[];
21
+ /** Already-resolved evidence, so a caller that needs the corpus too reads each ref once. */
22
+ resolved?: ResolvedEvidence;
23
+ }
24
+ export interface SourceResult {
25
+ checks: GeneValidationCheck[];
26
+ /** Misses that OUR clipping explains. The gene may pass, but only on probation (RV-13). */
27
+ clipped: VerbatimToken[];
28
+ }
29
+ /**
30
+ * The CURATOR-ONLY repair line for a failing K2 (RV-17, B3): the missing tokens, verbatim, so the
31
+ * model can cite them or take them out of its draft in the same task.
32
+ *
33
+ * WHY IT IS NOT ON THE OUTCOME. `CandidateOutcome` is logged and stored, and a stored detail may
34
+ * never echo gene or evidence text (I-19) - the `poison-untrusted` case fails the moment a token
35
+ * leaves through it. This string is built at the tool boundary instead, from the model's own draft
36
+ * and its own evidence, and exists only in that one tool answer.
37
+ */
38
+ export declare function repairLines(content: GeneContent, corpus: string): string[];
39
+ /** K2, reusable by `recheck` (10.9). Returns the K2 check and, when run, the live_check record. */
40
+ export declare function checkSource(input: SourceInput): Promise<SourceResult>;
41
+ export declare function validateKnowledge(ctx: CandidateContext, report: StaticReport): Promise<TypeResult>;