@aragon-agent/cli 0.6.54 → 0.6.56
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 +2912 -2838
- package/README.md +4226 -4042
- package/dist/agent/controller.d.ts +119 -0
- package/dist/agent/controller.js +365 -2
- package/dist/agent/governance-wiring.js +8 -1
- package/dist/agent/redteam-prompt.d.ts +47 -0
- package/dist/agent/redteam-prompt.js +161 -0
- package/dist/agent/redteam-wiring.d.ts +159 -0
- package/dist/agent/redteam-wiring.js +349 -0
- package/dist/agent/system-prompt.d.ts +39 -0
- package/dist/agent/system-prompt.js +18 -0
- package/dist/app/App.d.ts +10 -1
- package/dist/app/App.js +233 -24
- package/dist/app/use-redteam-mode.d.ts +56 -0
- package/dist/app/use-redteam-mode.js +121 -0
- package/dist/cli.js +82 -4
- package/dist/commands/builtins.js +43 -1
- package/dist/commands/catalog.js +5 -0
- package/dist/commands/index-build.js +2 -1
- package/dist/commands/redteam-command.d.ts +22 -0
- package/dist/commands/redteam-command.js +141 -0
- package/dist/commands/registry.d.ts +8 -0
- package/dist/config/app-paths.d.ts +10 -0
- package/dist/config/app-paths.js +12 -0
- package/dist/config/cli-commands.d.ts +29 -0
- package/dist/config/cli-commands.js +76 -1
- package/dist/config/env.d.ts +3 -1
- package/dist/config/env.js +23 -1
- package/dist/config/load.d.ts +22 -0
- package/dist/config/load.js +22 -2
- package/dist/config/redteam-launch.d.ts +77 -0
- package/dist/config/redteam-launch.js +58 -0
- package/dist/config/store.js +21 -1
- package/dist/config/ui-state.d.ts +44 -0
- package/dist/config/ui-state.js +38 -0
- package/dist/exec/bridge/server.d.ts +7 -0
- package/dist/exec/bridge/server.js +6 -2
- package/dist/exec/cli-commands.js +4 -0
- package/dist/exec/index.js +2 -0
- package/dist/exec/options.d.ts +11 -0
- package/dist/exec/options.js +21 -1
- package/dist/gene/block.d.ts +33 -0
- package/dist/gene/block.js +51 -0
- package/dist/gene/capacity.d.ts +74 -0
- package/dist/gene/capacity.js +169 -0
- package/dist/gene/catalog-reconcile.d.ts +13 -0
- package/dist/gene/catalog-reconcile.js +105 -0
- package/dist/gene/catalog-stats.d.ts +27 -0
- package/dist/gene/catalog-stats.js +89 -0
- package/dist/gene/catalog-sync.d.ts +82 -0
- package/dist/gene/catalog-sync.js +324 -0
- package/dist/gene/catalog.d.ts +160 -0
- package/dist/gene/catalog.js +433 -0
- package/dist/gene/cli-commands.d.ts +50 -0
- package/dist/gene/cli-commands.js +500 -0
- package/dist/gene/command-report.d.ts +40 -0
- package/dist/gene/command-report.js +246 -0
- package/dist/gene/command.d.ts +29 -0
- package/dist/gene/command.js +561 -0
- package/dist/gene/commit-apply-types.d.ts +13 -0
- package/dist/gene/commit-apply-types.js +1 -0
- package/dist/gene/commit-compound.d.ts +34 -0
- package/dist/gene/commit-compound.js +212 -0
- package/dist/gene/commit-counts.d.ts +41 -0
- package/dist/gene/commit-counts.js +70 -0
- package/dist/gene/commit-exec.d.ts +42 -0
- package/dist/gene/commit-exec.js +134 -0
- package/dist/gene/commit-head.d.ts +52 -0
- package/dist/gene/commit-head.js +97 -0
- package/dist/gene/commit-plan.d.ts +95 -0
- package/dist/gene/commit-plan.js +68 -0
- package/dist/gene/commit-prepare.d.ts +63 -0
- package/dist/gene/commit-prepare.js +159 -0
- package/dist/gene/commit-types.d.ts +234 -0
- package/dist/gene/commit-types.js +3 -0
- package/dist/gene/curator/agent.d.ts +137 -0
- package/dist/gene/curator/agent.js +203 -0
- package/dist/gene/curator/budget.d.ts +69 -0
- package/dist/gene/curator/budget.js +131 -0
- package/dist/gene/curator/conflicts.d.ts +54 -0
- package/dist/gene/curator/conflicts.js +143 -0
- package/dist/gene/curator/curator.d.ts +170 -0
- package/dist/gene/curator/curator.js +617 -0
- package/dist/gene/curator/deps.d.ts +34 -0
- package/dist/gene/curator/deps.js +48 -0
- package/dist/gene/curator/deterministic.d.ts +62 -0
- package/dist/gene/curator/deterministic.js +287 -0
- package/dist/gene/curator/executors.d.ts +36 -0
- package/dist/gene/curator/executors.js +379 -0
- package/dist/gene/curator/lanes.d.ts +52 -0
- package/dist/gene/curator/lanes.js +99 -0
- package/dist/gene/curator/lease.d.ts +76 -0
- package/dist/gene/curator/lease.js +171 -0
- package/dist/gene/curator/library.d.ts +36 -0
- package/dist/gene/curator/library.js +169 -0
- package/dist/gene/curator/lifecycle.d.ts +52 -0
- package/dist/gene/curator/lifecycle.js +109 -0
- package/dist/gene/curator/maintenance.d.ts +71 -0
- package/dist/gene/curator/maintenance.js +213 -0
- package/dist/gene/curator/probation.d.ts +51 -0
- package/dist/gene/curator/probation.js +71 -0
- package/dist/gene/curator/probe.d.ts +131 -0
- package/dist/gene/curator/probe.js +534 -0
- package/dist/gene/curator/prompt.d.ts +18 -0
- package/dist/gene/curator/prompt.js +128 -0
- package/dist/gene/curator/publish.d.ts +64 -0
- package/dist/gene/curator/publish.js +113 -0
- package/dist/gene/curator/recheck.d.ts +55 -0
- package/dist/gene/curator/recheck.js +103 -0
- package/dist/gene/curator/run-events.d.ts +63 -0
- package/dist/gene/curator/run-events.js +55 -0
- package/dist/gene/curator/similarity.d.ts +13 -0
- package/dist/gene/curator/similarity.js +46 -0
- package/dist/gene/curator/switches.d.ts +78 -0
- package/dist/gene/curator/switches.js +146 -0
- package/dist/gene/curator/task-context.d.ts +93 -0
- package/dist/gene/curator/task-context.js +63 -0
- package/dist/gene/curator/task-runner.d.ts +56 -0
- package/dist/gene/curator/task-runner.js +257 -0
- package/dist/gene/curator/tool-support.d.ts +112 -0
- package/dist/gene/curator/tool-support.js +197 -0
- package/dist/gene/curator/toolkit.d.ts +49 -0
- package/dist/gene/curator/toolkit.js +104 -0
- package/dist/gene/curator/tools-read.d.ts +4 -0
- package/dist/gene/curator/tools-read.js +177 -0
- package/dist/gene/curator/tools-release.d.ts +73 -0
- package/dist/gene/curator/tools-release.js +287 -0
- package/dist/gene/curator/tools-verify.d.ts +47 -0
- package/dist/gene/curator/tools-verify.js +202 -0
- package/dist/gene/curator/tools-write.d.ts +26 -0
- package/dist/gene/curator/tools-write.js +394 -0
- package/dist/gene/curator/tools.d.ts +23 -0
- package/dist/gene/curator/tools.js +21 -0
- package/dist/gene/curator/validate/common.d.ts +87 -0
- package/dist/gene/curator/validate/common.js +132 -0
- package/dist/gene/curator/validate/evidence-tokens.d.ts +36 -0
- package/dist/gene/curator/validate/evidence-tokens.js +139 -0
- package/dist/gene/curator/validate/index.d.ts +23 -0
- package/dist/gene/curator/validate/index.js +62 -0
- package/dist/gene/curator/validate/knowledge.d.ts +25 -0
- package/dist/gene/curator/validate/knowledge.js +216 -0
- package/dist/gene/curator/validate/live-check.d.ts +14 -0
- package/dist/gene/curator/validate/live-check.js +144 -0
- package/dist/gene/curator/validate/ports.d.ts +67 -0
- package/dist/gene/curator/validate/ports.js +1 -0
- package/dist/gene/curator/validate/prompts.d.ts +41 -0
- package/dist/gene/curator/validate/prompts.js +161 -0
- package/dist/gene/curator/validate/skill.d.ts +15 -0
- package/dist/gene/curator/validate/skill.js +251 -0
- package/dist/gene/curator/validate/tool.d.ts +6 -0
- package/dist/gene/curator/validate/tool.js +217 -0
- package/dist/gene/curator/validate/types.d.ts +90 -0
- package/dist/gene/curator/validate/types.js +1 -0
- package/dist/gene/curator/validator-ports.d.ts +38 -0
- package/dist/gene/curator/validator-ports.js +29 -0
- package/dist/gene/diag.d.ts +209 -0
- package/dist/gene/diag.js +549 -0
- package/dist/gene/env.d.ts +10 -0
- package/dist/gene/env.js +214 -0
- package/dist/gene/eval-recorder.d.ts +84 -0
- package/dist/gene/eval-recorder.js +222 -0
- package/dist/gene/explain-transport.d.ts +3 -0
- package/dist/gene/explain-transport.js +39 -0
- package/dist/gene/explain.d.ts +96 -0
- package/dist/gene/explain.js +293 -0
- package/dist/gene/fs.d.ts +39 -0
- package/dist/gene/fs.js +139 -0
- package/dist/gene/fsck.d.ts +68 -0
- package/dist/gene/fsck.js +134 -0
- package/dist/gene/gc-library-sweeps.d.ts +9 -0
- package/dist/gene/gc-library-sweeps.js +220 -0
- package/dist/gene/gc-rejected-set.d.ts +15 -0
- package/dist/gene/gc-rejected-set.js +63 -0
- package/dist/gene/gc-safe.d.ts +12 -0
- package/dist/gene/gc-safe.js +74 -0
- package/dist/gene/gc-scope-sweeps.d.ts +18 -0
- package/dist/gene/gc-scope-sweeps.js +297 -0
- package/dist/gene/gc-types.d.ts +55 -0
- package/dist/gene/gc-types.js +26 -0
- package/dist/gene/gc.d.ts +42 -0
- package/dist/gene/gc.js +129 -0
- package/dist/gene/gene-errors.d.ts +23 -0
- package/dist/gene/gene-errors.js +29 -0
- package/dist/gene/hints.d.ts +91 -0
- package/dist/gene/hints.js +394 -0
- package/dist/gene/hub.d.ts +149 -0
- package/dist/gene/hub.js +371 -0
- package/dist/gene/import-plan.d.ts +80 -0
- package/dist/gene/import-plan.js +294 -0
- package/dist/gene/import-proposal.d.ts +23 -0
- package/dist/gene/import-proposal.js +101 -0
- package/dist/gene/import-skill-port.d.ts +6 -0
- package/dist/gene/import-skill-port.js +53 -0
- package/dist/gene/import-sources.d.ts +48 -0
- package/dist/gene/import-sources.js +140 -0
- package/dist/gene/index-writer.d.ts +36 -0
- package/dist/gene/index-writer.js +101 -0
- package/dist/gene/learn/learn-call.d.ts +63 -0
- package/dist/gene/learn/learn-call.js +157 -0
- package/dist/gene/learn/learn-prompt.d.ts +51 -0
- package/dist/gene/learn/learn-prompt.js +245 -0
- package/dist/gene/learn/learner.d.ts +181 -0
- package/dist/gene/learn/learner.js +426 -0
- package/dist/gene/learn/ledger.d.ts +220 -0
- package/dist/gene/learn/ledger.js +394 -0
- package/dist/gene/learn/proposal-build.d.ts +83 -0
- package/dist/gene/learn/proposal-build.js +211 -0
- package/dist/gene/learn/proposal-guard.d.ts +43 -0
- package/dist/gene/learn/proposal-guard.js +37 -0
- package/dist/gene/learn/signals-port.d.ts +47 -0
- package/dist/gene/learn/signals-port.js +86 -0
- package/dist/gene/maintenance-paths.d.ts +7 -0
- package/dist/gene/maintenance-paths.js +20 -0
- package/dist/gene/maintenance-probation.d.ts +33 -0
- package/dist/gene/maintenance-probation.js +127 -0
- package/dist/gene/maintenance-proposals.d.ts +24 -0
- package/dist/gene/maintenance-proposals.js +68 -0
- package/dist/gene/maintenance-runner.d.ts +92 -0
- package/dist/gene/maintenance-runner.js +262 -0
- package/dist/gene/maintenance-tasks.d.ts +37 -0
- package/dist/gene/maintenance-tasks.js +95 -0
- package/dist/gene/manager-actions.d.ts +12 -0
- package/dist/gene/manager-actions.js +279 -0
- package/dist/gene/manager-approve.d.ts +29 -0
- package/dist/gene/manager-approve.js +84 -0
- package/dist/gene/manager-context.d.ts +90 -0
- package/dist/gene/manager-context.js +201 -0
- package/dist/gene/manager-detail.d.ts +17 -0
- package/dist/gene/manager-detail.js +313 -0
- package/dist/gene/manager-gc.d.ts +13 -0
- package/dist/gene/manager-gc.js +81 -0
- package/dist/gene/manager-library.d.ts +39 -0
- package/dist/gene/manager-library.js +90 -0
- package/dist/gene/manager-list.d.ts +27 -0
- package/dist/gene/manager-list.js +170 -0
- package/dist/gene/manager-queue.d.ts +16 -0
- package/dist/gene/manager-queue.js +124 -0
- package/dist/gene/manager-stats.d.ts +28 -0
- package/dist/gene/manager-stats.js +53 -0
- package/dist/gene/manager-view.d.ts +27 -0
- package/dist/gene/manager-view.js +124 -0
- package/dist/gene/manager.d.ts +56 -0
- package/dist/gene/manager.js +179 -0
- package/dist/gene/orphan-scopes.d.ts +37 -0
- package/dist/gene/orphan-scopes.js +150 -0
- package/dist/gene/paths.d.ts +73 -0
- package/dist/gene/paths.js +239 -0
- package/dist/gene/plan-content.d.ts +73 -0
- package/dist/gene/plan-content.js +522 -0
- package/dist/gene/plan-lifecycle.d.ts +29 -0
- package/dist/gene/plan-lifecycle.js +310 -0
- package/dist/gene/policy.d.ts +71 -0
- package/dist/gene/policy.js +313 -0
- package/dist/gene/project-learning.d.ts +25 -0
- package/dist/gene/project-learning.js +54 -0
- package/dist/gene/propagation.d.ts +48 -0
- package/dist/gene/propagation.js +45 -0
- package/dist/gene/queue-lock.d.ts +22 -0
- package/dist/gene/queue-lock.js +99 -0
- package/dist/gene/queue-record.d.ts +57 -0
- package/dist/gene/queue-record.js +145 -0
- package/dist/gene/queue.d.ts +235 -0
- package/dist/gene/queue.js +764 -0
- package/dist/gene/read.d.ts +61 -0
- package/dist/gene/read.js +252 -0
- package/dist/gene/runlog.d.ts +101 -0
- package/dist/gene/runlog.js +404 -0
- package/dist/gene/schema-lite.d.ts +24 -0
- package/dist/gene/schema-lite.js +159 -0
- package/dist/gene/scope-guard.d.ts +23 -0
- package/dist/gene/scope-guard.js +9 -0
- package/dist/gene/scope-lock.d.ts +48 -0
- package/dist/gene/scope-lock.js +222 -0
- package/dist/gene/scope-verify.d.ts +63 -0
- package/dist/gene/scope-verify.js +123 -0
- package/dist/gene/secrets.d.ts +43 -0
- package/dist/gene/secrets.js +161 -0
- package/dist/gene/service-context.d.ts +43 -0
- package/dist/gene/service-context.js +79 -0
- package/dist/gene/service-prepare.d.ts +25 -0
- package/dist/gene/service-prepare.js +219 -0
- package/dist/gene/service-types.d.ts +196 -0
- package/dist/gene/service-types.js +1 -0
- package/dist/gene/service-view.d.ts +41 -0
- package/dist/gene/service-view.js +69 -0
- package/dist/gene/service.d.ts +114 -0
- package/dist/gene/service.js +761 -0
- package/dist/gene/session-start.d.ts +36 -0
- package/dist/gene/session-start.js +212 -0
- package/dist/gene/store-port.d.ts +88 -0
- package/dist/gene/store-port.js +10 -0
- package/dist/gene/store-rows.d.ts +36 -0
- package/dist/gene/store-rows.js +72 -0
- package/dist/gene/store.d.ts +125 -0
- package/dist/gene/store.js +622 -0
- package/dist/gene/tombstones.d.ts +47 -0
- package/dist/gene/tombstones.js +61 -0
- package/dist/gene/tool-runner.d.ts +47 -0
- package/dist/gene/tool-runner.js +154 -0
- package/dist/gene/tool-screen.d.ts +41 -0
- package/dist/gene/tool-screen.js +227 -0
- package/dist/gene/tools.d.ts +112 -0
- package/dist/gene/tools.js +539 -0
- package/dist/gene/transfer.d.ts +85 -0
- package/dist/gene/transfer.js +433 -0
- package/dist/gene/ui-hints.d.ts +15 -0
- package/dist/gene/ui-hints.js +67 -0
- package/dist/gene/usage-fold-cursor.d.ts +24 -0
- package/dist/gene/usage-fold-cursor.js +115 -0
- package/dist/gene/usage-fold.d.ts +49 -0
- package/dist/gene/usage-fold.js +397 -0
- package/dist/gene/usage.d.ts +67 -0
- package/dist/gene/usage.js +231 -0
- package/dist/gene/version-service.d.ts +118 -0
- package/dist/gene/version-service.js +453 -0
- package/dist/gene/wiring-events.d.ts +43 -0
- package/dist/gene/wiring-events.js +113 -0
- package/dist/gene/wiring-models.d.ts +46 -0
- package/dist/gene/wiring-models.js +81 -0
- package/dist/gene/wiring.d.ts +200 -0
- package/dist/gene/wiring.js +764 -0
- package/dist/governance/prompts/orchestrator-block.js +3 -2
- package/dist/host/controller-factory.d.ts +8 -0
- package/dist/host/controller-factory.js +7 -0
- package/dist/host/gene.d.ts +26 -0
- package/dist/host/gene.js +24 -0
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/session/checkpoint.d.ts +15 -0
- package/dist/session/checkpoint.js +18 -0
- package/dist/session/persist.d.ts +21 -0
- package/dist/session/persist.js +10 -0
- package/dist/session/startup-session.d.ts +11 -2
- package/dist/session/startup-session.js +12 -2
- package/dist/session/validate-session.js +31 -0
- package/dist/team/runtime.d.ts +16 -0
- package/dist/team/runtime.js +29 -0
- package/dist/team/subagent.d.ts +55 -0
- package/dist/team/subagent.js +46 -2
- package/dist/tools/index.d.ts +60 -2
- package/dist/tools/index.js +68 -10
- package/package.json +3 -3
- package/skills/project-indexer/SKILL.md +275 -147
- package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -0
- package/skills/project-indexer/templates/config-template.md +12 -0
- package/skills/project-indexer/templates/index-template.md +4 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { AgentTool, ToolResult } from '@aragon-agent/core';
|
|
2
|
+
import type { GeneService } from './service.js';
|
|
3
|
+
import type { GeneActor, GeneHintHit } from './service-types.js';
|
|
4
|
+
/** Whether a tool is decorated at all. Pure; the factory and the tests share it. */
|
|
5
|
+
export declare function isHintableTool(name: string): boolean;
|
|
6
|
+
export type GeneHintService = Pick<GeneService, 'hintSearch' | 'markHintsShown'>;
|
|
7
|
+
export interface GeneHintPorts {
|
|
8
|
+
service: GeneHintService;
|
|
9
|
+
/** Who is calling. Read per call: the run id changes with every user turn. */
|
|
10
|
+
actor(): GeneActor;
|
|
11
|
+
/** Cheap pre-check (`gene.use && gene.hints`); false skips all bookkeeping. Default: true. */
|
|
12
|
+
active?(): boolean;
|
|
13
|
+
/** Hints per run. Default `GENE_LIMITS.hintsPerRun`. */
|
|
14
|
+
hintsPerRun?: number;
|
|
15
|
+
}
|
|
16
|
+
/** What `before()` learned and `after()` needs. */
|
|
17
|
+
export interface HintCall {
|
|
18
|
+
tool: string;
|
|
19
|
+
/** Names seen for the first time on this call: the tool, the shell command's first word. */
|
|
20
|
+
newNames: string[];
|
|
21
|
+
digest: string;
|
|
22
|
+
/** The same call failed within the last ten, so this one is a retry. */
|
|
23
|
+
retry: boolean;
|
|
24
|
+
/** Set on the way in when the engine is off, so `after` is a no-op. */
|
|
25
|
+
skip: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** `(tool, args)` as a short stable key: the same call with the same arguments hashes the same. */
|
|
28
|
+
export declare function argsDigest(tool: string, params: unknown): string;
|
|
29
|
+
/**
|
|
30
|
+
* The command a `bash` call is really about: its first word, skipping `NAME=value` prefixes and a
|
|
31
|
+
* leading `cd dir &&`. `''` when there is none. Lower-cased, path and extension removed
|
|
32
|
+
* (`C:\tools\Docker.exe` -> `docker`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function commandWord(command: unknown): string;
|
|
35
|
+
/**
|
|
36
|
+
* The text a failure is searched by: error codes first, then up to ten plain words, with paths,
|
|
37
|
+
* URLs, ids, hashes and numbers removed (9.4). Never contains the command line, so a secret on it
|
|
38
|
+
* cannot reach a query. `label` (default none) leads when given: a failure query is the error
|
|
39
|
+
* text, and an anchor that no gene mentions only dilutes the match.
|
|
40
|
+
*/
|
|
41
|
+
export declare function normaliseErrorQuery(text: string, label?: string): string;
|
|
42
|
+
/** The hint paragraph for `hits`, within `GENE_LIMITS.hintMaxChars`; null when nothing fits. */
|
|
43
|
+
export declare function renderHintBlock(hits: readonly GeneHintHit[]): {
|
|
44
|
+
text: string;
|
|
45
|
+
shown: GeneHintHit[];
|
|
46
|
+
} | null;
|
|
47
|
+
export declare class GeneHintEngine {
|
|
48
|
+
private readonly ports;
|
|
49
|
+
/** Tool names and command words used so far this SESSION (survives run boundaries). */
|
|
50
|
+
private readonly seenNames;
|
|
51
|
+
private recent;
|
|
52
|
+
/** Per-RUN state: reset when the actor's run id changes. */
|
|
53
|
+
private runId;
|
|
54
|
+
private readonly hintedGenes;
|
|
55
|
+
private hintCount;
|
|
56
|
+
private lastFailureQuery;
|
|
57
|
+
private userRetry;
|
|
58
|
+
/** Milliseconds the last `before` + `after` pair cost, for the 8 ms budget test. */
|
|
59
|
+
lastCostMs: number;
|
|
60
|
+
private startedAt;
|
|
61
|
+
constructor(ports: GeneHintPorts);
|
|
62
|
+
/** `/retry`: the next tool result repeats the last failure's lookup at the retry floor. */
|
|
63
|
+
markUserRetry(): void;
|
|
64
|
+
/** Forget everything (`/clear`, `/resume`). */
|
|
65
|
+
reset(): void;
|
|
66
|
+
private resetRun;
|
|
67
|
+
private isActive;
|
|
68
|
+
/** Called with the tool name and raw arguments BEFORE the tool runs. Never throws. */
|
|
69
|
+
before(tool: string, params: unknown): HintCall;
|
|
70
|
+
private noteNames;
|
|
71
|
+
/** The tool threw instead of returning: that is a failure for retry detection, never a hint. */
|
|
72
|
+
noteThrown(call: HintCall): void;
|
|
73
|
+
/**
|
|
74
|
+
* Called with the finished result. Returns the text to append (it starts with the sentinel) or
|
|
75
|
+
* '' for no hint. Never throws.
|
|
76
|
+
*/
|
|
77
|
+
after(call: HintCall, result: ToolResult): string;
|
|
78
|
+
/** Which lookup this call earns, if any: failure, user retry, or first use of a name. */
|
|
79
|
+
private planLookup;
|
|
80
|
+
private takeUserRetry;
|
|
81
|
+
private lookup;
|
|
82
|
+
}
|
|
83
|
+
/** Append the hint to the last text block, or add a text block when the result has none. */
|
|
84
|
+
export declare function appendHint(result: ToolResult, hint: string): ToolResult;
|
|
85
|
+
/**
|
|
86
|
+
* Decorate one tool. Tools the engine never hints are returned UNCHANGED (the same object), so the
|
|
87
|
+
* decorated array differs from the plain one only where a hint can appear. The wrapper is applied
|
|
88
|
+
* INSIDE the host's gates (the confirmation, approval, mode and ceiling wrappers), so a call a
|
|
89
|
+
* gate refused never reaches it and carries no hint.
|
|
90
|
+
*/
|
|
91
|
+
export declare function withGeneHints(tool: AgentTool, engine: GeneHintEngine): AgentTool;
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage hints: unfamiliar tool, failure, retry (gene-bank spec 9.4, RV-17, I-1, I-24).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`, and the hint text is read
|
|
5
|
+
* by a MODEL, so it is English too.
|
|
6
|
+
*
|
|
7
|
+
* NO MODEL, NO DISK. Every lookup is one synchronous, in-memory `GeneService.hintSearch`
|
|
8
|
+
* (its own 8 ms CPU budget), so a hint costs the turn nothing it could notice. The engine adds
|
|
9
|
+
* bookkeeping only: which names this session has already used, which calls failed, which genes
|
|
10
|
+
* have already been shown this run.
|
|
11
|
+
*
|
|
12
|
+
* THE HINT IS A TAIL, NOT A PROMPT EDIT. It is appended to the END of a tool result, after a
|
|
13
|
+
* fixed sentinel (`GENE_HINT_SENTINEL`), because nothing mid-run may change the system prompt
|
|
14
|
+
* (9.3). That makes a hint late for the call that triggered it - the real "ahead of time" work is
|
|
15
|
+
* the `<gene_context>` zone and the rules block, and the hint is the backstop for the next call,
|
|
16
|
+
* the retry and the rest of the turn.
|
|
17
|
+
*
|
|
18
|
+
* THE LEARNER MUST NEVER SEE ITS OWN HINT AS EVIDENCE (RV-17). The learner subscribes to the
|
|
19
|
+
* DECORATED result; without the sentinel the library's own suggestion would be distilled back into
|
|
20
|
+
* the library as if it had happened (a self-reinforcing loop, TH-10's cousin). `stripGeneHints`
|
|
21
|
+
* cuts at the sentinel in the ledger, in `errorSignature` and in evidence snapshots. This module
|
|
22
|
+
* is also careful to strip hints from the text it reads itself, so a hint never feeds the next
|
|
23
|
+
* hint's query.
|
|
24
|
+
*
|
|
25
|
+
* A HINT NEVER CHANGES THE OUTCOME. `withGeneHints` returns the same `isError`, the same content
|
|
26
|
+
* blocks in the same order, plus at most one extra paragraph at the end of the last text block.
|
|
27
|
+
* Nothing here throws; any internal fault yields "no hint".
|
|
28
|
+
*/
|
|
29
|
+
import { createHash } from 'node:crypto';
|
|
30
|
+
import { clipEscaped } from '@aragon-agent/tui/model/gene/escape';
|
|
31
|
+
import { GENE_LIMITS } from '@aragon-agent/tui/model/gene/limits';
|
|
32
|
+
import { GENE_HINT_SENTINEL, stripGeneHints } from '@aragon-agent/tui/model/gene/signals';
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Constants (9.4)
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
/** First use of a name: relevance floor and the line cap. */
|
|
37
|
+
const FIRST_USE_MIN = 0.5;
|
|
38
|
+
/** A failure: relevance floor. */
|
|
39
|
+
const FAILURE_MIN = 0.55;
|
|
40
|
+
/** A retry: the floor drops, and one more line is allowed (the cap stays `hintMaxLines`). */
|
|
41
|
+
const RETRY_MIN = 0.45;
|
|
42
|
+
const NORMAL_LINES = 2;
|
|
43
|
+
/** How many of the most recent calls count when looking for "the same call failed already". */
|
|
44
|
+
const RECENT_CALLS = 10;
|
|
45
|
+
const QUERY_CHARS = 160;
|
|
46
|
+
const ERROR_TEXT_CHARS = 600;
|
|
47
|
+
const DIGEST_CHARS = 20_000;
|
|
48
|
+
const HEADER = 'possibly relevant (gene_read opens one):';
|
|
49
|
+
/** Tools that never carry a hint: the library's own, and the three human-interaction ones. */
|
|
50
|
+
const NEVER_HINTED = new Set(['ask_user', 'submit_plan', 'todo_write']);
|
|
51
|
+
/** Whether a tool is decorated at all. Pure; the factory and the tests share it. */
|
|
52
|
+
export function isHintableTool(name) {
|
|
53
|
+
return !name.startsWith('gene_') && !NEVER_HINTED.has(name);
|
|
54
|
+
}
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Pure helpers
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
function stableStringify(value, depth = 0) {
|
|
59
|
+
if (value === null || typeof value !== 'object')
|
|
60
|
+
return JSON.stringify(value) ?? 'null';
|
|
61
|
+
if (depth > 4)
|
|
62
|
+
return '"[deep]"';
|
|
63
|
+
if (Array.isArray(value))
|
|
64
|
+
return `[${value.map((v) => stableStringify(v, depth + 1)).join(',')}]`;
|
|
65
|
+
const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
|
|
66
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v, depth + 1)}`).join(',')}}`;
|
|
67
|
+
}
|
|
68
|
+
/** `(tool, args)` as a short stable key: the same call with the same arguments hashes the same. */
|
|
69
|
+
export function argsDigest(tool, params) {
|
|
70
|
+
let body;
|
|
71
|
+
try {
|
|
72
|
+
body = stableStringify(params).slice(0, DIGEST_CHARS);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
body = '?';
|
|
76
|
+
}
|
|
77
|
+
return createHash('sha1').update(`${tool}\u0000${body}`).digest('hex').slice(0, 16);
|
|
78
|
+
}
|
|
79
|
+
const SEGMENT_SPLIT = /&&|\|\||;|\|/;
|
|
80
|
+
const ENV_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
81
|
+
const PREFIX_COMMANDS = new Set(['cd', 'pushd', 'set', 'export']);
|
|
82
|
+
const QUOTED_WORD = /^(["'])(.*?)\1/;
|
|
83
|
+
function firstWordOf(segment) {
|
|
84
|
+
const text = segment.trim();
|
|
85
|
+
// A quoted executable path may hold spaces ("C:\Program Files\Git\bin\git.exe" status).
|
|
86
|
+
const quoted = QUOTED_WORD.exec(text);
|
|
87
|
+
if (quoted !== null)
|
|
88
|
+
return quoted[2] ?? '';
|
|
89
|
+
for (const word of text.split(/\s+/)) {
|
|
90
|
+
if (word.length > 0 && !ENV_ASSIGNMENT.test(word))
|
|
91
|
+
return word;
|
|
92
|
+
}
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The command a `bash` call is really about: its first word, skipping `NAME=value` prefixes and a
|
|
97
|
+
* leading `cd dir &&`. `''` when there is none. Lower-cased, path and extension removed
|
|
98
|
+
* (`C:\tools\Docker.exe` -> `docker`).
|
|
99
|
+
*/
|
|
100
|
+
export function commandWord(command) {
|
|
101
|
+
if (typeof command !== 'string')
|
|
102
|
+
return '';
|
|
103
|
+
const segments = command.split(SEGMENT_SPLIT);
|
|
104
|
+
for (const segment of segments) {
|
|
105
|
+
const word = firstWordOf(segment);
|
|
106
|
+
if (word.length === 0)
|
|
107
|
+
continue;
|
|
108
|
+
if (PREFIX_COMMANDS.has(word.toLowerCase()))
|
|
109
|
+
continue;
|
|
110
|
+
const base = word.replace(/^["']+|["']+$/g, '').split(/[\\/]/).pop() ?? '';
|
|
111
|
+
const bare = base.replace(/\.(?:exe|cmd|bat|ps1)$/i, '').toLowerCase();
|
|
112
|
+
return /^[a-z][a-z0-9._+-]{0,40}$/.test(bare) ? bare : '';
|
|
113
|
+
}
|
|
114
|
+
return '';
|
|
115
|
+
}
|
|
116
|
+
const ERROR_CODE = /^(?:E[A-Z]{3,}|ERR_[A-Z0-9_]+|EAI_[A-Z0-9_]+|TS\d{4}|CS\d{4}|E\d{4})$/;
|
|
117
|
+
const STOPWORDS = new Set([
|
|
118
|
+
'the', 'and', 'for', 'with', 'from', 'that', 'this', 'was', 'were', 'are', 'not', 'has', 'have',
|
|
119
|
+
'had', 'but', 'you', 'your', 'error', 'errors', 'failed', 'failure', 'fatal', 'warning',
|
|
120
|
+
'exception', 'uncaught', 'unhandled', 'while', 'into', 'exit', 'code',
|
|
121
|
+
]);
|
|
122
|
+
function isScrubbedToken(token) {
|
|
123
|
+
if (/^[a-z]:[\\/]/i.test(token) || /^https?:\/\//i.test(token))
|
|
124
|
+
return true;
|
|
125
|
+
if (/[\\/]/.test(token))
|
|
126
|
+
return true;
|
|
127
|
+
if (/^(?:0x)?[0-9a-f]{6,}$/i.test(token) && /\d/.test(token))
|
|
128
|
+
return true;
|
|
129
|
+
return /^\d+$/.test(token);
|
|
130
|
+
}
|
|
131
|
+
const URL_TEXT = /\bhttps?:\/\/\S+/gi;
|
|
132
|
+
const WIN_PATH_TEXT = /\b[a-z]:[\\/][^\s'"`<>|]*/gi;
|
|
133
|
+
const POSIX_PATH_TEXT = /(?:^|[\s'"(])(?:~|\.{1,2})?\/[^\s'"`<>|)]*/g;
|
|
134
|
+
/** Words shorter than this are noise ("at", "in", "of"); error CODES are exempt. */
|
|
135
|
+
const WORD_MIN = 3;
|
|
136
|
+
/**
|
|
137
|
+
* The text a failure is searched by: error codes first, then up to ten plain words, with paths,
|
|
138
|
+
* URLs, ids, hashes and numbers removed (9.4). Never contains the command line, so a secret on it
|
|
139
|
+
* cannot reach a query. `label` (default none) leads when given: a failure query is the error
|
|
140
|
+
* text, and an anchor that no gene mentions only dilutes the match.
|
|
141
|
+
*/
|
|
142
|
+
export function normaliseErrorQuery(text, label = '') {
|
|
143
|
+
const clean = stripGeneHints(text)
|
|
144
|
+
.replace(/^Error:\s*/, '')
|
|
145
|
+
.replace(/^\$ [^\n]*\n?/, '')
|
|
146
|
+
.slice(0, ERROR_TEXT_CHARS)
|
|
147
|
+
.replace(URL_TEXT, ' ')
|
|
148
|
+
.replace(WIN_PATH_TEXT, ' ')
|
|
149
|
+
.replace(POSIX_PATH_TEXT, ' ');
|
|
150
|
+
const codes = [];
|
|
151
|
+
const words = [];
|
|
152
|
+
for (const raw of clean.split(/[\s,;:()[\]{}"'`<>=]+/)) {
|
|
153
|
+
const token = raw.replace(/^[.\-_]+|[.\-_]+$/g, '');
|
|
154
|
+
if (token.length < 2 || isScrubbedToken(token))
|
|
155
|
+
continue;
|
|
156
|
+
if (ERROR_CODE.test(token)) {
|
|
157
|
+
if (!codes.includes(token))
|
|
158
|
+
codes.push(token);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const lower = token.toLowerCase();
|
|
162
|
+
if (lower.length < WORD_MIN || !/^[a-z][a-z'_-]+$/.test(lower) || STOPWORDS.has(lower))
|
|
163
|
+
continue;
|
|
164
|
+
if (words.length < 10 && !words.includes(lower))
|
|
165
|
+
words.push(lower);
|
|
166
|
+
}
|
|
167
|
+
return [label, ...codes, ...words].filter((part) => part.length > 0).join(' ').slice(0, QUERY_CHARS);
|
|
168
|
+
}
|
|
169
|
+
function textOf(result) {
|
|
170
|
+
return result.content.map((block) => (block.type === 'text' ? block.text : '')).join('\n');
|
|
171
|
+
}
|
|
172
|
+
function blockText(lines) {
|
|
173
|
+
return `\n[gene hint] ${lines.length} ${HEADER}\n${lines.join('\n')}`;
|
|
174
|
+
}
|
|
175
|
+
/** The hint paragraph for `hits`, within `GENE_LIMITS.hintMaxChars`; null when nothing fits. */
|
|
176
|
+
export function renderHintBlock(hits) {
|
|
177
|
+
const max = GENE_LIMITS.hintMaxChars;
|
|
178
|
+
const shown = [];
|
|
179
|
+
const lines = [];
|
|
180
|
+
for (const hit of hits.slice(0, GENE_LIMITS.hintMaxLines)) {
|
|
181
|
+
if (blockText([...lines, hit.line]).length <= max) {
|
|
182
|
+
lines.push(hit.line);
|
|
183
|
+
}
|
|
184
|
+
else if (lines.length === 0) {
|
|
185
|
+
// One over-long line (briefLineMax makes this unreachable today): clip it, never drop it.
|
|
186
|
+
lines.push(clipEscaped(hit.line, max - blockText(['']).length));
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
shown.push(hit);
|
|
192
|
+
}
|
|
193
|
+
return shown.length === 0 ? null : { text: blockText(lines), shown };
|
|
194
|
+
}
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
// The engine
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
export class GeneHintEngine {
|
|
199
|
+
ports;
|
|
200
|
+
/** Tool names and command words used so far this SESSION (survives run boundaries). */
|
|
201
|
+
seenNames = new Set();
|
|
202
|
+
recent = [];
|
|
203
|
+
/** Per-RUN state: reset when the actor's run id changes. */
|
|
204
|
+
runId = null;
|
|
205
|
+
hintedGenes = new Set();
|
|
206
|
+
hintCount = 0;
|
|
207
|
+
lastFailureQuery = null;
|
|
208
|
+
userRetry = false;
|
|
209
|
+
/** Milliseconds the last `before` + `after` pair cost, for the 8 ms budget test. */
|
|
210
|
+
lastCostMs = 0;
|
|
211
|
+
startedAt = 0;
|
|
212
|
+
constructor(ports) {
|
|
213
|
+
this.ports = ports;
|
|
214
|
+
}
|
|
215
|
+
/** `/retry`: the next tool result repeats the last failure's lookup at the retry floor. */
|
|
216
|
+
markUserRetry() {
|
|
217
|
+
this.userRetry = true;
|
|
218
|
+
}
|
|
219
|
+
/** Forget everything (`/clear`, `/resume`). */
|
|
220
|
+
reset() {
|
|
221
|
+
this.seenNames.clear();
|
|
222
|
+
this.recent = [];
|
|
223
|
+
this.resetRun(null);
|
|
224
|
+
this.lastFailureQuery = null;
|
|
225
|
+
this.userRetry = false;
|
|
226
|
+
}
|
|
227
|
+
resetRun(runId) {
|
|
228
|
+
this.runId = runId;
|
|
229
|
+
this.hintedGenes.clear();
|
|
230
|
+
this.hintCount = 0;
|
|
231
|
+
}
|
|
232
|
+
isActive() {
|
|
233
|
+
try {
|
|
234
|
+
return this.ports.active === undefined || this.ports.active();
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/** Called with the tool name and raw arguments BEFORE the tool runs. Never throws. */
|
|
241
|
+
before(tool, params) {
|
|
242
|
+
const call = { tool, newNames: [], digest: '', retry: false, skip: true };
|
|
243
|
+
try {
|
|
244
|
+
if (!this.isActive())
|
|
245
|
+
return call;
|
|
246
|
+
this.startedAt = performance.now();
|
|
247
|
+
const actor = this.ports.actor();
|
|
248
|
+
if (actor.runId !== this.runId)
|
|
249
|
+
this.resetRun(actor.runId);
|
|
250
|
+
call.skip = false;
|
|
251
|
+
call.digest = argsDigest(tool, params);
|
|
252
|
+
call.retry = this.recent.some((r) => r.digest === call.digest && r.failed);
|
|
253
|
+
this.noteNames(call, params);
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
call.skip = true;
|
|
257
|
+
}
|
|
258
|
+
return call;
|
|
259
|
+
}
|
|
260
|
+
noteNames(call, params) {
|
|
261
|
+
const names = [call.tool];
|
|
262
|
+
if (call.tool === 'bash' && params !== null && typeof params === 'object') {
|
|
263
|
+
const word = commandWord(params.command);
|
|
264
|
+
if (word.length > 0)
|
|
265
|
+
names.push(word);
|
|
266
|
+
}
|
|
267
|
+
for (const name of names) {
|
|
268
|
+
if (this.seenNames.has(name))
|
|
269
|
+
continue;
|
|
270
|
+
this.seenNames.add(name);
|
|
271
|
+
call.newNames.push(name);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/** The tool threw instead of returning: that is a failure for retry detection, never a hint. */
|
|
275
|
+
noteThrown(call) {
|
|
276
|
+
if (call.skip)
|
|
277
|
+
return;
|
|
278
|
+
this.recent.push({ digest: call.digest, failed: true });
|
|
279
|
+
if (this.recent.length > RECENT_CALLS)
|
|
280
|
+
this.recent.shift();
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Called with the finished result. Returns the text to append (it starts with the sentinel) or
|
|
284
|
+
* '' for no hint. Never throws.
|
|
285
|
+
*/
|
|
286
|
+
after(call, result) {
|
|
287
|
+
if (call.skip)
|
|
288
|
+
return '';
|
|
289
|
+
try {
|
|
290
|
+
const failed = result.isError === true;
|
|
291
|
+
this.recent.push({ digest: call.digest, failed });
|
|
292
|
+
if (this.recent.length > RECENT_CALLS)
|
|
293
|
+
this.recent.shift();
|
|
294
|
+
const plan = this.planLookup(call, failed, stripGeneHints(textOf(result)));
|
|
295
|
+
const text = plan === null ? '' : this.lookup(plan);
|
|
296
|
+
this.lastCostMs = performance.now() - this.startedAt;
|
|
297
|
+
return text;
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
return '';
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/** Which lookup this call earns, if any: failure, user retry, or first use of a name. */
|
|
304
|
+
planLookup(call, failed, text) {
|
|
305
|
+
if (failed) {
|
|
306
|
+
const query = normaliseErrorQuery(text);
|
|
307
|
+
this.lastFailureQuery = query;
|
|
308
|
+
const userRetry = this.takeUserRetry();
|
|
309
|
+
const retry = call.retry || userRetry;
|
|
310
|
+
return {
|
|
311
|
+
query,
|
|
312
|
+
minRelevance: retry ? RETRY_MIN : FAILURE_MIN,
|
|
313
|
+
lines: retry ? GENE_LIMITS.hintMaxLines : NORMAL_LINES,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (this.takeUserRetry() && this.lastFailureQuery !== null) {
|
|
317
|
+
return { query: this.lastFailureQuery, minRelevance: RETRY_MIN, lines: GENE_LIMITS.hintMaxLines };
|
|
318
|
+
}
|
|
319
|
+
if (call.newNames.length > 0) {
|
|
320
|
+
return { query: call.newNames.join(' '), minRelevance: FIRST_USE_MIN, lines: NORMAL_LINES, types: ['tool', 'knowledge'] };
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
takeUserRetry() {
|
|
325
|
+
const was = this.userRetry;
|
|
326
|
+
this.userRetry = false;
|
|
327
|
+
return was;
|
|
328
|
+
}
|
|
329
|
+
lookup(plan) {
|
|
330
|
+
const cap = this.ports.hintsPerRun ?? GENE_LIMITS.hintsPerRun;
|
|
331
|
+
if (this.hintCount >= cap || plan.query.trim().length === 0)
|
|
332
|
+
return '';
|
|
333
|
+
const actor = this.ports.actor();
|
|
334
|
+
const hits = this.ports.service
|
|
335
|
+
.hintSearch(actor, {
|
|
336
|
+
text: plan.query,
|
|
337
|
+
minRelevance: plan.minRelevance,
|
|
338
|
+
max: GENE_LIMITS.hintMaxLines,
|
|
339
|
+
...(plan.types !== undefined ? { types: plan.types } : {}),
|
|
340
|
+
})
|
|
341
|
+
.filter((hit) => !this.hintedGenes.has(hit.id))
|
|
342
|
+
.slice(0, plan.lines);
|
|
343
|
+
const block = renderHintBlock(hits);
|
|
344
|
+
if (block === null)
|
|
345
|
+
return '';
|
|
346
|
+
for (const hit of block.shown)
|
|
347
|
+
this.hintedGenes.add(hit.id);
|
|
348
|
+
this.hintCount += 1;
|
|
349
|
+
this.ports.service.markHintsShown(actor, block.shown.map((hit) => hit.id));
|
|
350
|
+
return block.text;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// ---------------------------------------------------------------------------
|
|
354
|
+
// The decorator
|
|
355
|
+
// ---------------------------------------------------------------------------
|
|
356
|
+
/** Append the hint to the last text block, or add a text block when the result has none. */
|
|
357
|
+
export function appendHint(result, hint) {
|
|
358
|
+
const blocks = [...result.content];
|
|
359
|
+
const last = blocks[blocks.length - 1];
|
|
360
|
+
if (last !== undefined && last.type === 'text') {
|
|
361
|
+
blocks[blocks.length - 1] = { type: 'text', text: last.text + hint };
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
blocks.push({ type: 'text', text: hint });
|
|
365
|
+
}
|
|
366
|
+
return { ...result, content: blocks };
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Decorate one tool. Tools the engine never hints are returned UNCHANGED (the same object), so the
|
|
370
|
+
* decorated array differs from the plain one only where a hint can appear. The wrapper is applied
|
|
371
|
+
* INSIDE the host's gates (the confirmation, approval, mode and ceiling wrappers), so a call a
|
|
372
|
+
* gate refused never reaches it and carries no hint.
|
|
373
|
+
*/
|
|
374
|
+
export function withGeneHints(tool, engine) {
|
|
375
|
+
if (!isHintableTool(tool.name))
|
|
376
|
+
return tool;
|
|
377
|
+
const original = tool.execute;
|
|
378
|
+
return {
|
|
379
|
+
...tool,
|
|
380
|
+
async execute(callId, params, ctx) {
|
|
381
|
+
const call = engine.before(tool.name, params);
|
|
382
|
+
let result;
|
|
383
|
+
try {
|
|
384
|
+
result = await original(callId, params, ctx);
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
engine.noteThrown(call);
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
const hint = engine.after(call, result);
|
|
391
|
+
return hint.length > 0 && hint.startsWith(GENE_HINT_SENTINEL) ? appendHint(result, hint) : result;
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `GeneActivityHub`: the ONE place that answers "what is the gene bank doing right now"
|
|
3
|
+
* (gene-bank spec 12.8, G-25, I-23).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* TWO KINDS OF FACT, TWO SOURCES. What THIS process knows synchronously (a search is running,
|
|
8
|
+
* the auto context just loaded 12 genes, the learner is reviewing) comes from the injected
|
|
9
|
+
* `HubLocalFacts` and is cheap enough to read on every call. What only the DISK knows (the
|
|
10
|
+
* curator may be a different process entirely - a terminal while you look at the desktop) comes
|
|
11
|
+
* from the tail of `runs/<today>.jsonl`, the lease file and the queue directory counts. The
|
|
12
|
+
* curator's own in-process variables are never trusted for the second kind (12.8 rule 1).
|
|
13
|
+
*
|
|
14
|
+
* ZERO BACKGROUND WORK WITHOUT A LISTENER. Nothing here touches the disk until the first
|
|
15
|
+
* `subscribe`, and the last `unsubscribe` cancels the poll timer. `view()` stays available with
|
|
16
|
+
* no subscriber - it just shows the file facts as of the last `refresh()`.
|
|
17
|
+
*
|
|
18
|
+
* THROTTLED, ALWAYS COMPARED. Listeners are notified at most 4 times a second, and only when
|
|
19
|
+
* `viewsEqual` says something observable changed (`revision` alone is not a change). A burst of
|
|
20
|
+
* local events inside one window collapses into one trailing emit, so no state is lost to the
|
|
21
|
+
* throttle - it is merely delayed by at most the window.
|
|
22
|
+
*
|
|
23
|
+
* CONVENTIONS THE CURATOR'S RECORDS FOLLOW (documented here because this file is the reader):
|
|
24
|
+
* `detail: 'name=<gene-name>'` on a stage record names the gene being worked on, and
|
|
25
|
+
* `detail: 'stage=publishing'` on a `validating` record marks the publish step (there is no
|
|
26
|
+
* separate run event for it). Both are optional; a record without them still moves the state.
|
|
27
|
+
*/
|
|
28
|
+
import type { GenePausedReason, GeneRunEvent, GeneRunRecord, GeneSessionView, GeneStage } from '@aragon-agent/tui/model/gene/types';
|
|
29
|
+
import type { LockInfo } from '../governance/store/run-lock.js';
|
|
30
|
+
import { type GenePathContext } from './paths.js';
|
|
31
|
+
import type { GeneRunLog, RunLogPage, RunLogReadOptions } from './runlog.js';
|
|
32
|
+
import type { QueueCounts } from './queue.js';
|
|
33
|
+
import type { GeneHintStore } from './ui-hints.js';
|
|
34
|
+
export declare const HUB_POLL_MS = 1500;
|
|
35
|
+
export declare const HUB_MIN_EMIT_MS = 250;
|
|
36
|
+
/** What the hub asks the rest of this process. All synchronous and cheap. */
|
|
37
|
+
export interface HubLocalFacts {
|
|
38
|
+
available(): boolean;
|
|
39
|
+
use(): boolean;
|
|
40
|
+
autoLearn(): boolean;
|
|
41
|
+
library(): GeneSessionView['library'];
|
|
42
|
+
context(): GeneSessionView['context'];
|
|
43
|
+
/** A search / context plan is in progress NOW. */
|
|
44
|
+
retrieving(): boolean;
|
|
45
|
+
learner(): GeneSessionView['learner'];
|
|
46
|
+
/** A reason THIS process knows the curator cannot work (for instance, no fast model). */
|
|
47
|
+
curatorPausedReason?(): GenePausedReason | undefined;
|
|
48
|
+
/** Refresh anything file-backed on the facts' side (the learner's daily budget). */
|
|
49
|
+
refresh?(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
/** Timers behind an interface so tests drive time by hand. */
|
|
52
|
+
export interface HubScheduler {
|
|
53
|
+
every(ms: number, fn: () => void): () => void;
|
|
54
|
+
after(ms: number, fn: () => void): () => void;
|
|
55
|
+
}
|
|
56
|
+
export declare const realScheduler: HubScheduler;
|
|
57
|
+
export interface HubDeps {
|
|
58
|
+
ctx?: Pick<GenePathContext, 'root'>;
|
|
59
|
+
facts: HubLocalFacts;
|
|
60
|
+
queue: {
|
|
61
|
+
counts(): Promise<QueueCounts>;
|
|
62
|
+
};
|
|
63
|
+
runLog: Pick<GeneRunLog, 'tailFrom' | 'tailInit' | 'read'>;
|
|
64
|
+
now: () => number;
|
|
65
|
+
pid: number;
|
|
66
|
+
isPidAlive?: (pid: number) => boolean;
|
|
67
|
+
scheduler?: HubScheduler;
|
|
68
|
+
pollMs?: number;
|
|
69
|
+
minEmitMs?: number;
|
|
70
|
+
leaseStaleMs?: number;
|
|
71
|
+
/** Test seam; defaults to reading `lock/curator.lease`. */
|
|
72
|
+
readLease?: () => Promise<LockInfo | null>;
|
|
73
|
+
/** Where "this hint was already shown" lives. Absent: the hub never raises a hint. */
|
|
74
|
+
hints?: GeneHintStore;
|
|
75
|
+
}
|
|
76
|
+
export interface CuratorFold {
|
|
77
|
+
working: boolean;
|
|
78
|
+
stage?: GeneStage;
|
|
79
|
+
geneName?: string;
|
|
80
|
+
proposalId?: string;
|
|
81
|
+
paused?: GenePausedReason;
|
|
82
|
+
last?: {
|
|
83
|
+
ev: GeneRunEvent;
|
|
84
|
+
t: number;
|
|
85
|
+
detail?: string;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Apply one run record to the curator state. Learner-side events (`reviewing`, `reviewed_none`,
|
|
90
|
+
* `proposed`, `queued`, `merged_into_pending`) deliberately change nothing here: they describe
|
|
91
|
+
* the session that wrote them, not the curator.
|
|
92
|
+
*/
|
|
93
|
+
export declare function foldCuratorRecord(fold: CuratorFold, record: GeneRunRecord): CuratorFold;
|
|
94
|
+
export declare class GeneActivityHub {
|
|
95
|
+
private readonly deps;
|
|
96
|
+
private readonly scheduler;
|
|
97
|
+
private readonly isPidAlive;
|
|
98
|
+
private readonly listeners;
|
|
99
|
+
private fold;
|
|
100
|
+
private fileFacts;
|
|
101
|
+
private tail;
|
|
102
|
+
private latest;
|
|
103
|
+
private revision;
|
|
104
|
+
private notifiedRevision;
|
|
105
|
+
private lastEmitAt;
|
|
106
|
+
private stopPolling;
|
|
107
|
+
private cancelTrailing;
|
|
108
|
+
private refreshing;
|
|
109
|
+
private refreshAgain;
|
|
110
|
+
private disposed;
|
|
111
|
+
/** A first publish or first queued proposal was seen LIVE (not in the initial tail). */
|
|
112
|
+
private hintTrigger;
|
|
113
|
+
private hint;
|
|
114
|
+
constructor(deps: HubDeps);
|
|
115
|
+
/** The current view: local facts read now, file facts as of the last `refresh()`. */
|
|
116
|
+
view(): GeneSessionView;
|
|
117
|
+
private compose;
|
|
118
|
+
private curatorView;
|
|
119
|
+
/** Paged processing log for the "expand" views; newest first. */
|
|
120
|
+
records(options: RunLogReadOptions): Promise<RunLogPage>;
|
|
121
|
+
/** Listen for changes. The first listener starts polling; the last one's removal stops it. */
|
|
122
|
+
subscribe(listener: () => void): () => void;
|
|
123
|
+
/** Whether any file work is scheduled; the test for "no listener, no background I/O". */
|
|
124
|
+
isPolling(): boolean;
|
|
125
|
+
/** A local synchronous event happened (search started, learner state changed). */
|
|
126
|
+
notify(): void;
|
|
127
|
+
/** Re-read the file facts now and emit if anything changed. Never rejects. */
|
|
128
|
+
refresh(): Promise<void>;
|
|
129
|
+
dispose(): void;
|
|
130
|
+
private startPolling;
|
|
131
|
+
private stopAll;
|
|
132
|
+
private requestEmit;
|
|
133
|
+
/** Notify listeners if the view changed since they were last told. */
|
|
134
|
+
private flush;
|
|
135
|
+
private refreshOnce;
|
|
136
|
+
/** `self` / `other` / `none` from the lease file; a stale heartbeat or a dead pid is `none`. */
|
|
137
|
+
private readHolder;
|
|
138
|
+
private advanceTail;
|
|
139
|
+
/** `live`: the records are new since the last look, not the history read at start-up. */
|
|
140
|
+
private apply;
|
|
141
|
+
/**
|
|
142
|
+
* U-1: the first publish or queued proposal tells the user once how to open the manager. The hint
|
|
143
|
+
* is recorded as seen BEFORE it is raised, so a second process or a later session stays quiet; an
|
|
144
|
+
* unreadable state file reads as "already seen" (see `GeneUiHints`). Off or unavailable: never.
|
|
145
|
+
*/
|
|
146
|
+
private raiseHint;
|
|
147
|
+
/** First look at a day: fold the last stretch of the file so the CURRENT state is known. */
|
|
148
|
+
private initTail;
|
|
149
|
+
}
|