@aragon-agent/cli 0.6.39 → 0.6.42

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 (83) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/README.md +126 -20
  3. package/dist/agent/controller.d.ts +139 -14
  4. package/dist/agent/controller.js +299 -40
  5. package/dist/agent/model-profile-settings.js +12 -1
  6. package/dist/agent/plan-prompt.d.ts +1 -3
  7. package/dist/agent/plan-prompt.js +13 -7
  8. package/dist/agent/reducer.d.ts +29 -1
  9. package/dist/agent/reducer.js +34 -6
  10. package/dist/agent/skill-triage-prompt.d.ts +42 -0
  11. package/dist/agent/skill-triage-prompt.js +74 -0
  12. package/dist/agent/system-prompt.d.ts +33 -2
  13. package/dist/agent/system-prompt.js +12 -4
  14. package/dist/cli.js +21 -5
  15. package/dist/commands/builtins.js +28 -185
  16. package/dist/commands/skills.js +86 -1
  17. package/dist/commands/subagent-command.d.ts +30 -0
  18. package/dist/commands/subagent-command.js +39 -0
  19. package/dist/commands/team-command.d.ts +49 -0
  20. package/dist/commands/team-command.js +259 -0
  21. package/dist/compaction/command.js +16 -3
  22. package/dist/compaction/compactor.d.ts +25 -0
  23. package/dist/compaction/compactor.js +111 -10
  24. package/dist/compaction/digest.d.ts +24 -1
  25. package/dist/compaction/digest.js +139 -17
  26. package/dist/compaction/limits.d.ts +21 -0
  27. package/dist/compaction/limits.js +21 -0
  28. package/dist/compaction/reason-text.d.ts +36 -0
  29. package/dist/compaction/reason-text.js +78 -0
  30. package/dist/compaction/types.d.ts +82 -14
  31. package/dist/compaction/wiring.d.ts +13 -8
  32. package/dist/compaction/wiring.js +1 -0
  33. package/dist/config/load.js +50 -3
  34. package/dist/config/model-kits.d.ts +2 -1
  35. package/dist/config/schema.d.ts +82 -6
  36. package/dist/config/schema.js +107 -9
  37. package/dist/config/store.js +10 -4
  38. package/dist/proc/log-mirror.d.ts +21 -4
  39. package/dist/proc/log-mirror.js +29 -7
  40. package/dist/skills/service.d.ts +41 -0
  41. package/dist/skills/service.js +62 -0
  42. package/dist/skills/triage.d.ts +194 -0
  43. package/dist/skills/triage.js +393 -0
  44. package/dist/team/dispatch-gate.d.ts +86 -0
  45. package/dist/team/dispatch-gate.js +75 -0
  46. package/dist/team/forced-dispatch.d.ts +95 -0
  47. package/dist/team/forced-dispatch.js +208 -0
  48. package/dist/team/forced-mode.d.ts +116 -0
  49. package/dist/team/forced-mode.js +156 -0
  50. package/dist/team/forced-prompt.d.ts +48 -0
  51. package/dist/team/forced-prompt.js +84 -0
  52. package/dist/team/limits.d.ts +61 -1
  53. package/dist/team/limits.js +69 -1
  54. package/dist/team/model.d.ts +5 -5
  55. package/dist/team/model.js +5 -5
  56. package/dist/team/normalize.d.ts +15 -0
  57. package/dist/team/normalize.js +21 -4
  58. package/dist/team/prompt.d.ts +6 -3
  59. package/dist/team/prompt.js +9 -5
  60. package/dist/team/task-tool.js +11 -7
  61. package/dist/tools/human-input.d.ts +35 -2
  62. package/dist/tools/human-input.js +38 -0
  63. package/dist/tools/plan-tools.d.ts +20 -12
  64. package/dist/tools/plan-tools.js +24 -17
  65. package/dist/ui/App.js +130 -11
  66. package/dist/ui/StatusBar.d.ts +15 -0
  67. package/dist/ui/StatusBar.js +2 -0
  68. package/dist/ui/Transcript.js +1 -1
  69. package/dist/ui/entries/CompactionCard.d.ts +11 -1
  70. package/dist/ui/entries/CompactionCard.js +65 -4
  71. package/dist/ui/layout/status-layout.d.ts +27 -0
  72. package/dist/ui/layout/status-layout.js +27 -1
  73. package/dist/ui/overlays/HelpOverlay.js +8 -4
  74. package/dist/ui/overlays/SettingsScreen.d.ts +14 -0
  75. package/dist/ui/overlays/SettingsScreen.js +39 -5
  76. package/dist/ui/overlays/TeamFanoutPage.d.ts +51 -0
  77. package/dist/ui/overlays/TeamFanoutPage.js +90 -0
  78. package/dist/ui/overlays/kit-settings-state.js +3 -2
  79. package/dist/ui/overlays/model-profile-state.d.ts +20 -2
  80. package/dist/ui/overlays/model-profile-state.js +12 -0
  81. package/dist/ui/overlays/team-fanout-state.d.ts +106 -0
  82. package/dist/ui/overlays/team-fanout-state.js +155 -0
  83. package/package.json +81 -81
