@aragon-agent/cli 0.6.55 → 0.6.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2935 -2864
- package/README.md +160 -45
- package/dist/agent/controller.d.ts +47 -0
- package/dist/agent/controller.js +153 -2
- package/dist/agent/governance-wiring.js +8 -1
- package/dist/agent/system-prompt.d.ts +26 -0
- package/dist/agent/system-prompt.js +11 -0
- package/dist/app/App.js +101 -3
- package/dist/cli.js +29 -1
- package/dist/commands/builtins.js +4 -0
- package/dist/commands/catalog.js +1 -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 +2 -1
- package/dist/config/env.js +12 -1
- package/dist/config/load.d.ts +10 -0
- package/dist/config/load.js +13 -2
- package/dist/config/store.js +11 -1
- 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 +104 -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 +206 -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 +243 -0
- package/dist/gene/curator/tools-write.d.ts +26 -0
- package/dist/gene/curator/tools-write.js +434 -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 +24 -0
- package/dist/gene/curator/validate/evidence-tokens.js +217 -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 +41 -0
- package/dist/gene/curator/validate/knowledge.js +255 -0
- package/dist/gene/curator/validate/live-check.d.ts +14 -0
- package/dist/gene/curator/validate/live-check.js +150 -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 +165 -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 +116 -0
- package/dist/gene/learn/learn-call.js +165 -0
- package/dist/gene/learn/learn-prompt.d.ts +58 -0
- package/dist/gene/learn/learn-prompt.js +254 -0
- package/dist/gene/learn/learner.d.ts +187 -0
- package/dist/gene/learn/learner.js +448 -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 +207 -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 +84 -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/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/team/runtime.d.ts +5 -0
- package/dist/team/runtime.js +23 -0
- package/dist/team/subagent.d.ts +34 -0
- package/dist/team/subagent.js +39 -2
- package/dist/tools/index.d.ts +36 -2
- package/dist/tools/index.js +48 -7
- package/package.json +3 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The oversight fence for proposals (gene-bank spec 11.3, I-12, TH-5).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHAT IT PROTECTS. A gene with `class: 'oversight'` (acceptance criteria, checks and balances,
|
|
7
|
+
* review checklists) is the yardstick the executing agents are measured against. If an executing
|
|
8
|
+
* agent could write to it, "learning from experience" would let the thing being checked edit
|
|
9
|
+
* the check. The same goes for a gene visible ONLY to the reviewer role: it is the reviewer's
|
|
10
|
+
* private instruction, and an executor must not be able to plant or alter one.
|
|
11
|
+
*
|
|
12
|
+
* WHO IS FENCED. Every origin EXCEPT the review roles, a person's explicit flag and system
|
|
13
|
+
* maintenance. The test is deliberately "not a reviewer" rather than "is DEV or TEST": an
|
|
14
|
+
* origin whose `agent` is missing or unrecognised is treated as an executor, because the way
|
|
15
|
+
* a fence fails open is by enumerating the dangerous names and missing one.
|
|
16
|
+
*
|
|
17
|
+
* TWO CHECKPOINTS. The learner calls this at ENQUEUE; the curator calls it again at CLAIM,
|
|
18
|
+
* because the queue file is a plain JSON file a person (or a bug) may have edited in between, and
|
|
19
|
+
* because the target gene may have been reclassified since. `GeneVersionService.commit` is the
|
|
20
|
+
* third line (it refuses non-user writes to oversight genes outright), so a miss here is
|
|
21
|
+
* caught later - but a rejected proposal here costs nothing and leaves a clean record.
|
|
22
|
+
*
|
|
23
|
+
* PURE over an injected `lookupGene`, which is the only thing that knows the library.
|
|
24
|
+
*/
|
|
25
|
+
import type { GeneClass, GeneProposal, GeneRole } from '@aragon-agent/tui/model/gene/types';
|
|
26
|
+
/** The two facts about a gene the fence needs. */
|
|
27
|
+
export interface GuardGene {
|
|
28
|
+
class?: GeneClass;
|
|
29
|
+
roles?: readonly GeneRole[];
|
|
30
|
+
}
|
|
31
|
+
export type LookupGene = (geneId: string) => GuardGene | undefined;
|
|
32
|
+
export type GuardCode = 'team_scope' | 'oversight_target' | 'reviewer_only_target' | 'oversight_draft' | 'reviewer_only_draft';
|
|
33
|
+
export type GuardVerdict = {
|
|
34
|
+
ok: true;
|
|
35
|
+
} | {
|
|
36
|
+
ok: false;
|
|
37
|
+
code: GuardCode;
|
|
38
|
+
geneId?: string;
|
|
39
|
+
};
|
|
40
|
+
/** May this proposal's author be an executing agent (and so be fenced)? */
|
|
41
|
+
export declare function isExecutionOrigin(origin: GeneProposal['origin']): boolean;
|
|
42
|
+
/** Check one proposal against the fence. `lookupGene` returning undefined means "no such gene". */
|
|
43
|
+
export declare function guardProposal(proposal: GeneProposal, lookupGene: LookupGene): GuardVerdict;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Review roles of the governance mode, plus the plain words. Everything else executes. */
|
|
2
|
+
const REVIEW_AGENT_RE = /^(?:rev|insp|reviewer|inspector)$/i;
|
|
3
|
+
/** May this proposal's author be an executing agent (and so be fenced)? */
|
|
4
|
+
export function isExecutionOrigin(origin) {
|
|
5
|
+
if (origin.source === 'user_flag' || origin.source === 'system')
|
|
6
|
+
return false;
|
|
7
|
+
return !REVIEW_AGENT_RE.test((origin.agent ?? '').trim());
|
|
8
|
+
}
|
|
9
|
+
function onlyReviewer(roles) {
|
|
10
|
+
return Array.isArray(roles) && roles.length > 0 && roles.every((r) => r === 'reviewer');
|
|
11
|
+
}
|
|
12
|
+
function referencedIds(p) {
|
|
13
|
+
const ids = [p.target?.id, p.mergeInto, ...(p.mergeFrom ?? [])];
|
|
14
|
+
return [...new Set(ids.filter((id) => typeof id === 'string' && id.length > 0))];
|
|
15
|
+
}
|
|
16
|
+
/** Check one proposal against the fence. `lookupGene` returning undefined means "no such gene". */
|
|
17
|
+
export function guardProposal(proposal, lookupGene) {
|
|
18
|
+
// The team scope is read-only to agents (11.1); the normaliser already refuses it, this is the re-check.
|
|
19
|
+
if (proposal.scope?.kind === 'team')
|
|
20
|
+
return { ok: false, code: 'team_scope' };
|
|
21
|
+
if (!isExecutionOrigin(proposal.origin))
|
|
22
|
+
return { ok: true };
|
|
23
|
+
for (const geneId of referencedIds(proposal)) {
|
|
24
|
+
const gene = lookupGene(geneId);
|
|
25
|
+
if (gene?.class === 'oversight')
|
|
26
|
+
return { ok: false, code: 'oversight_target', geneId };
|
|
27
|
+
if (onlyReviewer(gene?.roles))
|
|
28
|
+
return { ok: false, code: 'reviewer_only_target', geneId };
|
|
29
|
+
}
|
|
30
|
+
const draft = proposal.draft;
|
|
31
|
+
// `class` is not part of the content type, but a hand-edited queue file can carry one.
|
|
32
|
+
if (draft?.class === 'oversight')
|
|
33
|
+
return { ok: false, code: 'oversight_draft' };
|
|
34
|
+
if (onlyReviewer(draft?.roles))
|
|
35
|
+
return { ok: false, code: 'reviewer_only_draft' };
|
|
36
|
+
return { ok: true };
|
|
37
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduce an `EvidenceLedger` snapshot to the counts the pure gate reads (gene-bank spec
|
|
3
|
+
* 10.1.2) and to the run facts the evaluation row needs (13.1).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* The gate (`collectSignals` / `shouldLearn`) takes COUNTS, never text, so deciding whether a run
|
|
8
|
+
* is worth a model call does not need the content of the run (I-8). This file is the only place
|
|
9
|
+
* that turns ledger arrays into those counts, so the definition of "a correction after an
|
|
10
|
+
* action" or "an unattributed gene read" exists once.
|
|
11
|
+
*
|
|
12
|
+
* "NEW SINCE" MATTERS. A strong signal can fire a learning call at `turn_end`, before the run
|
|
13
|
+
* is over. Without a watermark the same correction would fire a second call at `agent_end`.
|
|
14
|
+
* Counts that describe EVENTS (corrections, arcs, flags, repeated errors) are therefore reported
|
|
15
|
+
* relative to the last call; counts that describe the RUN (tool calls, outcome, todo state) stay
|
|
16
|
+
* cumulative, because "was this a real procedure" is a property of the whole run.
|
|
17
|
+
*/
|
|
18
|
+
import type { LearnLedgerFacts } from '@aragon-agent/tui/model/gene/signals';
|
|
19
|
+
import type { LedgerSnapshot, LedgerWatermark } from './ledger.js';
|
|
20
|
+
/**
|
|
21
|
+
* Genes read whose effect nothing pinned down: no `gene_feedback`, no `gene_run` result, and
|
|
22
|
+
* not already covered by an earlier learning call.
|
|
23
|
+
*/
|
|
24
|
+
export declare function unattributedReads(snap: LedgerSnapshot, mark?: LedgerWatermark): number;
|
|
25
|
+
export declare function factsFromLedger(snap: LedgerSnapshot, mark?: LedgerWatermark): LearnLedgerFacts;
|
|
26
|
+
/** The run facts an evaluation row takes from the ledger; the controller adds the rest. */
|
|
27
|
+
export interface LedgerEvalFacts {
|
|
28
|
+
toolCalls: number;
|
|
29
|
+
toolErrors: number;
|
|
30
|
+
retries: number;
|
|
31
|
+
userCorrections: number;
|
|
32
|
+
turns: number;
|
|
33
|
+
errorSigs: string[];
|
|
34
|
+
genes: {
|
|
35
|
+
shown: number;
|
|
36
|
+
read: number;
|
|
37
|
+
adopted: number;
|
|
38
|
+
helped: number;
|
|
39
|
+
harmed: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Deterministic gene counts only. A `helped` here means the agent said so through
|
|
44
|
+
* `gene_feedback` or a `gene_run` succeeded; attributions that the learning call produces later
|
|
45
|
+
* go to the usage log, not into the row written at `agent_end`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function evalFactsFromLedger(snap: LedgerSnapshot): LedgerEvalFacts;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
function delta(now, before) {
|
|
2
|
+
return Math.max(0, now - (before ?? 0));
|
|
3
|
+
}
|
|
4
|
+
/** Most times any one error signature occurred since the mark. */
|
|
5
|
+
function repeatedSince(snap, since) {
|
|
6
|
+
let max = 0;
|
|
7
|
+
for (const [sig, count] of snap.sigCounts) {
|
|
8
|
+
max = Math.max(max, count - (since?.sigCounts.get(sig) ?? 0));
|
|
9
|
+
}
|
|
10
|
+
return max;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Genes read whose effect nothing pinned down: no `gene_feedback`, no `gene_run` result, and
|
|
14
|
+
* not already covered by an earlier learning call.
|
|
15
|
+
*/
|
|
16
|
+
export function unattributedReads(snap, mark) {
|
|
17
|
+
const since = mark !== undefined && mark.run === snap.run ? mark : undefined;
|
|
18
|
+
let count = 0;
|
|
19
|
+
for (const id of snap.reads.keys()) {
|
|
20
|
+
const settled = snap.feedback.has(id) || snap.runResults.has(id) || since?.readIds.has(id) === true;
|
|
21
|
+
if (!settled)
|
|
22
|
+
count += 1;
|
|
23
|
+
}
|
|
24
|
+
return count;
|
|
25
|
+
}
|
|
26
|
+
/** A run that has not ended cannot have completed: L5 must not fire mid-run. */
|
|
27
|
+
function outcomeOf(snap) {
|
|
28
|
+
return snap.outcome === 'running' ? 'aborted' : snap.outcome;
|
|
29
|
+
}
|
|
30
|
+
export function factsFromLedger(snap, mark) {
|
|
31
|
+
// The ledger's counters restart with every run, so a mark taken in an earlier run would
|
|
32
|
+
// subtract numbers from a different scale and swallow the new run's signals.
|
|
33
|
+
const since = mark !== undefined && mark.run === snap.run ? mark : undefined;
|
|
34
|
+
const c = snap.counters;
|
|
35
|
+
const b = since?.counters;
|
|
36
|
+
return {
|
|
37
|
+
userCorrections: delta(c.userCorrections, b?.userCorrections),
|
|
38
|
+
toolErrors: delta(c.toolErrors, b?.toolErrors),
|
|
39
|
+
repeatedErrorMaxCount: repeatedSince(snap, since),
|
|
40
|
+
recoveryArcs: delta(c.arcs, b?.arcs),
|
|
41
|
+
flaggedGeneFeedback: delta(c.flaggedFeedback, b?.flaggedFeedback),
|
|
42
|
+
toolCalls: c.toolCalls,
|
|
43
|
+
outcome: outcomeOf(snap),
|
|
44
|
+
todoAllDone: snap.todoAllDone,
|
|
45
|
+
lastVerifyOk: snap.lastVerifyOk,
|
|
46
|
+
unattributedGeneReads: unattributedReads(snap, since),
|
|
47
|
+
unfamiliarRecoveries: delta(c.unfamiliarRecoveries, b?.unfamiliarRecoveries),
|
|
48
|
+
statedFacts: delta(c.statedFacts, b?.statedFacts),
|
|
49
|
+
correctionAfterAction: delta(c.correctionAfterAction, b?.correctionAfterAction),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Deterministic gene counts only. A `helped` here means the agent said so through
|
|
54
|
+
* `gene_feedback` or a `gene_run` succeeded; attributions that the learning call produces later
|
|
55
|
+
* go to the usage log, not into the row written at `agent_end`.
|
|
56
|
+
*/
|
|
57
|
+
export function evalFactsFromLedger(snap) {
|
|
58
|
+
const helped = new Set();
|
|
59
|
+
const harmed = new Set();
|
|
60
|
+
for (const [id, verdict] of snap.feedback) {
|
|
61
|
+
if (verdict === 'helped')
|
|
62
|
+
helped.add(id);
|
|
63
|
+
if (verdict === 'misleading' || verdict === 'outdated')
|
|
64
|
+
harmed.add(id);
|
|
65
|
+
}
|
|
66
|
+
for (const [id, ok] of snap.runResults)
|
|
67
|
+
if (ok)
|
|
68
|
+
helped.add(id);
|
|
69
|
+
const adopted = new Set([...helped, ...harmed, ...snap.runResults.keys()]);
|
|
70
|
+
const bySigCount = [...snap.sigCounts.entries()].sort((a, b) => b[1] - a[1]).map(([sig]) => sig);
|
|
71
|
+
return {
|
|
72
|
+
toolCalls: snap.counters.toolCalls,
|
|
73
|
+
toolErrors: snap.counters.toolErrors,
|
|
74
|
+
retries: snap.counters.retries,
|
|
75
|
+
userCorrections: snap.counters.userCorrections,
|
|
76
|
+
turns: snap.counters.turns,
|
|
77
|
+
errorSigs: bySigCount.slice(0, 10),
|
|
78
|
+
genes: {
|
|
79
|
+
shown: snap.shown.size,
|
|
80
|
+
read: snap.reads.size,
|
|
81
|
+
adopted: adopted.size,
|
|
82
|
+
helped: helped.size,
|
|
83
|
+
harmed: harmed.size,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type GenePathContext } from './paths.js';
|
|
2
|
+
type RootContext = Pick<GenePathContext, 'root'>;
|
|
3
|
+
/** The cross-process guard around one usage fold (defence in depth beside the curator lease). */
|
|
4
|
+
export declare function foldLockFile(ctx?: RootContext): string;
|
|
5
|
+
/** The 30-day "recently rejected" fingerprint set (7.3). */
|
|
6
|
+
export declare function recentlyRejectedFile(ctx?: RootContext): string;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The few library-level paths the background maintenance owns (gene-bank spec 6.8, 7.3, 7.5).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS IS NOT IN `paths.ts`. `paths.ts` belongs to the storage work package and is frozen for
|
|
7
|
+
* this one. These two builders take no caller input at all (no id, no scope, no file name), so
|
|
8
|
+
* there is nothing to validate and nothing that can leave the library root; when `paths.ts` is
|
|
9
|
+
* next opened they should move there and this file should disappear.
|
|
10
|
+
*/
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { geneRoot } from './paths.js';
|
|
13
|
+
/** The cross-process guard around one usage fold (defence in depth beside the curator lease). */
|
|
14
|
+
export function foldLockFile(ctx) {
|
|
15
|
+
return join(geneRoot(ctx), 'lock', 'usage-fold.lock');
|
|
16
|
+
}
|
|
17
|
+
/** The 30-day "recently rejected" fingerprint set (7.3). */
|
|
18
|
+
export function recentlyRejectedFile(ctx) {
|
|
19
|
+
return join(geneRoot(ctx), 'rejected-recent.json');
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { GeneIndexRow, GeneProbation, GeneProposal, GeneStats } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
import type { GeneStore } from './store.js';
|
|
3
|
+
export interface ProbationSweepDeps {
|
|
4
|
+
store: GeneStore;
|
|
5
|
+
/** The published rows to consider (the lease holder's catalog). */
|
|
6
|
+
rows: () => Iterable<GeneIndexRow>;
|
|
7
|
+
enqueue: (proposal: GeneProposal) => Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
now: () => number;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
random: (n: number) => number;
|
|
13
|
+
limit?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ProbationSweepReport {
|
|
16
|
+
examined: number;
|
|
17
|
+
continuing: number;
|
|
18
|
+
graduated: number;
|
|
19
|
+
rollbacks: number;
|
|
20
|
+
enqueued: number;
|
|
21
|
+
}
|
|
22
|
+
/** Outcomes since the probation began, from the weekly rows. */
|
|
23
|
+
export declare function probationWindow(probation: GeneProbation, stats: GeneStats | undefined): GeneProbation;
|
|
24
|
+
export declare class ProbationSweeper {
|
|
25
|
+
private readonly deps;
|
|
26
|
+
private resumeAt;
|
|
27
|
+
constructor(deps: ProbationSweepDeps);
|
|
28
|
+
sweep(): Promise<ProbationSweepReport>;
|
|
29
|
+
/** The next `limit` eligible rows in id order, wrapping around the end. */
|
|
30
|
+
private nextWindow;
|
|
31
|
+
private examine;
|
|
32
|
+
private enqueueRollback;
|
|
33
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The probation sweep: enforce S6 without a model (gene-bank spec 10.7.3 S6, 10.6, I-7, I-9).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* A gene the curator published starts on probation (`head.probation`). Nothing writes the head
|
|
7
|
+
* as outcomes arrive - statistics never touch heads - so the sweep reads the outcomes where they
|
|
8
|
+
* live, in the stats shard, and asks the pure decision in `curator/lifecycle.ts`
|
|
9
|
+
* (`evaluateProbation`) what the rule says:
|
|
10
|
+
*
|
|
11
|
+
* rollback harmed at least twice and never helped -> a P0 `revoke` proposal. The `why`
|
|
12
|
+
* starts with a stable token, `probation_rollback:previous` or
|
|
13
|
+
* `probation_rollback:revoke`, telling the deterministic P0 handler whether an
|
|
14
|
+
* earlier published version exists to go back to (S6: "roll back, or revoke a v1").
|
|
15
|
+
* graduate the window is over, or three outcomes arrived: nothing to write. Probation is a
|
|
16
|
+
* record on the head and `isOnProbation` is computed from it, so "graduated" is the
|
|
17
|
+
* absence of a problem, not a new state.
|
|
18
|
+
* continue nothing to do yet.
|
|
19
|
+
*
|
|
20
|
+
* WHERE THE COUNTS COME FROM. The shard keeps `weeks` rows `[weekStart, adopted, helped, harmed]`
|
|
21
|
+
* for the last 13 weeks, so the outcomes since probation began are the rows from the start week
|
|
22
|
+
* on. The week the probation started in may include a few outcomes from just before it, which can
|
|
23
|
+
* only make a rollback slightly earlier. The rows carry no `neutral` column, so "three outcomes"
|
|
24
|
+
* is counted as helped + harmed; a gene that only ever gets neutral outcomes simply graduates on
|
|
25
|
+
* time instead, which is harmless. `harmed >= 2 && helped == 0` - the rule that matters - is exact.
|
|
26
|
+
*
|
|
27
|
+
* NEVER TOUCHES A PINNED GENE (I-7) and never a person's gene. BOUNDED: at most `limit` genes per
|
|
28
|
+
* sweep, resuming where the last sweep stopped, so a large library is covered over several sweeps
|
|
29
|
+
* instead of being read in one.
|
|
30
|
+
*/
|
|
31
|
+
import { geneShard } from '@aragon-agent/tui/model/gene/ids';
|
|
32
|
+
import { weekStart } from '@aragon-agent/tui/model/gene/score';
|
|
33
|
+
import { evaluateProbation } from './curator/lifecycle.js';
|
|
34
|
+
import { previousPublished } from './gc-scope-sweeps.js';
|
|
35
|
+
import { buildSystemProposal } from './maintenance-proposals.js';
|
|
36
|
+
const DEFAULT_LIMIT = 200;
|
|
37
|
+
/** Outcomes since the probation began, from the weekly rows. */
|
|
38
|
+
export function probationWindow(probation, stats) {
|
|
39
|
+
const since = weekStart(probation.startedAt);
|
|
40
|
+
let helped = 0;
|
|
41
|
+
let harmed = 0;
|
|
42
|
+
const weeks = stats?.weeks;
|
|
43
|
+
for (const week of Array.isArray(weeks) ? weeks : []) {
|
|
44
|
+
if (!Array.isArray(week) || week[0] < since)
|
|
45
|
+
continue;
|
|
46
|
+
helped += Math.max(0, week[2] || 0);
|
|
47
|
+
harmed += Math.max(0, week[3] || 0);
|
|
48
|
+
}
|
|
49
|
+
helped = Math.max(helped, probation.helped);
|
|
50
|
+
harmed = Math.max(harmed, probation.harmed);
|
|
51
|
+
const adoptions = Math.max(probation.adoptions, helped + harmed);
|
|
52
|
+
return { ...probation, helped, harmed, adoptions };
|
|
53
|
+
}
|
|
54
|
+
function eligible(row) {
|
|
55
|
+
return (row.status === 'published' &&
|
|
56
|
+
!row.pinned &&
|
|
57
|
+
row.trust !== 'human' &&
|
|
58
|
+
row.class === 'standard' &&
|
|
59
|
+
row.scope.kind !== 'team');
|
|
60
|
+
}
|
|
61
|
+
export class ProbationSweeper {
|
|
62
|
+
deps;
|
|
63
|
+
resumeAt = 0;
|
|
64
|
+
constructor(deps) {
|
|
65
|
+
this.deps = deps;
|
|
66
|
+
}
|
|
67
|
+
async sweep() {
|
|
68
|
+
const report = {
|
|
69
|
+
examined: 0,
|
|
70
|
+
continuing: 0,
|
|
71
|
+
graduated: 0,
|
|
72
|
+
rollbacks: 0,
|
|
73
|
+
enqueued: 0,
|
|
74
|
+
};
|
|
75
|
+
for (const row of this.nextWindow()) {
|
|
76
|
+
const read = await this.deps.store.readHead(row.scope, row.id);
|
|
77
|
+
if (read?.head.probation === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
report.examined += 1;
|
|
80
|
+
await this.examine(row, read.head, report);
|
|
81
|
+
}
|
|
82
|
+
return report;
|
|
83
|
+
}
|
|
84
|
+
/** The next `limit` eligible rows in id order, wrapping around the end. */
|
|
85
|
+
nextWindow() {
|
|
86
|
+
const all = [...this.deps.rows()].filter(eligible).sort((a, b) => (a.id < b.id ? -1 : 1));
|
|
87
|
+
if (all.length === 0)
|
|
88
|
+
return [];
|
|
89
|
+
const limit = Math.min(this.deps.limit ?? DEFAULT_LIMIT, all.length);
|
|
90
|
+
const start = this.resumeAt % all.length;
|
|
91
|
+
this.resumeAt = (start + limit) % all.length;
|
|
92
|
+
return Array.from({ length: limit }, (_, i) => all[(start + i) % all.length]);
|
|
93
|
+
}
|
|
94
|
+
async examine(row, head, report) {
|
|
95
|
+
const { store, now } = this.deps;
|
|
96
|
+
const shard = await store.readStatsShard(row.scope, geneShard(row.id));
|
|
97
|
+
const window = probationWindow(head.probation, shard[row.id]);
|
|
98
|
+
const decision = evaluateProbation(window, { now: now(), hasPreviousPublished: true });
|
|
99
|
+
if (decision.action === 'continue')
|
|
100
|
+
report.continuing += 1;
|
|
101
|
+
if (decision.action === 'graduate')
|
|
102
|
+
report.graduated += 1;
|
|
103
|
+
if (decision.action !== 'rollback')
|
|
104
|
+
return;
|
|
105
|
+
report.rollbacks += 1;
|
|
106
|
+
const hasPrevious = (await previousPublished(store, row.scope, head)) !== null;
|
|
107
|
+
if (await this.enqueueRollback(row, head, hasPrevious))
|
|
108
|
+
report.enqueued += 1;
|
|
109
|
+
}
|
|
110
|
+
async enqueueRollback(row, head, hasPrevious) {
|
|
111
|
+
const route = hasPrevious ? 'previous' : 'revoke';
|
|
112
|
+
const action = hasPrevious ? 'roll back to the previous published version' : 'revoke it';
|
|
113
|
+
const proposal = buildSystemProposal({
|
|
114
|
+
kind: 'revoke',
|
|
115
|
+
scope: row.scope,
|
|
116
|
+
type: row.type,
|
|
117
|
+
target: { id: row.id, basisVersion: head.latestVersion },
|
|
118
|
+
now: this.deps.now(),
|
|
119
|
+
sessionId: this.deps.sessionId,
|
|
120
|
+
random: this.deps.random,
|
|
121
|
+
goal: 'Probation check by the background maintenance.',
|
|
122
|
+
why: `probation_rollback:${route} - harmed twice in probation, never helped; ${action}.`,
|
|
123
|
+
expectedBenefit: 'Stops a gene that is hurting runs from being served.',
|
|
124
|
+
});
|
|
125
|
+
return (await this.deps.enqueue(proposal)).ok;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { GeneEvidenceInput, GeneProposal, GeneScope, GeneType, ProposalKind } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
export interface SystemProposalSeed {
|
|
3
|
+
kind: ProposalKind;
|
|
4
|
+
scope: GeneScope;
|
|
5
|
+
now: number;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
random: (n: number) => number;
|
|
8
|
+
/** English, fixed text; clipped to `proposalWhyMax`. */
|
|
9
|
+
why: string;
|
|
10
|
+
expectedBenefit?: string;
|
|
11
|
+
/** English, one line: what made the system ask. Clipped to `proposalGoalMax`. */
|
|
12
|
+
goal: string;
|
|
13
|
+
type?: GeneType;
|
|
14
|
+
target?: {
|
|
15
|
+
id: string;
|
|
16
|
+
basisVersion: number | null;
|
|
17
|
+
};
|
|
18
|
+
/** Distinguishes two target-less requests of the same kind (`capacity:tool`, `periodic`). */
|
|
19
|
+
subject?: string;
|
|
20
|
+
evidence?: GeneEvidenceInput[];
|
|
21
|
+
}
|
|
22
|
+
export declare function buildSystemProposal(seed: SystemProposalSeed): GeneProposal;
|
|
23
|
+
/** Gene ids packed into evidence entries of at most `proposalEvidenceTextMax` characters each. */
|
|
24
|
+
export declare function idsAsEvidence(ids: readonly string[]): GeneEvidenceInput[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proposals the SYSTEM writes about the library (gene-bank spec 10.5, 10.9, 10.10).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* The learner turns a model's reply into proposals; the background maintenance and the session
|
|
7
|
+
* start turn FACTS into proposals - "this gene's environment stamp no longer matches", "this
|
|
8
|
+
* gene failed its probation", "this type is 90% full". No model is involved in making them, so
|
|
9
|
+
* every field is a fixed English sentence or a token built from ids and counts (I-19): there is no
|
|
10
|
+
* gene text, evidence quote or path in a `why`.
|
|
11
|
+
*
|
|
12
|
+
* `priority` and `dedupeKey` come from the shared functions in `tui/model/gene/proposal.ts`, so a
|
|
13
|
+
* proposal made here folds into an identical pending one exactly as a learner's would (10.5.3).
|
|
14
|
+
* Two requests for the same gene at the same basis are one request.
|
|
15
|
+
*/
|
|
16
|
+
import { mintProposalId } from '@aragon-agent/tui/model/gene/ids';
|
|
17
|
+
import { GENE_LIMITS } from '@aragon-agent/tui/model/gene/limits';
|
|
18
|
+
import { dedupeKeyOf, priorityOf } from '@aragon-agent/tui/model/gene/proposal';
|
|
19
|
+
function clip(text, max) {
|
|
20
|
+
return text.length <= max ? text : text.slice(0, max).trimEnd();
|
|
21
|
+
}
|
|
22
|
+
export function buildSystemProposal(seed) {
|
|
23
|
+
const keyInput = {
|
|
24
|
+
kind: seed.kind,
|
|
25
|
+
scope: seed.scope,
|
|
26
|
+
...(seed.target ? { targetId: seed.target.id, basisVersion: seed.target.basisVersion } : {}),
|
|
27
|
+
...(seed.subject === undefined ? {} : { fingerprint: seed.subject }),
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
schema: 1,
|
|
31
|
+
id: mintProposalId(seed.random),
|
|
32
|
+
createdAt: seed.now,
|
|
33
|
+
kind: seed.kind,
|
|
34
|
+
...(seed.type === undefined ? {} : { type: seed.type }),
|
|
35
|
+
scope: seed.scope,
|
|
36
|
+
...(seed.target === undefined ? {} : { target: seed.target }),
|
|
37
|
+
origin: {
|
|
38
|
+
source: 'system',
|
|
39
|
+
sessionId: seed.sessionId,
|
|
40
|
+
runId: `sys-${seed.now}`,
|
|
41
|
+
goal: clip(seed.goal, GENE_LIMITS.proposalGoalMax),
|
|
42
|
+
},
|
|
43
|
+
why: clip(seed.why, GENE_LIMITS.proposalWhyMax),
|
|
44
|
+
expectedBenefit: clip(seed.expectedBenefit ?? 'Keeps the library accurate.', GENE_LIMITS.proposalBenefitMax),
|
|
45
|
+
evidence: (seed.evidence ?? []).slice(0, GENE_LIMITS.proposalEvidenceMax),
|
|
46
|
+
priority: priorityOf({ kind: seed.kind }),
|
|
47
|
+
dedupeKey: dedupeKeyOf(keyInput),
|
|
48
|
+
merged: 0,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Gene ids packed into evidence entries of at most `proposalEvidenceTextMax` characters each. */
|
|
52
|
+
export function idsAsEvidence(ids) {
|
|
53
|
+
const entries = [];
|
|
54
|
+
let current = [];
|
|
55
|
+
const flush = () => {
|
|
56
|
+
if (current.length > 0)
|
|
57
|
+
entries.push({ kind: 'case', text: current.join(',') });
|
|
58
|
+
current = [];
|
|
59
|
+
};
|
|
60
|
+
for (const id of ids) {
|
|
61
|
+
const used = current.join(',').length + id.length + 1;
|
|
62
|
+
if (used > GENE_LIMITS.proposalEvidenceTextMax)
|
|
63
|
+
flush();
|
|
64
|
+
current.push(id);
|
|
65
|
+
}
|
|
66
|
+
flush();
|
|
67
|
+
return entries.slice(0, GENE_LIMITS.proposalEvidenceMax);
|
|
68
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { GeneCatalog } from './catalog.js';
|
|
2
|
+
import type { GeneGc } from './gc.js';
|
|
3
|
+
import type { StoreIndexWriter } from './index-writer.js';
|
|
4
|
+
import type { GeneQueue } from './queue.js';
|
|
5
|
+
import type { ScopeLockManager } from './scope-lock.js';
|
|
6
|
+
import type { GeneStore } from './store.js';
|
|
7
|
+
import { type UsageFoldDeps } from './usage-fold.js';
|
|
8
|
+
import { type TimerPort } from './usage.js';
|
|
9
|
+
import type { GeneVersionService } from './version-service.js';
|
|
10
|
+
export interface RunnerIntervals {
|
|
11
|
+
tickMs: number;
|
|
12
|
+
recoverMs: number;
|
|
13
|
+
foldMs: number;
|
|
14
|
+
capacityMs: number;
|
|
15
|
+
reconcileMs: number;
|
|
16
|
+
probationMs: number;
|
|
17
|
+
gcMs: number;
|
|
18
|
+
/** How long after a capacity warning the same type may be warned about again. */
|
|
19
|
+
capacityRenotifyMs: number;
|
|
20
|
+
}
|
|
21
|
+
export declare const DEFAULT_INTERVALS: RunnerIntervals;
|
|
22
|
+
type JobName = 'recover' | 'fold' | 'capacity' | 'reconcile' | 'probation' | 'gc';
|
|
23
|
+
export interface TickReport {
|
|
24
|
+
leaseHolder: boolean;
|
|
25
|
+
/** Another tick was still running; nothing was started. */
|
|
26
|
+
busy: boolean;
|
|
27
|
+
ran: JobName[];
|
|
28
|
+
failed: JobName[];
|
|
29
|
+
}
|
|
30
|
+
export interface MaintenanceRunnerDeps {
|
|
31
|
+
store: GeneStore;
|
|
32
|
+
locks: ScopeLockManager;
|
|
33
|
+
service: Pick<GeneVersionService, 'verifyScope' | 'reconcileScope' | 'rebuildScopeCounts' | 'store' | 'totals' | 'limits'>;
|
|
34
|
+
catalog: Pick<GeneCatalog, 'reconcile' | 'scopes' | 'countsFor' | 'isLoaded' | 'rows' | 'compact' | 'catchUp'>;
|
|
35
|
+
queue: Pick<GeneQueue, 'enqueue' | 'recoverStale'>;
|
|
36
|
+
gc: Pick<GeneGc, 'run'>;
|
|
37
|
+
compactor: Pick<StoreIndexWriter, 'compactIfNeeded'>;
|
|
38
|
+
isLeaseHolder: () => boolean;
|
|
39
|
+
sessionId: string;
|
|
40
|
+
now?: () => number;
|
|
41
|
+
timer?: TimerPort;
|
|
42
|
+
random?: (n: number) => number;
|
|
43
|
+
intervals?: Partial<RunnerIntervals>;
|
|
44
|
+
/** Extra knobs for the usage fold (`batch`, `isOnProbation`, test hooks). */
|
|
45
|
+
fold?: Partial<Omit<UsageFoldDeps, 'store' | 'locks' | 'isLeaseHolder' | 'failures'>>;
|
|
46
|
+
probationLimit?: number;
|
|
47
|
+
/** Operation name and error CLASS only. Must not throw. */
|
|
48
|
+
onError?: (operation: string, errorClass: string) => void;
|
|
49
|
+
}
|
|
50
|
+
export declare class GeneMaintenanceRunner {
|
|
51
|
+
private readonly deps;
|
|
52
|
+
private readonly intervals;
|
|
53
|
+
private readonly now;
|
|
54
|
+
private readonly timer;
|
|
55
|
+
private readonly lastStart;
|
|
56
|
+
private readonly capacityNotified;
|
|
57
|
+
private readonly foldFailures;
|
|
58
|
+
private readonly sweeper;
|
|
59
|
+
private readonly jobs;
|
|
60
|
+
private handle;
|
|
61
|
+
private running;
|
|
62
|
+
private ticking;
|
|
63
|
+
private wasLeader;
|
|
64
|
+
/** The time of the tick in progress: every job and every proposal it makes shares it. */
|
|
65
|
+
private tickAt;
|
|
66
|
+
constructor(deps: MaintenanceRunnerDeps);
|
|
67
|
+
/** Arm the loop. Idempotent. The timer is unref'd, so it never keeps the process alive. */
|
|
68
|
+
start(): void;
|
|
69
|
+
/** Stop scheduling and wait for a tick in flight to finish. Never rejects. */
|
|
70
|
+
stop(): Promise<void>;
|
|
71
|
+
private schedule;
|
|
72
|
+
/** Run every due job once. `at` overrides the clock (tests). Never rejects. */
|
|
73
|
+
tick(at?: number): Promise<TickReport>;
|
|
74
|
+
/** Whatever goes wrong inside a tick - even `isLeaseHolder` throwing - stays inside it. */
|
|
75
|
+
private runDueSafely;
|
|
76
|
+
private runDue;
|
|
77
|
+
private isDue;
|
|
78
|
+
private runJob;
|
|
79
|
+
private note;
|
|
80
|
+
private buildJobs;
|
|
81
|
+
private enqueueDeps;
|
|
82
|
+
private enqueue;
|
|
83
|
+
private publishedRows;
|
|
84
|
+
private recover;
|
|
85
|
+
/** Fold; while a backlog remains, fold again (bounded) instead of waiting a minute per batch. */
|
|
86
|
+
private fold;
|
|
87
|
+
private capacity;
|
|
88
|
+
private reconcile;
|
|
89
|
+
private probation;
|
|
90
|
+
private collectGarbage;
|
|
91
|
+
}
|
|
92
|
+
export {};
|