@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,220 @@
|
|
|
1
|
+
export declare const LEDGER_LIMITS: {
|
|
2
|
+
readonly maxBytes: number;
|
|
3
|
+
readonly userText: 600;
|
|
4
|
+
readonly usersMax: 24;
|
|
5
|
+
readonly goalMax: 500;
|
|
6
|
+
readonly callsMax: 80;
|
|
7
|
+
readonly argText: 160;
|
|
8
|
+
readonly errText: 300;
|
|
9
|
+
readonly arcsMax: 8;
|
|
10
|
+
/** A repair counts only if the same tool succeeds within this many calls of the failure. */
|
|
11
|
+
readonly arcWindow: 6;
|
|
12
|
+
readonly genesMax: 60;
|
|
13
|
+
readonly turnsMax: 12;
|
|
14
|
+
readonly turnTail: 300;
|
|
15
|
+
readonly filesMax: 30;
|
|
16
|
+
readonly fileText: 200;
|
|
17
|
+
readonly childText: 400;
|
|
18
|
+
readonly childrenMax: 8;
|
|
19
|
+
readonly priorTurns: 2;
|
|
20
|
+
readonly priorGoal: 200;
|
|
21
|
+
};
|
|
22
|
+
export type GeneFeedbackVerdict = 'helped' | 'misleading' | 'not_applicable' | 'outdated';
|
|
23
|
+
/** What the gene subsystem tells the learner (the controller forwards these). */
|
|
24
|
+
export type GeneLedgerEvent = {
|
|
25
|
+
kind: 'shown';
|
|
26
|
+
geneIds: readonly string[];
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'search';
|
|
29
|
+
query: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'read';
|
|
32
|
+
geneId: string;
|
|
33
|
+
tier: 2 | 3;
|
|
34
|
+
version?: number;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'feedback';
|
|
37
|
+
geneId: string;
|
|
38
|
+
verdict: GeneFeedbackVerdict;
|
|
39
|
+
}
|
|
40
|
+
/** A `gene_run` result: a deterministic outcome for that gene, no model needed. */
|
|
41
|
+
| {
|
|
42
|
+
kind: 'run_result';
|
|
43
|
+
geneId: string;
|
|
44
|
+
ok: boolean;
|
|
45
|
+
} | {
|
|
46
|
+
kind: 'unfamiliar_recovery';
|
|
47
|
+
};
|
|
48
|
+
export type RunOutcome = 'completed' | 'error' | 'aborted';
|
|
49
|
+
interface Sized {
|
|
50
|
+
seq: number;
|
|
51
|
+
size: number;
|
|
52
|
+
signalled: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface LedgerUser extends Sized {
|
|
55
|
+
text: string;
|
|
56
|
+
correction: boolean;
|
|
57
|
+
statedFact: boolean;
|
|
58
|
+
afterAction: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface LedgerCall extends Sized {
|
|
61
|
+
id: string;
|
|
62
|
+
tool: string;
|
|
63
|
+
arg?: string;
|
|
64
|
+
ok: boolean;
|
|
65
|
+
err?: string;
|
|
66
|
+
ms: number;
|
|
67
|
+
sig?: string;
|
|
68
|
+
turn: number;
|
|
69
|
+
}
|
|
70
|
+
export interface LedgerArc extends Sized {
|
|
71
|
+
sig: string;
|
|
72
|
+
tool: string;
|
|
73
|
+
/** Calls between the failure and the success. */
|
|
74
|
+
gap: number;
|
|
75
|
+
/** Some other tool ran in between: an actual repair, not a plain retry. */
|
|
76
|
+
viaFix: boolean;
|
|
77
|
+
}
|
|
78
|
+
export interface LedgerGene extends Sized {
|
|
79
|
+
kind: 'search' | 'read' | 'feedback' | 'run_result';
|
|
80
|
+
geneId?: string;
|
|
81
|
+
query?: string;
|
|
82
|
+
version?: number;
|
|
83
|
+
tier?: 2 | 3;
|
|
84
|
+
verdict?: GeneFeedbackVerdict;
|
|
85
|
+
ok?: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface LedgerTurn extends Sized {
|
|
88
|
+
index: number;
|
|
89
|
+
tail: string;
|
|
90
|
+
}
|
|
91
|
+
export interface LedgerRead {
|
|
92
|
+
seq: number;
|
|
93
|
+
tier: 2 | 3;
|
|
94
|
+
version?: number;
|
|
95
|
+
}
|
|
96
|
+
export interface LedgerCounters {
|
|
97
|
+
userCorrections: number;
|
|
98
|
+
correctionAfterAction: number;
|
|
99
|
+
statedFacts: number;
|
|
100
|
+
toolCalls: number;
|
|
101
|
+
toolErrors: number;
|
|
102
|
+
retries: number;
|
|
103
|
+
arcs: number;
|
|
104
|
+
flaggedFeedback: number;
|
|
105
|
+
unfamiliarRecoveries: number;
|
|
106
|
+
turns: number;
|
|
107
|
+
}
|
|
108
|
+
export interface LedgerSnapshot {
|
|
109
|
+
/** Which run this describes. A watermark from another run says nothing about this one. */
|
|
110
|
+
run: number;
|
|
111
|
+
active: boolean;
|
|
112
|
+
goal: string;
|
|
113
|
+
prior?: {
|
|
114
|
+
goal: string;
|
|
115
|
+
tails: readonly string[];
|
|
116
|
+
};
|
|
117
|
+
users: readonly LedgerUser[];
|
|
118
|
+
calls: readonly LedgerCall[];
|
|
119
|
+
arcs: readonly LedgerArc[];
|
|
120
|
+
genes: readonly LedgerGene[];
|
|
121
|
+
turns: readonly LedgerTurn[];
|
|
122
|
+
files: readonly string[];
|
|
123
|
+
children: readonly string[];
|
|
124
|
+
counters: LedgerCounters;
|
|
125
|
+
/** Failed-call count per error signature, whole run. */
|
|
126
|
+
sigCounts: ReadonlyMap<string, number>;
|
|
127
|
+
reads: ReadonlyMap<string, LedgerRead>;
|
|
128
|
+
feedback: ReadonlyMap<string, GeneFeedbackVerdict>;
|
|
129
|
+
runResults: ReadonlyMap<string, boolean>;
|
|
130
|
+
shown: ReadonlySet<string>;
|
|
131
|
+
outcome: RunOutcome | 'running';
|
|
132
|
+
todoAllDone: boolean;
|
|
133
|
+
lastVerifyOk: boolean;
|
|
134
|
+
bytes: number;
|
|
135
|
+
}
|
|
136
|
+
/** A frozen copy of the countable facts, used to ask "what is NEW since the last learning call". */
|
|
137
|
+
export interface LedgerWatermark {
|
|
138
|
+
/** The run it was taken in; `factsFromLedger` ignores it once a new run has begun. */
|
|
139
|
+
run: number;
|
|
140
|
+
counters: LedgerCounters;
|
|
141
|
+
sigCounts: ReadonlyMap<string, number>;
|
|
142
|
+
/** Genes already read when the mark was taken: the learning call has attributed those. */
|
|
143
|
+
readIds: ReadonlySet<string>;
|
|
144
|
+
}
|
|
145
|
+
export interface LedgerDeps {
|
|
146
|
+
knownSecrets?: () => readonly string[];
|
|
147
|
+
maxBytes?: number;
|
|
148
|
+
}
|
|
149
|
+
/** The one argument a tool call is worth naming (same keys as the fast reviewer's digest). */
|
|
150
|
+
export declare function pickArg(args: unknown): string | undefined;
|
|
151
|
+
/** A call whose success means "the work was checked": a test / build / lint style command. */
|
|
152
|
+
export declare function isVerifyCall(tool: string, arg: string | undefined): boolean;
|
|
153
|
+
export declare function isFileTool(tool: string): boolean;
|
|
154
|
+
export declare class EvidenceLedger {
|
|
155
|
+
private readonly deps;
|
|
156
|
+
private readonly maxBytes;
|
|
157
|
+
private seq;
|
|
158
|
+
private runSerial;
|
|
159
|
+
private active;
|
|
160
|
+
private sessionActed;
|
|
161
|
+
private goal;
|
|
162
|
+
private prior;
|
|
163
|
+
private users;
|
|
164
|
+
private calls;
|
|
165
|
+
private arcs;
|
|
166
|
+
private genes;
|
|
167
|
+
private turns;
|
|
168
|
+
private files;
|
|
169
|
+
private children;
|
|
170
|
+
private counters;
|
|
171
|
+
private sigCounts;
|
|
172
|
+
private reads;
|
|
173
|
+
private feedback;
|
|
174
|
+
private runResults;
|
|
175
|
+
private shown;
|
|
176
|
+
private pending;
|
|
177
|
+
private openFailures;
|
|
178
|
+
private outcome;
|
|
179
|
+
private todoAllDone;
|
|
180
|
+
private lastVerifyOk;
|
|
181
|
+
private turnIndex;
|
|
182
|
+
constructor(deps?: LedgerDeps);
|
|
183
|
+
/** Start a new run. A little of the previous run is kept so a correction has something to refer to. */
|
|
184
|
+
beginRun(): void;
|
|
185
|
+
/** `/clear`, `/resume`, exit: forget everything, including that the agent ever acted. */
|
|
186
|
+
resetSession(): void;
|
|
187
|
+
isActive(): boolean;
|
|
188
|
+
/** Mark the run over. The content stays readable until the next `beginRun`. */
|
|
189
|
+
finishRun(outcome: RunOutcome, todoAllDone: boolean): void;
|
|
190
|
+
private carryOver;
|
|
191
|
+
private clearRunState;
|
|
192
|
+
private ensureRun;
|
|
193
|
+
/** Hint-stripped, secret-scrubbed, clipped. The only way text enters the ledger. */
|
|
194
|
+
private clean;
|
|
195
|
+
addUser(text: string): void;
|
|
196
|
+
startCall(id: string, tool: string, args: unknown): void;
|
|
197
|
+
endCall(args: {
|
|
198
|
+
id: string;
|
|
199
|
+
tool: string;
|
|
200
|
+
isError: boolean;
|
|
201
|
+
text: string;
|
|
202
|
+
ms: number;
|
|
203
|
+
}): void;
|
|
204
|
+
/** A success closes the open failures of the same tool that are still inside the window. */
|
|
205
|
+
private recordRecovery;
|
|
206
|
+
endTurn(tail: string): void;
|
|
207
|
+
addGeneEvent(event: GeneLedgerEvent): void;
|
|
208
|
+
private noteFeedback;
|
|
209
|
+
private pushGene;
|
|
210
|
+
addChild(summary: string): void;
|
|
211
|
+
noteRetry(): void;
|
|
212
|
+
private push;
|
|
213
|
+
private trimCount;
|
|
214
|
+
private totalBytes;
|
|
215
|
+
/** Over 24 KB: unsignalled turns, then calls, users, genes go first; then the oldest signalled. */
|
|
216
|
+
private enforceTotal;
|
|
217
|
+
snapshot(): LedgerSnapshot;
|
|
218
|
+
watermark(): LedgerWatermark;
|
|
219
|
+
}
|
|
220
|
+
export {};
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The evidence ledger: a bounded, in-memory record of what happened in a run (gene-bank spec
|
|
3
|
+
* 10.1.1, I-16, RV-17).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* NEVER PERSISTED. The ledger lives in this process and is dropped on `/clear`, `/resume` and
|
|
8
|
+
* exit. The only thing that ever leaves it is a PROJECTION built for one learning call
|
|
9
|
+
* (`learn-prompt.ts`), and only after the local gate (`signals-port.ts`) found a reason to pay
|
|
10
|
+
* for that call.
|
|
11
|
+
*
|
|
12
|
+
* EVERY TEXT IS CLEANED ON THE WAY IN, nowhere else: first `stripGeneHints` (the learner sees
|
|
13
|
+
* tool results AFTER the hint engine decorated them - without stripping, the library's own
|
|
14
|
+
* advice would be distilled back into the library, RV-17), then `redactSecrets`, then clipped.
|
|
15
|
+
* Downstream code - the projection, the evidence check, the signatures - can therefore treat
|
|
16
|
+
* ledger text as already safe. The one exception is the error SIGNATURE, hashed from the
|
|
17
|
+
* stripped-but-not-redacted text so it matches `KnowledgePayload.resolves` (both come from
|
|
18
|
+
* `errorSignature`); a hash cannot leak what it hashes.
|
|
19
|
+
*
|
|
20
|
+
* BOUNDED TWO WAYS: per-array entry counts, and a 24 KB total. Over the total, UNSIGNALLED
|
|
21
|
+
* frames go first (an ordinary successful call tells the reviewer nothing), oldest first, and
|
|
22
|
+
* signalled frames last - a user's correction is the last thing to be forgotten.
|
|
23
|
+
*/
|
|
24
|
+
import { detectStatedFact, detectUserCorrection, errorSignature, stripGeneHints, } from '@aragon-agent/tui/model/gene/signals';
|
|
25
|
+
import { redactSecrets } from '../secrets.js';
|
|
26
|
+
export const LEDGER_LIMITS = {
|
|
27
|
+
maxBytes: 24 * 1024,
|
|
28
|
+
userText: 600,
|
|
29
|
+
usersMax: 24,
|
|
30
|
+
goalMax: 500,
|
|
31
|
+
callsMax: 80,
|
|
32
|
+
argText: 160,
|
|
33
|
+
errText: 300,
|
|
34
|
+
arcsMax: 8,
|
|
35
|
+
/** A repair counts only if the same tool succeeds within this many calls of the failure. */
|
|
36
|
+
arcWindow: 6,
|
|
37
|
+
genesMax: 60,
|
|
38
|
+
turnsMax: 12,
|
|
39
|
+
turnTail: 300,
|
|
40
|
+
filesMax: 30,
|
|
41
|
+
fileText: 200,
|
|
42
|
+
childText: 400,
|
|
43
|
+
childrenMax: 8,
|
|
44
|
+
priorTurns: 2,
|
|
45
|
+
priorGoal: 200,
|
|
46
|
+
};
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Pure helpers
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
function emptyCounters() {
|
|
51
|
+
return {
|
|
52
|
+
userCorrections: 0,
|
|
53
|
+
correctionAfterAction: 0,
|
|
54
|
+
statedFacts: 0,
|
|
55
|
+
toolCalls: 0,
|
|
56
|
+
toolErrors: 0,
|
|
57
|
+
retries: 0,
|
|
58
|
+
arcs: 0,
|
|
59
|
+
flaggedFeedback: 0,
|
|
60
|
+
unfamiliarRecoveries: 0,
|
|
61
|
+
turns: 0,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function clipPoints(text, max) {
|
|
65
|
+
const points = Array.from(text);
|
|
66
|
+
return points.length <= max ? text : `${points.slice(0, max - 3).join('')}...`;
|
|
67
|
+
}
|
|
68
|
+
/** The one argument a tool call is worth naming (same keys as the fast reviewer's digest). */
|
|
69
|
+
export function pickArg(args) {
|
|
70
|
+
const a = (args ?? {});
|
|
71
|
+
for (const key of ['path', 'file_path', 'pattern', 'command', 'query', 'label']) {
|
|
72
|
+
const value = a[key];
|
|
73
|
+
if (typeof value === 'string' && value.length > 0)
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const SHELL_TOOL_RE = /^(?:bash|shell|powershell|pwsh|cmd|exec|run_command|execute_command)$/i;
|
|
79
|
+
const VERIFY_RE = /\b(?:test|tests|vitest|jest|pytest|mocha|tsc|typecheck|lint|build|verify|cargo\s+(?:test|check|build)|go\s+(?:test|build|vet)|dotnet\s+(?:test|build))\b/i;
|
|
80
|
+
const FILE_TOOL_RE = /^(?:write_file|edit_file|write|edit|apply_patch|multi_edit|create_file)$/i;
|
|
81
|
+
/** A call whose success means "the work was checked": a test / build / lint style command. */
|
|
82
|
+
export function isVerifyCall(tool, arg) {
|
|
83
|
+
return SHELL_TOOL_RE.test(tool) && arg !== undefined && VERIFY_RE.test(arg);
|
|
84
|
+
}
|
|
85
|
+
export function isFileTool(tool) {
|
|
86
|
+
return FILE_TOOL_RE.test(tool);
|
|
87
|
+
}
|
|
88
|
+
/** The optional version, spread-ready: absent stays absent. */
|
|
89
|
+
function versionOf(event) {
|
|
90
|
+
return event.version ? { version: event.version } : {};
|
|
91
|
+
}
|
|
92
|
+
function approxSize(entry) {
|
|
93
|
+
return JSON.stringify(entry).length;
|
|
94
|
+
}
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// The ledger
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
export class EvidenceLedger {
|
|
99
|
+
deps;
|
|
100
|
+
maxBytes;
|
|
101
|
+
seq = 0;
|
|
102
|
+
runSerial = 0;
|
|
103
|
+
active = false;
|
|
104
|
+
sessionActed = false;
|
|
105
|
+
goal = '';
|
|
106
|
+
prior;
|
|
107
|
+
users = [];
|
|
108
|
+
calls = [];
|
|
109
|
+
arcs = [];
|
|
110
|
+
genes = [];
|
|
111
|
+
turns = [];
|
|
112
|
+
files = [];
|
|
113
|
+
children = [];
|
|
114
|
+
counters = emptyCounters();
|
|
115
|
+
sigCounts = new Map();
|
|
116
|
+
reads = new Map();
|
|
117
|
+
feedback = new Map();
|
|
118
|
+
runResults = new Map();
|
|
119
|
+
shown = new Set();
|
|
120
|
+
pending = new Map();
|
|
121
|
+
openFailures = [];
|
|
122
|
+
outcome = 'running';
|
|
123
|
+
todoAllDone = false;
|
|
124
|
+
lastVerifyOk = false;
|
|
125
|
+
turnIndex = 0;
|
|
126
|
+
constructor(deps = {}) {
|
|
127
|
+
this.deps = deps;
|
|
128
|
+
this.maxBytes = deps.maxBytes ?? LEDGER_LIMITS.maxBytes;
|
|
129
|
+
}
|
|
130
|
+
// ---- lifecycle ----------------------------------------------------------
|
|
131
|
+
/** Start a new run. A little of the previous run is kept so a correction has something to refer to. */
|
|
132
|
+
beginRun() {
|
|
133
|
+
const carried = this.carryOver();
|
|
134
|
+
this.clearRunState();
|
|
135
|
+
this.prior = carried;
|
|
136
|
+
this.runSerial += 1;
|
|
137
|
+
this.active = true;
|
|
138
|
+
}
|
|
139
|
+
/** `/clear`, `/resume`, exit: forget everything, including that the agent ever acted. */
|
|
140
|
+
resetSession() {
|
|
141
|
+
this.clearRunState();
|
|
142
|
+
this.prior = undefined;
|
|
143
|
+
this.sessionActed = false;
|
|
144
|
+
this.runSerial += 1;
|
|
145
|
+
this.active = false;
|
|
146
|
+
}
|
|
147
|
+
isActive() {
|
|
148
|
+
return this.active;
|
|
149
|
+
}
|
|
150
|
+
/** Mark the run over. The content stays readable until the next `beginRun`. */
|
|
151
|
+
finishRun(outcome, todoAllDone) {
|
|
152
|
+
this.outcome = outcome;
|
|
153
|
+
this.todoAllDone = todoAllDone;
|
|
154
|
+
this.active = false;
|
|
155
|
+
}
|
|
156
|
+
carryOver() {
|
|
157
|
+
if (this.goal === '' && this.turns.length === 0)
|
|
158
|
+
return undefined;
|
|
159
|
+
const tails = this.turns.slice(-LEDGER_LIMITS.priorTurns).map((t) => t.tail);
|
|
160
|
+
return { goal: clipPoints(this.goal, LEDGER_LIMITS.priorGoal), tails };
|
|
161
|
+
}
|
|
162
|
+
clearRunState() {
|
|
163
|
+
this.goal = '';
|
|
164
|
+
this.users = [];
|
|
165
|
+
this.calls = [];
|
|
166
|
+
this.arcs = [];
|
|
167
|
+
this.genes = [];
|
|
168
|
+
this.turns = [];
|
|
169
|
+
this.files = [];
|
|
170
|
+
this.children = [];
|
|
171
|
+
this.counters = emptyCounters();
|
|
172
|
+
this.sigCounts = new Map();
|
|
173
|
+
this.reads = new Map();
|
|
174
|
+
this.feedback = new Map();
|
|
175
|
+
this.runResults = new Map();
|
|
176
|
+
this.shown = new Set();
|
|
177
|
+
this.pending = new Map();
|
|
178
|
+
this.openFailures = [];
|
|
179
|
+
this.outcome = 'running';
|
|
180
|
+
this.todoAllDone = false;
|
|
181
|
+
this.lastVerifyOk = false;
|
|
182
|
+
this.turnIndex = 0;
|
|
183
|
+
}
|
|
184
|
+
ensureRun() {
|
|
185
|
+
if (!this.active)
|
|
186
|
+
this.beginRun();
|
|
187
|
+
}
|
|
188
|
+
// ---- cleaning ------------------------------------------------------------
|
|
189
|
+
/** Hint-stripped, secret-scrubbed, clipped. The only way text enters the ledger. */
|
|
190
|
+
clean(text, max) {
|
|
191
|
+
const stripped = stripGeneHints(typeof text === 'string' ? text : '');
|
|
192
|
+
const redacted = redactSecrets(stripped, this.deps.knownSecrets?.() ?? []).text;
|
|
193
|
+
return clipPoints(redacted.replace(/\s+$/g, ''), max);
|
|
194
|
+
}
|
|
195
|
+
// ---- inputs ------------------------------------------------------------------
|
|
196
|
+
addUser(text) {
|
|
197
|
+
this.ensureRun();
|
|
198
|
+
const clean = this.clean(text, LEDGER_LIMITS.userText);
|
|
199
|
+
if (clean.length === 0)
|
|
200
|
+
return;
|
|
201
|
+
const correction = detectUserCorrection(clean);
|
|
202
|
+
const statedFact = detectStatedFact(clean);
|
|
203
|
+
const afterAction = this.sessionActed;
|
|
204
|
+
if (this.goal === '')
|
|
205
|
+
this.goal = clipPoints(clean, LEDGER_LIMITS.goalMax);
|
|
206
|
+
this.counters.userCorrections += correction ? 1 : 0;
|
|
207
|
+
this.counters.correctionAfterAction += correction && afterAction ? 1 : 0;
|
|
208
|
+
this.counters.statedFacts += statedFact ? 1 : 0;
|
|
209
|
+
this.push(this.users, { text: clean, correction, statedFact, afterAction }, correction || statedFact);
|
|
210
|
+
this.trimCount(this.users, LEDGER_LIMITS.usersMax);
|
|
211
|
+
}
|
|
212
|
+
startCall(id, tool, args) {
|
|
213
|
+
this.ensureRun();
|
|
214
|
+
this.sessionActed = true;
|
|
215
|
+
const picked = pickArg(args);
|
|
216
|
+
const arg = picked === undefined ? undefined : this.clean(picked, LEDGER_LIMITS.argText);
|
|
217
|
+
this.pending.set(id, { tool, ...(arg !== undefined ? { arg } : {}), turn: this.turnIndex + 1 });
|
|
218
|
+
if (isFileTool(tool) && arg !== undefined && !this.files.includes(arg)) {
|
|
219
|
+
this.files.push(clipPoints(arg, LEDGER_LIMITS.fileText));
|
|
220
|
+
if (this.files.length > LEDGER_LIMITS.filesMax)
|
|
221
|
+
this.files.shift();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
endCall(args) {
|
|
225
|
+
this.ensureRun();
|
|
226
|
+
const started = this.pending.get(args.id);
|
|
227
|
+
this.pending.delete(args.id);
|
|
228
|
+
const ok = !args.isError;
|
|
229
|
+
const arg = started?.arg;
|
|
230
|
+
this.counters.toolCalls += 1;
|
|
231
|
+
this.counters.toolErrors += ok ? 0 : 1;
|
|
232
|
+
if (isVerifyCall(args.tool, arg))
|
|
233
|
+
this.lastVerifyOk = ok;
|
|
234
|
+
const entry = {
|
|
235
|
+
id: args.id,
|
|
236
|
+
tool: args.tool,
|
|
237
|
+
...(arg !== undefined ? { arg } : {}),
|
|
238
|
+
ok,
|
|
239
|
+
ms: Math.max(0, Math.trunc(args.ms) || 0),
|
|
240
|
+
turn: started?.turn ?? this.turnIndex + 1,
|
|
241
|
+
};
|
|
242
|
+
if (ok) {
|
|
243
|
+
// A success that closed a recovery arc is itself evidence; keep it when the ledger is full.
|
|
244
|
+
const closed = this.recordRecovery(args.tool);
|
|
245
|
+
this.push(this.calls, entry, closed > 0);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
const sig = errorSignature(args.tool, args.text);
|
|
249
|
+
this.sigCounts.set(sig, (this.sigCounts.get(sig) ?? 0) + 1);
|
|
250
|
+
const err = this.clean(args.text, LEDGER_LIMITS.errText);
|
|
251
|
+
const call = this.push(this.calls, { ...entry, sig, ...(err ? { err } : {}) }, true);
|
|
252
|
+
this.openFailures.push({ seq: call.seq, tool: args.tool, sig, callIndex: this.counters.toolCalls });
|
|
253
|
+
}
|
|
254
|
+
this.trimCount(this.calls, LEDGER_LIMITS.callsMax);
|
|
255
|
+
}
|
|
256
|
+
/** A success closes the open failures of the same tool that are still inside the window. */
|
|
257
|
+
recordRecovery(tool) {
|
|
258
|
+
const now = this.counters.toolCalls;
|
|
259
|
+
const live = this.openFailures.filter((f) => now - f.callIndex <= LEDGER_LIMITS.arcWindow);
|
|
260
|
+
const closing = live.filter((f) => f.tool === tool);
|
|
261
|
+
this.openFailures = live.filter((f) => f.tool !== tool);
|
|
262
|
+
for (const failure of closing) {
|
|
263
|
+
const between = this.calls.filter((c) => c.seq > failure.seq);
|
|
264
|
+
const arc = { sig: failure.sig, tool, gap: between.length, viaFix: between.some((c) => c.tool !== tool) };
|
|
265
|
+
this.push(this.arcs, arc, true);
|
|
266
|
+
this.counters.arcs += 1;
|
|
267
|
+
}
|
|
268
|
+
while (this.arcs.length > LEDGER_LIMITS.arcsMax)
|
|
269
|
+
this.arcs.shift();
|
|
270
|
+
return closing.length;
|
|
271
|
+
}
|
|
272
|
+
endTurn(tail) {
|
|
273
|
+
this.ensureRun();
|
|
274
|
+
this.turnIndex += 1;
|
|
275
|
+
this.counters.turns += 1;
|
|
276
|
+
const text = this.clean(tail, LEDGER_LIMITS.turnTail);
|
|
277
|
+
this.push(this.turns, { index: this.turnIndex, tail: text }, false);
|
|
278
|
+
this.trimCount(this.turns, LEDGER_LIMITS.turnsMax);
|
|
279
|
+
}
|
|
280
|
+
addGeneEvent(event) {
|
|
281
|
+
this.ensureRun();
|
|
282
|
+
switch (event.kind) {
|
|
283
|
+
case 'shown':
|
|
284
|
+
for (const id of event.geneIds)
|
|
285
|
+
this.shown.add(id);
|
|
286
|
+
return;
|
|
287
|
+
case 'unfamiliar_recovery':
|
|
288
|
+
this.counters.unfamiliarRecoveries += 1;
|
|
289
|
+
return;
|
|
290
|
+
case 'search':
|
|
291
|
+
this.pushGene({ kind: 'search', query: this.clean(event.query, 120) }, false);
|
|
292
|
+
return;
|
|
293
|
+
case 'read':
|
|
294
|
+
if (!this.reads.has(event.geneId)) {
|
|
295
|
+
this.reads.set(event.geneId, { seq: this.seq + 1, tier: event.tier, ...versionOf(event) });
|
|
296
|
+
}
|
|
297
|
+
this.pushGene({ kind: 'read', geneId: event.geneId, tier: event.tier, ...versionOf(event) }, true);
|
|
298
|
+
return;
|
|
299
|
+
case 'feedback':
|
|
300
|
+
this.noteFeedback(event);
|
|
301
|
+
return;
|
|
302
|
+
case 'run_result':
|
|
303
|
+
this.runResults.set(event.geneId, event.ok);
|
|
304
|
+
this.pushGene({ kind: 'run_result', geneId: event.geneId, ok: event.ok }, true);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
noteFeedback(event) {
|
|
308
|
+
this.feedback.set(event.geneId, event.verdict);
|
|
309
|
+
const flagged = event.verdict === 'misleading' || event.verdict === 'outdated';
|
|
310
|
+
this.counters.flaggedFeedback += flagged ? 1 : 0;
|
|
311
|
+
this.pushGene({ kind: 'feedback', geneId: event.geneId, verdict: event.verdict }, true);
|
|
312
|
+
}
|
|
313
|
+
pushGene(entry, signalled) {
|
|
314
|
+
this.push(this.genes, entry, signalled);
|
|
315
|
+
this.trimCount(this.genes, LEDGER_LIMITS.genesMax);
|
|
316
|
+
}
|
|
317
|
+
addChild(summary) {
|
|
318
|
+
this.ensureRun();
|
|
319
|
+
this.children.push(this.clean(summary, LEDGER_LIMITS.childText));
|
|
320
|
+
if (this.children.length > LEDGER_LIMITS.childrenMax)
|
|
321
|
+
this.children.shift();
|
|
322
|
+
}
|
|
323
|
+
noteRetry() {
|
|
324
|
+
this.ensureRun();
|
|
325
|
+
this.counters.retries += 1;
|
|
326
|
+
}
|
|
327
|
+
// ---- bounds ------------------------------------------------------------------
|
|
328
|
+
push(list, body, signalled) {
|
|
329
|
+
this.seq += 1;
|
|
330
|
+
const entry = { ...body, seq: this.seq, size: 0, signalled };
|
|
331
|
+
entry.size = approxSize(entry);
|
|
332
|
+
list.push(entry);
|
|
333
|
+
this.enforceTotal();
|
|
334
|
+
return entry;
|
|
335
|
+
}
|
|
336
|
+
trimCount(list, max) {
|
|
337
|
+
while (list.length > max)
|
|
338
|
+
list.shift();
|
|
339
|
+
}
|
|
340
|
+
totalBytes() {
|
|
341
|
+
const all = [this.users, this.calls, this.arcs, this.genes, this.turns];
|
|
342
|
+
return all.reduce((sum, list) => sum + list.reduce((s, e) => s + e.size, 0), 0);
|
|
343
|
+
}
|
|
344
|
+
/** Over 24 KB: unsignalled turns, then calls, users, genes go first; then the oldest signalled. */
|
|
345
|
+
enforceTotal() {
|
|
346
|
+
const order = [this.turns, this.calls, this.users, this.genes];
|
|
347
|
+
while (this.totalBytes() > this.maxBytes) {
|
|
348
|
+
const unsignalled = order.find((list) => list.some((e) => !e.signalled));
|
|
349
|
+
if (unsignalled) {
|
|
350
|
+
unsignalled.splice(unsignalled.findIndex((e) => !e.signalled), 1);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const lists = [...order, this.arcs].filter((l) => l.length > 0);
|
|
354
|
+
if (lists.length === 0)
|
|
355
|
+
return;
|
|
356
|
+
const oldest = lists.reduce((a, b) => (a[0].seq <= b[0].seq ? a : b));
|
|
357
|
+
oldest.shift();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// ---- reading -----------------------------------------------------------------
|
|
361
|
+
snapshot() {
|
|
362
|
+
return {
|
|
363
|
+
run: this.runSerial,
|
|
364
|
+
active: this.active,
|
|
365
|
+
goal: this.goal,
|
|
366
|
+
...(this.prior ? { prior: this.prior } : {}),
|
|
367
|
+
users: this.users,
|
|
368
|
+
calls: this.calls,
|
|
369
|
+
arcs: this.arcs,
|
|
370
|
+
genes: this.genes,
|
|
371
|
+
turns: this.turns,
|
|
372
|
+
files: this.files,
|
|
373
|
+
children: this.children,
|
|
374
|
+
counters: { ...this.counters },
|
|
375
|
+
sigCounts: new Map(this.sigCounts),
|
|
376
|
+
reads: new Map(this.reads),
|
|
377
|
+
feedback: new Map(this.feedback),
|
|
378
|
+
runResults: new Map(this.runResults),
|
|
379
|
+
shown: new Set(this.shown),
|
|
380
|
+
outcome: this.outcome,
|
|
381
|
+
todoAllDone: this.todoAllDone,
|
|
382
|
+
lastVerifyOk: this.lastVerifyOk,
|
|
383
|
+
bytes: this.totalBytes(),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
watermark() {
|
|
387
|
+
return {
|
|
388
|
+
run: this.runSerial,
|
|
389
|
+
counters: { ...this.counters },
|
|
390
|
+
sigCounts: new Map(this.sigCounts),
|
|
391
|
+
readIds: new Set(this.reads.keys()),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* From the reviewer's normalised answer to queue-ready proposals and usage events (gene-bank
|
|
3
|
+
* spec 10.1.4, I-9, I-16).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* `normalizeLearningOutput` (pure, in the model) decides what a reply MEANS; this file decides
|
|
8
|
+
* what the ENGINE does with it, using facts only the engine has: the ledger (did the user really
|
|
9
|
+
* say that? did anything fail after the gene was read?), the session (which scope key?) and the
|
|
10
|
+
* library (what version is the target at?). Everything here is a pure function of its inputs so
|
|
11
|
+
* the learner can stay a thin state machine.
|
|
12
|
+
*
|
|
13
|
+
* TWO DISCIPLINES LIVE HERE.
|
|
14
|
+
*
|
|
15
|
+
* I-9, "a run's failure is not every gene's fault". The model is told to judge a gene only by
|
|
16
|
+
* what followed its read, but a prompt is a request, not a guarantee. `adjustAttributions` makes
|
|
17
|
+
* it structural: a `harmed` verdict survives only if something actually went wrong AFTER the
|
|
18
|
+
* gene was read (a failed call, or the user correcting the agent). A gene whose window was all
|
|
19
|
+
* successes cannot be marked harmful because the task failed somewhere else. The reverse
|
|
20
|
+
* double-count is closed too: a gene the agent already rated through `gene_feedback`, or whose
|
|
21
|
+
* `gene_run` result is known, is attributed deterministically at that moment and is not scored a
|
|
22
|
+
* second time by a model.
|
|
23
|
+
*
|
|
24
|
+
* Evidence trust. The model quotes the user; the engine checks the quote. Only a quote found in
|
|
25
|
+
* the ledger's user messages becomes `trust: 'user'` (and is replaced by the ledger's own text,
|
|
26
|
+
* so what is stored is what was said, not what the model remembers). A quote that cannot be
|
|
27
|
+
* found is `untrusted` and cannot, on its own, make a gene trustworthy (11.6).
|
|
28
|
+
*/
|
|
29
|
+
import type { GeneEvidenceInput, GeneProposal, GeneProposalAttribution, GeneScope, GeneScopeKind, GeneUsageEvent } from '@aragon-agent/tui/model/gene/types';
|
|
30
|
+
import { type NormalizedProposalDraft } from '@aragon-agent/tui/model/gene/proposal';
|
|
31
|
+
import type { LearningSignal } from '@aragon-agent/tui/model/gene/signals';
|
|
32
|
+
import type { LedgerSnapshot } from './ledger.js';
|
|
33
|
+
export interface SessionFacts {
|
|
34
|
+
sessionId: string;
|
|
35
|
+
runId: string;
|
|
36
|
+
projectKey?: string;
|
|
37
|
+
agent?: string;
|
|
38
|
+
taskLabel?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface GeneBasis {
|
|
41
|
+
version: number | null;
|
|
42
|
+
hash?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ProposalContext {
|
|
45
|
+
now: number;
|
|
46
|
+
random: (n: number) => number;
|
|
47
|
+
session: SessionFacts;
|
|
48
|
+
snapshot: LedgerSnapshot;
|
|
49
|
+
signals: readonly LearningSignal[];
|
|
50
|
+
attributions: readonly GeneProposalAttribution[];
|
|
51
|
+
basisOf: (geneId: string) => GeneBasis | undefined;
|
|
52
|
+
knownSecrets: readonly string[];
|
|
53
|
+
}
|
|
54
|
+
/** The concrete scope for a scope KIND, or null when the session cannot name one. */
|
|
55
|
+
export declare function resolveScope(kind: GeneScopeKind, session: SessionFacts): GeneScope | null;
|
|
56
|
+
/** Check quotes against the ledger, scrub secrets, clip. */
|
|
57
|
+
export declare function verifyEvidence(list: readonly GeneEvidenceInput[], snapshot: LedgerSnapshot, knownSecrets: readonly string[]): GeneEvidenceInput[];
|
|
58
|
+
/** Did anything go wrong AFTER the gene was read? Only then can the gene be blamed. */
|
|
59
|
+
export declare function troubleAfterRead(snapshot: LedgerSnapshot, geneId: string): boolean;
|
|
60
|
+
export interface AdjustedAttributions {
|
|
61
|
+
kept: GeneProposalAttribution[];
|
|
62
|
+
/** `harmed` verdicts with no trouble in the gene's window, reduced to `unknown`. */
|
|
63
|
+
downgraded: number;
|
|
64
|
+
/** Verdicts dropped because the agent already rated the gene itself. */
|
|
65
|
+
alreadyAttributed: number;
|
|
66
|
+
}
|
|
67
|
+
export declare function adjustAttributions(attributions: readonly GeneProposalAttribution[], snapshot: LedgerSnapshot): AdjustedAttributions;
|
|
68
|
+
export interface OutcomeContext {
|
|
69
|
+
now: number;
|
|
70
|
+
runId: string;
|
|
71
|
+
snapshot: LedgerSnapshot;
|
|
72
|
+
scopeOf: (geneId: string) => GeneScope | undefined;
|
|
73
|
+
versionOf?: (geneId: string) => number | undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `outcome` usage events for the attributions that count (10.1.4): adopted, and `helped` /
|
|
77
|
+
* `harmed` / `neutral`. `unknown` is not an event at all (I-9). A gene whose scope or version
|
|
78
|
+
* cannot be determined is skipped: an event the fold cannot route would be dropped and counted
|
|
79
|
+
* as a defect there.
|
|
80
|
+
*/
|
|
81
|
+
export declare function outcomeEvents(attributions: readonly GeneProposalAttribution[], ctx: OutcomeContext): GeneUsageEvent[];
|
|
82
|
+
/** A queue-ready proposal, or null when the draft cannot be anchored (no scope, target vanished). */
|
|
83
|
+
export declare function buildProposal(draft: NormalizedProposalDraft, ctx: ProposalContext): GeneProposal | null;
|