@@ -9,7 +9,7 @@
9
9
  * `read_file` and `grep`): it is the full log on disk plus the PATH in the
10
10
  * truncation note.
11
11
  *
12
- * THREE RULES, each of which is about not becoming a new failure mode:
12
+ * THREE RULES PLUS A SCOPE, each of which is about not becoming a new failure mode:
13
13
  *
14
14
  * - ASYNC AND COALESCED. `appendFile` with a <=4 writes/second buffer, so a
15
15
  * webpack build emitting thousands of lines cannot turn logging into the
@@ -19,19 +19,36 @@
19
19
  * - FAILURES ARE DEBUG LOGS, NEVER THROWS. A full disk must not kill a training
20
20
  * run; the ring, the tools and the job state machine do not depend on this
21
21
  * module at all.
22
+ * - SCOPED TO ITS OWN ROOT. The retention sweep deletes session directories under
23
+ * the jobs root the CALLER names, never under a parent derived from it: a
24
+ * derived parent is other people's directory the moment the mirror is handed a
25
+ * scratch path.
22
26
  */
23
27
  export interface JobLogMirrorOptions {
24
28
  /** `${aragonHome}/jobs/${sessionTag}`. A closure so a test can hand in a temp dir. */
25
29
  root: () => string;
30
+ /**
31
+ * THE DIRECTORY WHOSE SESSION SUBDIRECTORIES MAY BE SWEPT - passed, never derived.
32
+ *
33
+ * `dirname(root())` used to stand in for this, and it was wrong in the only way that
34
+ * matters: for any caller whose `root()` does not sit exactly one level below the jobs
35
+ * directory (a scratch dir in a test is the OS temp root's child) it handed the sweep a
36
+ * directory full of OTHER people's data and deleted everything but the newest few
37
+ * entries. A release run paid 40 s for that sweep and lost the temp directories of the
38
+ * test files running beside it. Omitted means NO sweep at all: growth is bounded only
39
+ * for callers that name the root they own.
40
+ */
41
+ jobsRoot?: () => string;
26
42
  maxBytes?: number;
27
43
  flushMs?: number;
28
44
  }
29
45
  /**
30
46
  * Delete all but the newest `PROC_LIMITS.mirrorRetainDirs` session directories.
31
47
  *
32
- * BEST EFFORT AND SILENT. This runs once per process at first use, and its whole
33
- * job is to stop `~/.aragon-agent/jobs/` from growing without bound; a directory
34
- * that cannot be read is not a reason to refuse to start.
48
+ * BEST EFFORT AND SILENT. This runs once per mirror at first use, and its whole job is to
49
+ * stop `~/.aragon-agent/jobs/` from growing without bound; a directory that cannot be read
50
+ * is not a reason to refuse to start. `jobsRoot` MUST be the directory this module owns -
51
+ * see `JobLogMirrorOptions.jobsRoot` for what deriving it cost.
35
52
  */
36
53
  export declare function pruneJobLogSessions(jobsRoot: string): void;
37
54
  export declare class JobLogMirror {
@@ -9,7 +9,7 @@
9
9
  * `read_file` and `grep`): it is the full log on disk plus the PATH in the
10
10
  * truncation note.
11
11
  *
12
- * THREE RULES, each of which is about not becoming a new failure mode:
12
+ * THREE RULES PLUS A SCOPE, each of which is about not becoming a new failure mode:
13
13
  *
14
14
  * - ASYNC AND COALESCED. `appendFile` with a <=4 writes/second buffer, so a
15
15
  * webpack build emitting thousands of lines cannot turn logging into the
@@ -19,18 +19,34 @@
19
19
  * - FAILURES ARE DEBUG LOGS, NEVER THROWS. A full disk must not kill a training
20
20
  * run; the ring, the tools and the job state machine do not depend on this
21
21
  * module at all.
22
+ * - SCOPED TO ITS OWN ROOT. The retention sweep deletes session directories under
23
+ * the jobs root the CALLER names, never under a parent derived from it: a
24
+ * derived parent is other people's directory the moment the mirror is handed a
25
+ * scratch path.
22
26
  */
23
27
  import { appendFile, appendFileSync, mkdirSync, readdirSync, rmSync, statSync } from 'node:fs';
24
28
  import { existsSync } from 'node:fs';
25
29
  import { dirname, join } from 'node:path';
26
30
  import { getLogger } from '../logging/logger.js';
27
31
  import { PROC_LIMITS } from './limits.js';
32
+ /**
33
+ * True when `path` holds nothing but `<jobId>.log` files, or nothing at all.
34
+ *
35
+ * DEFENSE IN DEPTH, NOT THE PRIMARY GUARD. The primary guard is that the caller names
36
+ * the jobs root instead of having it derived. This one means a sweep handed a directory
37
+ * that is not a mirror root is a no-op rather than a data loss - an empty directory and a
38
+ * directory of job logs are the only two shapes this module ever creates.
39
+ */
40
+ function isMirrorDirectory(path) {
41
+ return readdirSync(path, { withFileTypes: true }).every((entry) => entry.isFile() && entry.name.endsWith('.log'));
42
+ }
28
43
  /**
29
44
  * Delete all but the newest `PROC_LIMITS.mirrorRetainDirs` session directories.
30
45
  *
31
- * BEST EFFORT AND SILENT. This runs once per process at first use, and its whole
32
- * job is to stop `~/.aragon-agent/jobs/` from growing without bound; a directory
33
- * that cannot be read is not a reason to refuse to start.
46
+ * BEST EFFORT AND SILENT. This runs once per mirror at first use, and its whole job is to
47
+ * stop `~/.aragon-agent/jobs/` from growing without bound; a directory that cannot be read
48
+ * is not a reason to refuse to start. `jobsRoot` MUST be the directory this module owns -
49
+ * see `JobLogMirrorOptions.jobsRoot` for what deriving it cost.
34
50
  */
35
51
  export function pruneJobLogSessions(jobsRoot) {
36
52
  try {
@@ -41,14 +57,16 @@ export function pruneJobLogSessions(jobsRoot) {
41
57
  .map((entry) => {
42
58
  const path = join(jobsRoot, entry.name);
43
59
  try {
44
- return { path, mtime: statSync(path).mtimeMs };
60
+ return { path, mtime: statSync(path).mtimeMs, prunable: isMirrorDirectory(path) };
45
61
  }
46
62
  catch {
47
- return { path, mtime: 0 };
63
+ return { path, mtime: 0, prunable: false };
48
64
  }
49
65
  })
50
66
  .sort((a, b) => b.mtime - a.mtime);
51
67
  for (const stale of dirs.slice(PROC_LIMITS.mirrorRetainDirs)) {
68
+ if (!stale.prunable)
69
+ continue;
52
70
  try {
53
71
  rmSync(stale.path, { recursive: true, force: true });
54
72
  }
@@ -107,7 +125,11 @@ export class JobLogMirror {
107
125
  this.files.set(jobId, { path, bytes, capped: bytes >= this.maxBytes() });
108
126
  if (!this.pruned) {
109
127
  this.pruned = true;
110
- pruneJobLogSessions(dirname(this.opts.root()));
128
+ // ONLY THE ROOT THE CALLER NAMED. See `JobLogMirrorOptions.jobsRoot` for why
129
+ // `dirname(root())` is not a substitute for it.
130
+ const jobsRoot = this.opts.jobsRoot?.();
131
+ if (jobsRoot !== undefined)
132
+ pruneJobLogSessions(jobsRoot);
111
133
  }
112
134
  }
113
135
  catch (err) {
@@ -9,6 +9,7 @@ import { SkillRegistry, type SkillFileRef, type SkillHost, type SkillPlatform, t
9
9
  import type { NoticeLevel } from '../agent/reducer.js';
10
10
  import type { SkillsConfig, SkillsRuntimeOptions, SkillsToolPolicyMode } from '../config/schema.js';
11
11
  import { type ConfirmRequest } from '../tools/index.js';
12
+ import { type SkillRoutingReport } from './triage.js';
12
13
  /**
13
14
  * Capability-probing approval gate (D17 / §8.3.1).
14
15
  *
@@ -229,6 +230,46 @@ export declare class SkillService {
229
230
  /** Warn once about `--skill <name>` values that match nothing (§7.5). */
230
231
  reportUnknownForcedSkills(): void;
231
232
  setDisabled(name: string, disabled: boolean): void;
233
+ /**
234
+ * Route one task against the installed skills — PURE COMPUTATION (I-T2).
235
+ *
236
+ * Reads in-memory records only: no file, no body, no network, no model call. The
237
+ * whole "which skills could apply here" question therefore costs zero context
238
+ * bytes, which is what makes the disclosure ladder honest — Level 2 is paid for
239
+ * only when the model actually opens a skill.
240
+ *
241
+ * Returns `null` when triage is switched off, so every caller has one shape to
242
+ * check rather than an empty report that looks like "no match".
243
+ *
244
+ * Writes NO usage counter. An automatic proposal is not a user's choice, which
245
+ * is the same reason `loadBody({ countUse: false })` exists for always-on
246
+ * skills: counting it would pin an auto-suggested skill to the top of the
247
+ * ranking forever and destroy the signal the ranking is there to carry.
248
+ */
249
+ triage(task: string): SkillRoutingReport | null;
250
+ /**
251
+ * `/skills route <text>` — the same computation, WITHOUT the on/off gate.
252
+ *
253
+ * The gate exists to keep the block out of the prompt; it must not make the
254
+ * explanation unreachable, because "why did nothing match" is the question a user
255
+ * asks precisely when they suspect the switch is off.
256
+ */
257
+ route(task: string): SkillRoutingReport;
258
+ /**
259
+ * `/skills triage on|off` — persist the switch AND rebuild the prompt now.
260
+ *
261
+ * `updateConfig` deliberately only replaces this object's config and calls
262
+ * `persist`; it does NOT call `deps.onChange`. Every other mutator supplies that
263
+ * call itself (`setDisabled` above, the directory-trust path below), and `onChange`
264
+ * is the sole route to `controller.refreshSkills()` → `rebuildSystemPrompt()`.
265
+ * Without it the setting would be written to disk and the running session would
266
+ * keep the old prompt until the next launch — which reads as a broken switch.
267
+ *
268
+ * The early return is not an optimization: `updateConfig` persists, so flipping a
269
+ * switch to the value it already has would produce a pointless disk write and a
270
+ * pointless prompt rebuild on every keystroke.
271
+ */
272
+ setTriageEnabled(enabled: boolean): void;
232
273
  getConfig(): SkillsConfig;
233
274
  /** Local use counters backing `--sort=recent`; empty when tracking is off. */
234
275
  getUsage(): SkillUsageMap;
@@ -14,6 +14,7 @@ import { currentPlatform } from './node-host.js';
14
14
  import { MANIFEST_FILENAME, readManifest, sha256Buffer, sha256File } from './manifest.js';
15
15
  import { isDirectory, normalizeTrustPath, resolveSkillRoots, getStagingDir, } from './paths.js';
16
16
  import { USAGE_MAX_ENTRIES, loadUsage, pruneUsage, recordUse } from './usage.js';
17
+ import { buildRoutingReport } from './triage.js';
17
18
  const ENTRY_FILE = 'SKILL.md';
18
19
  /**
19
20
  * Re-exported from `manifest.ts` rather than spelled out again. The two copies
@@ -615,6 +616,67 @@ export class SkillService {
615
616
  this.updateConfig({ disabled: [...next] });
616
617
  this.deps.onChange?.();
617
618
  }
619
+ /**
620
+ * Route one task against the installed skills — PURE COMPUTATION (I-T2).
621
+ *
622
+ * Reads in-memory records only: no file, no body, no network, no model call. The
623
+ * whole "which skills could apply here" question therefore costs zero context
624
+ * bytes, which is what makes the disclosure ladder honest — Level 2 is paid for
625
+ * only when the model actually opens a skill.
626
+ *
627
+ * Returns `null` when triage is switched off, so every caller has one shape to
628
+ * check rather than an empty report that looks like "no match".
629
+ *
630
+ * Writes NO usage counter. An automatic proposal is not a user's choice, which
631
+ * is the same reason `loadBody({ countUse: false })` exists for always-on
632
+ * skills: counting it would pin an auto-suggested skill to the top of the
633
+ * ranking forever and destroy the signal the ranking is there to carry.
634
+ */
635
+ triage(task) {
636
+ if (!this.config.enabled || !this.config.triage)
637
+ return null;
638
+ return buildRoutingReport({
639
+ task,
640
+ records: this.registry.list(),
641
+ activeNames: this.registry.activeNames,
642
+ now: Date.now(),
643
+ });
644
+ }
645
+ /**
646
+ * `/skills route <text>` — the same computation, WITHOUT the on/off gate.
647
+ *
648
+ * The gate exists to keep the block out of the prompt; it must not make the
649
+ * explanation unreachable, because "why did nothing match" is the question a user
650
+ * asks precisely when they suspect the switch is off.
651
+ */
652
+ route(task) {
653
+ return buildRoutingReport({
654
+ task,
655
+ records: this.registry.list(),
656
+ activeNames: this.registry.activeNames,
657
+ now: Date.now(),
658
+ });
659
+ }
660
+ /**
661
+ * `/skills triage on|off` — persist the switch AND rebuild the prompt now.
662
+ *
663
+ * `updateConfig` deliberately only replaces this object's config and calls
664
+ * `persist`; it does NOT call `deps.onChange`. Every other mutator supplies that
665
+ * call itself (`setDisabled` above, the directory-trust path below), and `onChange`
666
+ * is the sole route to `controller.refreshSkills()` → `rebuildSystemPrompt()`.
667
+ * Without it the setting would be written to disk and the running session would
668
+ * keep the old prompt until the next launch — which reads as a broken switch.
669
+ *
670
+ * The early return is not an optimization: `updateConfig` persists, so flipping a
671
+ * switch to the value it already has would produce a pointless disk write and a
672
+ * pointless prompt rebuild on every keystroke.
673
+ */
674
+ setTriageEnabled(enabled) {
675
+ if (this.config.triage === enabled)
676
+ return;
677
+ this.updateConfig({ triage: enabled });
678
+ this.deps.onChange?.();
679
+ }
618
680
  getConfig() {
619
681
  return this.config;
620
682
  }
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Deterministic skill routing for the pre-work triage step
3
+ * (skill-triage-and-unbounded-ask §4.2.2).
4
+ *
5
+ * WHY THIS IS NOT AN LLM CALL (D-11). The question "which installed skill, if any,
6
+ * covers this task?" is answered against data the process already holds: the
7
+ * `SkillRecord` set in `SkillRegistry`, with a name, a one-line description and a
8
+ * keyword list. A model call would add a round trip, latency and — the decisive
9
+ * point — untestability, because a router that is itself a model can only be
10
+ * asserted on statistically. This module is a pure function of its inputs, so the
11
+ * whole feature has unit tests instead of anecdotes.
12
+ *
13
+ * WHAT IT IS ALLOWED TO TOUCH. Records only. No filesystem, no `SKILL.md` read,
14
+ * no network, no clock (invariant I-T2, asserted by a source-scanning test). That
15
+ * is what makes the disclosure ladder real: "which skills exist" costs zero
16
+ * context bytes and zero IO, and the expensive Level 2 body is paid for only when
17
+ * the model actually calls `skill(name)`.
18
+ *
19
+ * BOTH SCRIPTS ARE HANDLED. The user writes tasks in Chinese and English, and
20
+ * skill descriptions are usually English. Space-separated tokens alone score zero
21
+ * on CJK text, so a run of Han/Kana/Hangul characters is tokenized into bigrams
22
+ * (plus the whole run when it is short enough for a phrase match to be likely).
23
+ *
24
+ * ASCII ONLY IN LITERALS: `skills/` is outside the glyph scanner's scope today,
25
+ * but new text keeps the same rule rather than assuming a scanner will never
26
+ * cover it.
27
+ */
28
+ import type { SkillRecord, SkillScope } from '@aragon-agent/core';
29
+ export interface SkillTriageLimits {
30
+ /** Candidates presented per turn. R-1: more than three is a reading list. */
31
+ maxCandidates: number;
32
+ /** One keyword hit is enough to be worth showing. */
33
+ minScore: number;
34
+ /** The score at which "you were told and did not load it" is worth a notice. */
35
+ confidentScore: number;
36
+ /**
37
+ * Byte ceiling for `<skill_candidates>`. 900, NOT 700: the fixed overhead is
38
+ * about 114 B, so 700 leaves ~586 B for three lines that cost up to 249 B each.
39
+ * A ceiling that silently drops the third candidate on ordinary input is not a
40
+ * ceiling, it is a slow leak — see the arithmetic table in `triage.test.ts`.
41
+ */
42
+ maxBlockBytes: number;
43
+ /** Byte ceiling for the `<skill_triage>` protocol block, asserted elsewhere. */
44
+ maxProtocolBytes: number;
45
+ /** Task text is truncated to this before tokenizing. */
46
+ maxTaskChars: number;
47
+ /** Tokens kept after tokenizing; bounds the scoring loop on a long task. */
48
+ maxTokens: number;
49
+ /** Latin tokens shorter than this are noise ("a", "of", "to"). */
50
+ latinTokenMinChars: number;
51
+ /** CJK runs shorter than this are noise; a single ideograph means nothing. */
52
+ cjkMinRunChars: number;
53
+ /** Bigrams taken per run. A 2,000-char run cannot be allowed to flood the set. */
54
+ maxCjkGramsPerRun: number;
55
+ /**
56
+ * Longest CJK run that ALSO contributes a whole-run token.
57
+ *
58
+ * Above this the whole-run token is dropped on purpose: a 2,000-character
59
+ * "token" cannot be a substring of any haystack, so it can only occupy one of
60
+ * `maxTokens` slots that a real token needed.
61
+ */
62
+ maxWholeRunChars: number;
63
+ /** Skill names are unbounded upstream (a kebab directory can be long). */
64
+ maxNameChars: number;
65
+ /** One line of description per candidate. */
66
+ descLineChars: number;
67
+ /** Each match-reason tag. */
68
+ reasonChars: number;
69
+ }
70
+ export declare const SKILL_TRIAGE_LIMITS: SkillTriageLimits;
71
+ export type MatchReason = 'name' | 'keyword' | 'description';
72
+ export interface SkillScore {
73
+ score: number;
74
+ reasons: MatchReason[];
75
+ mentioned: boolean;
76
+ }
77
+ export interface SkillCandidate {
78
+ name: string;
79
+ scope: SkillScope;
80
+ /** Already truncated to `descLineChars`; the renderer does not re-cut it. */
81
+ description: string;
82
+ /** 0..44 — see `TRIAGE_WEIGHTS` / `TRIAGE_CAPS`. */
83
+ score: number;
84
+ /** At most three, in the order they were first hit. */
85
+ reasons: MatchReason[];
86
+ }
87
+ export interface SkillRoutingReport {
88
+ /** The task text AFTER truncation to `maxTaskChars`. */
89
+ task: string;
90
+ /** How many tokens the task produced — the explanation for a miss. */
91
+ tokenCount: number;
92
+ /** How many records were eligible to be scored. */
93
+ eligible: number;
94
+ candidates: SkillCandidate[];
95
+ /**
96
+ * The best-scoring skill that did NOT make the list, or `null` when nothing
97
+ * scored at all.
98
+ *
99
+ * It exists for exactly one caller: `/skills route`'s "no match" output. "No
100
+ * skill matched" on its own is a dead end, and the threshold is the one number a
101
+ * user may need to argue with. Naming the runner-up and its score is what turns
102
+ * that dead end into "the threshold is slightly too high" or "nothing is close".
103
+ */
104
+ topUnqualified: {
105
+ name: string;
106
+ score: number;
107
+ } | null;
108
+ decision: 'none' | 'suggest' | 'confident';
109
+ /**
110
+ * Timestamp, for display and logging only. It never participates in ordering or
111
+ * scoring, which is what keeps this module a pure function (I-T2).
112
+ */
113
+ at: number;
114
+ }
115
+ /**
116
+ * Task text to a token set, Latin words and CJK bigrams mixed together.
117
+ *
118
+ * DETERMINISTIC BY CONSTRUCTION: no random sampling, no clock, no iteration over a
119
+ * `Set` whose insertion order depends on anything but the input. AC-T3 asserts
120
+ * that two calls on the same input are `deepEqual`.
121
+ */
122
+ export declare function tokenizeTask(text: string, limits?: SkillTriageLimits): string[];
123
+ /**
124
+ * Score one record against the task (44 is the ceiling: 12 + 5*2 + 4*4 + 2*3).
125
+ *
126
+ * THE THREE HAYSTACKS ARE SEPARATE on purpose. A token found in `keywords` is a
127
+ * deliberate author signal and scores 4; the same token found only in the prose
128
+ * description scores 2. Merging them into one string would make every keyword hit
129
+ * look like a description hit as well, inflating the score on exactly the records
130
+ * whose authors were least specific.
131
+ *
132
+ * `record.frontmatter.keywords`, never `record.keywords`: `SkillRecord` has no
133
+ * top-level keyword field, and both keywords and `activation` hang off
134
+ * `frontmatter`.
135
+ */
136
+ export declare function scoreSkill(record: SkillRecord, tokens: string[], taskText: string): SkillScore;
137
+ export interface SelectSkillCandidatesInput {
138
+ task: string;
139
+ records: SkillRecord[];
140
+ /** Skills already loaded this turn — never proposed again (I-T4). */
141
+ activeNames: readonly string[];
142
+ limits?: Partial<SkillTriageLimits>;
143
+ /**
144
+ * Reference timestamp for the report's `at` field. Absent means `0`, so the
145
+ * function has no clock of its own (I-T2).
146
+ */
147
+ now?: number;
148
+ }
149
+ /**
150
+ * The candidate list alone — `buildRoutingReport` minus the report.
151
+ *
152
+ * ONE PIPELINE, TWO VIEWS. This used to repeat the tokenize / rank / filter / slice
153
+ * sequence, which meant the candidate order and the report's `topUnqualified` were
154
+ * produced by two pieces of code that had to be kept in agreement by hand: exactly
155
+ * the drift `rankEligible`'s single comparator exists to prevent. The report owns
156
+ * the arithmetic; this is the projection of it for a caller who does not want
157
+ * `at` / `eligible` / `topUnqualified`.
158
+ */
159
+ export declare function selectSkillCandidates(input: SelectSkillCandidatesInput): SkillCandidate[];
160
+ /**
161
+ * The router's whole decision, as one pure call — and the ONE place the arithmetic
162
+ * lives (`selectSkillCandidates` is a projection of it).
163
+ *
164
+ * THE FILTER IS THE SAME ONE `catalogRecords` AND `skill_find` USE (I-T4): not
165
+ * disabled, not invalid, not `activation: manual`, and not already active. It is
166
+ * re-implemented here rather than imported because the report needs the
167
+ * candidates' scores, and `catalogRecords` returns records. `triage.test.ts` pins
168
+ * this filter against `catalogRecords` so the two cannot drift apart silently.
169
+ *
170
+ * ORDER IS SCOPE FIRST, then name. That is NOT the order the user sees in
171
+ * `<available_skills>`, where `usageTracking` re-ranks by recent use
172
+ * (`service.ts:catalogBlock`). Intentional: the catalog answers "what have I used
173
+ * lately", the candidate list answers "what should I read first".
174
+ *
175
+ * `at` is the only non-derived field and it is display-only, so a test can pass a
176
+ * fixed value and compare two reports with `deepEqual`.
177
+ */
178
+ export declare function buildRoutingReport(input: SelectSkillCandidatesInput): SkillRoutingReport;
179
+ /**
180
+ * The `<skill_candidates>` block, or `''` when there is nothing to propose.
181
+ *
182
+ * `''` is load-bearing: it is what keeps `buildSystemPrompt` byte-identical to the
183
+ * pre-feature text when triage finds nothing, so an empty result cannot leave an
184
+ * empty shell behind (I-T1).
185
+ *
186
+ * BUDGET DISCIPLINE, copied from `renderSkillCatalog`: reserve the worst-case
187
+ * overflow line UP FRONT, add lines while they fit, and on overflow drop whole
188
+ * lines rather than truncating text or the closing tag. A dropped candidate is
189
+ * visible as `(+N more not shown)`; a truncated one reads as a corrupt skill name.
190
+ */
191
+ export declare function renderSkillCandidates(candidates: SkillCandidate[], opts?: {
192
+ maxBytes?: number;
193
+ limits?: Partial<SkillTriageLimits>;
194
+ }): string;