@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,145 @@
|
|
|
1
|
+
import { isValidProposalId } from '@aragon-agent/tui/model/gene/ids';
|
|
2
|
+
import { GENE_LIMITS } from '@aragon-agent/tui/model/gene/limits';
|
|
3
|
+
import { sha1Hex, serializeJson } from './fs.js';
|
|
4
|
+
/**
|
|
5
|
+
* The privacy-safe husk of a proposal (I3-5, RV-42): every field that can carry session or
|
|
6
|
+
* project text is emptied; the identity fields stay so the done/ trace still says WHICH
|
|
7
|
+
* proposal was dropped and from which project. Nothing here is a model-written sentence.
|
|
8
|
+
*/
|
|
9
|
+
export function redactProposal(proposal) {
|
|
10
|
+
const { draft: _draft, applicability: _applicability, attributions: _attributions, ...rest } = proposal;
|
|
11
|
+
const origin = {
|
|
12
|
+
source: proposal.origin.source,
|
|
13
|
+
sessionId: proposal.origin.sessionId,
|
|
14
|
+
runId: proposal.origin.runId,
|
|
15
|
+
goal: '',
|
|
16
|
+
...(proposal.origin.projectKey !== undefined ? { projectKey: proposal.origin.projectKey } : {}),
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
...rest,
|
|
20
|
+
origin,
|
|
21
|
+
why: '',
|
|
22
|
+
expectedBenefit: '',
|
|
23
|
+
evidence: proposal.evidence.map((e) => ({ ...e, text: '' })),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const NAME_RE = /^([0-4])-(\d{13})-([^-]*)-(.+)\.json$/;
|
|
27
|
+
/** Split a queue file name; null when it is not one of ours (such files are ignored). */
|
|
28
|
+
export function parseQueueName(name) {
|
|
29
|
+
const m = NAME_RE.exec(name);
|
|
30
|
+
if (!m)
|
|
31
|
+
return null;
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
priority: Number(m[1]),
|
|
35
|
+
createdAt: Number(m[2]),
|
|
36
|
+
dedupe8: m[3],
|
|
37
|
+
proposalId: m[4],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Only names we mint count as queue items; anything else in these directories is not ours. */
|
|
41
|
+
export function isQueueName(name) {
|
|
42
|
+
return parseQueueName(name) !== null;
|
|
43
|
+
}
|
|
44
|
+
function isRecord(value) {
|
|
45
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
46
|
+
}
|
|
47
|
+
function finiteOr(value, fallback) {
|
|
48
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
49
|
+
}
|
|
50
|
+
/** The fields every reader of a queue file depends on; anything less is not a proposal. */
|
|
51
|
+
function hasProposalShape(p) {
|
|
52
|
+
const priority = p.priority;
|
|
53
|
+
const priorityOk = typeof priority === 'number' && priority >= 0 && priority <= 4;
|
|
54
|
+
const shapeOk = typeof p.kind === 'string' && typeof p.dedupeKey === 'string' && isRecord(p.scope);
|
|
55
|
+
return isValidProposalId(p.id) && priorityOk && shapeOk;
|
|
56
|
+
}
|
|
57
|
+
/** Tolerant: a hand-edited or torn file is `null`, never an exception. */
|
|
58
|
+
export function coerceQueueRecord(raw) {
|
|
59
|
+
if (!isRecord(raw) || !isRecord(raw.proposal))
|
|
60
|
+
return null;
|
|
61
|
+
const p = raw.proposal;
|
|
62
|
+
if (!hasProposalShape(p))
|
|
63
|
+
return null;
|
|
64
|
+
const proposal = { ...p, evidence: Array.isArray(p.evidence) ? p.evidence : [] };
|
|
65
|
+
const record = {
|
|
66
|
+
...raw,
|
|
67
|
+
schema: 1,
|
|
68
|
+
proposal,
|
|
69
|
+
attempt: Math.max(0, Math.trunc(finiteOr(raw.attempt, 0))),
|
|
70
|
+
notBefore: finiteOr(raw.notBefore, 0),
|
|
71
|
+
};
|
|
72
|
+
return record;
|
|
73
|
+
}
|
|
74
|
+
function clipCodePoints(text, max) {
|
|
75
|
+
const points = Array.from(text);
|
|
76
|
+
return points.length <= max ? text : points.slice(0, max).join('');
|
|
77
|
+
}
|
|
78
|
+
function evidenceKey(e) {
|
|
79
|
+
return sha1Hex(String(e.text ?? ''));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Fold `incoming` into `existing` (10.5.3): evidence by text hash up to the cap, the higher
|
|
83
|
+
* priority (smaller number), the newer draft, `merged` counting every folded request. The
|
|
84
|
+
* existing id and `createdAt` survive on purpose: the item has been waiting, and aging must
|
|
85
|
+
* keep counting from the first request, not restart on every duplicate.
|
|
86
|
+
*/
|
|
87
|
+
export function mergeProposals(existing, incoming) {
|
|
88
|
+
const seen = new Set();
|
|
89
|
+
const evidence = [...existing.evidence, ...incoming.evidence].filter((e) => {
|
|
90
|
+
const key = evidenceKey(e);
|
|
91
|
+
if (seen.has(key))
|
|
92
|
+
return false;
|
|
93
|
+
seen.add(key);
|
|
94
|
+
return true;
|
|
95
|
+
});
|
|
96
|
+
const takesDraft = incoming.draft !== undefined;
|
|
97
|
+
const merged = {
|
|
98
|
+
...existing,
|
|
99
|
+
priority: Math.min(existing.priority, incoming.priority),
|
|
100
|
+
evidence: evidence.slice(0, GENE_LIMITS.proposalEvidenceMax),
|
|
101
|
+
merged: existing.merged + 1 + Math.max(0, incoming.merged || 0),
|
|
102
|
+
};
|
|
103
|
+
if (takesDraft) {
|
|
104
|
+
// The draft, its rationale and its benefit describe each other; take them together.
|
|
105
|
+
merged.draft = incoming.draft;
|
|
106
|
+
merged.why = incoming.why;
|
|
107
|
+
merged.expectedBenefit = incoming.expectedBenefit;
|
|
108
|
+
}
|
|
109
|
+
if (incoming.attributions && incoming.attributions.length > 0)
|
|
110
|
+
merged.attributions = incoming.attributions;
|
|
111
|
+
return merged;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Shrink a record until its JSON fits `queueItemMaxKB`: clip evidence texts, drop evidence from
|
|
115
|
+
* the tail, finally drop the draft. Returns null when even that is not enough.
|
|
116
|
+
*/
|
|
117
|
+
export function fitRecordToLimit(record) {
|
|
118
|
+
const max = GENE_LIMITS.queueItemMaxKB * 1024;
|
|
119
|
+
for (const candidate of shrinkingCandidates(record)) {
|
|
120
|
+
const text = serializeJson(candidate);
|
|
121
|
+
if (Buffer.byteLength(text, 'utf8') <= max)
|
|
122
|
+
return { record: candidate, text };
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
/** The record itself, then ever smaller versions of it; each clip is relative to the ORIGINAL. */
|
|
127
|
+
function* shrinkingCandidates(record) {
|
|
128
|
+
const original = record.proposal.evidence;
|
|
129
|
+
const withEvidence = (list) => ({
|
|
130
|
+
...record,
|
|
131
|
+
proposal: { ...record.proposal, evidence: list },
|
|
132
|
+
});
|
|
133
|
+
yield record;
|
|
134
|
+
let smallest = original;
|
|
135
|
+
for (const factor of [0.5, 0.25, 0.1]) {
|
|
136
|
+
smallest = original.map((e) => ({
|
|
137
|
+
...e,
|
|
138
|
+
text: clipCodePoints(e.text, Math.floor(Array.from(e.text).length * factor)),
|
|
139
|
+
}));
|
|
140
|
+
yield withEvidence(smallest);
|
|
141
|
+
}
|
|
142
|
+
for (let keep = smallest.length - 1; keep >= 0; keep -= 1)
|
|
143
|
+
yield withEvidence(smallest.slice(0, keep));
|
|
144
|
+
yield { ...withEvidence([]), proposal: { ...record.proposal, evidence: [], draft: undefined } };
|
|
145
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { GeneProposal, GeneScope } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
import type { GeneQueueEntryView } from '@aragon-agent/tui/model/gene/port';
|
|
3
|
+
import { coerceQueueRecord, fitRecordToLimit, mergeProposals, parseQueueName, redactProposal, type GeneQueueRecord, type ParsedQueueName, type QueueOutcome, type QueueResult } from './queue-record.js';
|
|
4
|
+
export { coerceQueueRecord, fitRecordToLimit, mergeProposals, parseQueueName, redactProposal };
|
|
5
|
+
export type { GeneQueueRecord, ParsedQueueName, QueueOutcome, QueueResult };
|
|
6
|
+
import { type GenePathContext, type QueueState } from './paths.js';
|
|
7
|
+
export interface QueueDeps {
|
|
8
|
+
/** Library root override (tests); defaults to the real one. */
|
|
9
|
+
ctx?: Pick<GenePathContext, 'root'>;
|
|
10
|
+
now: () => number;
|
|
11
|
+
pid: number;
|
|
12
|
+
isPidAlive?: (pid: number) => boolean;
|
|
13
|
+
/** Pause between lock attempts; defaults to a real timer. */
|
|
14
|
+
sleep?: (ms: number) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface ClaimedItem {
|
|
17
|
+
name: string;
|
|
18
|
+
workerId: string;
|
|
19
|
+
path: string;
|
|
20
|
+
item: GeneQueueRecord;
|
|
21
|
+
}
|
|
22
|
+
export type EnqueueResult = {
|
|
23
|
+
ok: true;
|
|
24
|
+
merged: false;
|
|
25
|
+
proposalId: string;
|
|
26
|
+
evicted?: string;
|
|
27
|
+
} | {
|
|
28
|
+
ok: true;
|
|
29
|
+
merged: true;
|
|
30
|
+
proposalId: string;
|
|
31
|
+
mergedInto: string;
|
|
32
|
+
} | {
|
|
33
|
+
ok: false;
|
|
34
|
+
reason: 'invalid' | 'too_large' | 'queue_full' | 'io';
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
/** What a failed attempt means for the item (10.5.5). */
|
|
38
|
+
export type QueueFailure = {
|
|
39
|
+
kind: 'transient';
|
|
40
|
+
error: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'budget';
|
|
43
|
+
resetAt: number;
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'validation';
|
|
46
|
+
error: string;
|
|
47
|
+
};
|
|
48
|
+
export interface FailResult {
|
|
49
|
+
state: 'pending' | 'dead' | 'done';
|
|
50
|
+
attempt: number;
|
|
51
|
+
notBefore: number;
|
|
52
|
+
}
|
|
53
|
+
export interface QueueCounts {
|
|
54
|
+
pending: number;
|
|
55
|
+
claimed: number;
|
|
56
|
+
dead: number;
|
|
57
|
+
done: number;
|
|
58
|
+
}
|
|
59
|
+
export interface QueueEntry {
|
|
60
|
+
state: QueueState;
|
|
61
|
+
name: string;
|
|
62
|
+
parsed: ParsedQueueName | null;
|
|
63
|
+
workerId?: string;
|
|
64
|
+
/** null = the file exists but cannot be read; shown as `unreadable`. */
|
|
65
|
+
item: GeneQueueRecord | null;
|
|
66
|
+
mtimeMs: number;
|
|
67
|
+
}
|
|
68
|
+
export interface RecoveredItem {
|
|
69
|
+
proposalId: string;
|
|
70
|
+
to: 'pending' | 'dead';
|
|
71
|
+
attempt: number;
|
|
72
|
+
}
|
|
73
|
+
export interface FenceResult {
|
|
74
|
+
/** Pending proposals moved to `done/`. */
|
|
75
|
+
superseded: string[];
|
|
76
|
+
/** Claimed proposals that got a `.cancel` marker. */
|
|
77
|
+
cancelled: string[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* What the version service needs from the queue: when a person commits a new version, every
|
|
81
|
+
* proposal built on an older one is dead (10.5.4, I-10). A structural port so the version
|
|
82
|
+
* service does not import this file.
|
|
83
|
+
*/
|
|
84
|
+
export interface ProposalFence {
|
|
85
|
+
supersedeBelow(geneId: string, newVersion: number): Promise<FenceResult>;
|
|
86
|
+
cancelForGene(geneId: string, reason: 'target_gone' | 'forgotten', detail?: string): Promise<FenceResult>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The port the version service calls (`commit-types.ts::ProposalFence`): keyed by gene AND
|
|
90
|
+
* scope, answering with a count. Declared here structurally so this file does not import the
|
|
91
|
+
* service. Gene ids are unique across scopes, so the scope is accepted and not needed.
|
|
92
|
+
*/
|
|
93
|
+
export interface VersionServiceFence {
|
|
94
|
+
supersedeStale(input: {
|
|
95
|
+
geneId: string;
|
|
96
|
+
scope: GeneScope;
|
|
97
|
+
basisBelow: number;
|
|
98
|
+
}): Promise<number>;
|
|
99
|
+
cancelForGene(input: {
|
|
100
|
+
geneId: string;
|
|
101
|
+
scope: GeneScope;
|
|
102
|
+
reason: string;
|
|
103
|
+
}): Promise<number>;
|
|
104
|
+
}
|
|
105
|
+
/** Wire a queue to the version service's port. `reason` becomes a stable `detail` token. */
|
|
106
|
+
export declare function versionServiceFence(queue: ProposalFence): VersionServiceFence;
|
|
107
|
+
export declare const QUEUE_MAX_ATTEMPTS = 4;
|
|
108
|
+
/** Backoff after the 1st, 2nd and 3rd transient failure; the 4th goes to `dead/`. */
|
|
109
|
+
export declare const QUEUE_BACKOFF_MS: readonly number[];
|
|
110
|
+
export declare class GeneQueue implements ProposalFence {
|
|
111
|
+
private readonly deps;
|
|
112
|
+
private readonly ctx;
|
|
113
|
+
private readonly root;
|
|
114
|
+
private readonly isPidAlive;
|
|
115
|
+
private countsCache;
|
|
116
|
+
constructor(deps: QueueDeps);
|
|
117
|
+
/** Run body while holding the item's lock. attempts > 1 waits for a short-lived holder. */
|
|
118
|
+
private withLock;
|
|
119
|
+
/** Add a proposal, folding it into a pending one with the same dedupe key (10.5.3). */
|
|
120
|
+
enqueue(proposal: GeneProposal): Promise<EnqueueResult>;
|
|
121
|
+
private enqueueUnchecked;
|
|
122
|
+
/** Returns the id of the pending proposal `incoming` was folded into, or null. */
|
|
123
|
+
private mergeIntoPending;
|
|
124
|
+
private mergeInto;
|
|
125
|
+
/** Rewrite a pending file; a changed priority changes the NAME, so the old file is renamed first. */
|
|
126
|
+
private rewritePending;
|
|
127
|
+
/**
|
|
128
|
+
* Enforce the cap (10.5.3): at 500, an incoming p=4 is dropped; otherwise the OLDEST item of
|
|
129
|
+
* the worst class is evicted, provided that class is worse than the incoming one.
|
|
130
|
+
*/
|
|
131
|
+
private makeRoom;
|
|
132
|
+
/**
|
|
133
|
+
* Take the next runnable item for `workerId`, or null. A lost race moves on to the next file.
|
|
134
|
+
* `skip` leaves an item pending (nothing is counted or moved): the curator uses it to keep
|
|
135
|
+
* cold-start imports from spending the budget live learning needs.
|
|
136
|
+
*/
|
|
137
|
+
claimNext(workerId: string, skip?: (proposal: GeneProposal) => boolean | Promise<boolean>): Promise<ClaimedItem | null>;
|
|
138
|
+
/**
|
|
139
|
+
* The claim itself, under the item's lock. The file is READ AGAIN here: between the scheduling
|
|
140
|
+
* peek and the lock another worker may have claimed it, a merge may have rewritten it, or a
|
|
141
|
+
* retry may have pushed its notBefore out - only what is true under the lock counts.
|
|
142
|
+
*/
|
|
143
|
+
private takeOwnership;
|
|
144
|
+
/** Refresh the heartbeat. False when the claim is gone (recovered by someone else). */
|
|
145
|
+
heartbeat(claimed: ClaimedItem): Promise<boolean>;
|
|
146
|
+
/** True when a superseding commit asked the worker to stop (10.5.4). */
|
|
147
|
+
isCancelled(claimed: ClaimedItem): Promise<boolean>;
|
|
148
|
+
/** Settle a claimed item into `done/`. False when the claim was lost in the meantime. */
|
|
149
|
+
complete(claimed: ClaimedItem, outcome: Omit<QueueOutcome, 'at'>): Promise<boolean>;
|
|
150
|
+
/**
|
|
151
|
+
* Settle a claimed item of a project that has been switched off for learning (I3-5, RV-42).
|
|
152
|
+
* NOT `complete` / `discard` / `fail`: those keep the whole proposal, evidence text included,
|
|
153
|
+
* in `done/` or `dead/`. The privacy switch promises that nothing about the session stays, so
|
|
154
|
+
* the proposal is reduced to its identity fields BEFORE it is moved.
|
|
155
|
+
*/
|
|
156
|
+
dropExcluded(claimed: ClaimedItem): Promise<boolean>;
|
|
157
|
+
/**
|
|
158
|
+
* The user just switched learning off: settle every `pending/` and `dead/` proposal that
|
|
159
|
+
* `isExcluded` matches the same redacted way, without waiting for a claim (RV-56). Returns the
|
|
160
|
+
* proposal ids that were dropped. Items another process is working on (`claimed/`) are left to
|
|
161
|
+
* the curator's own checkpoints.
|
|
162
|
+
*/
|
|
163
|
+
dropExcludedWhere(isExcluded: (proposal: GeneProposal) => boolean): Promise<string[]>;
|
|
164
|
+
private excludedRecord;
|
|
165
|
+
/** Give an item back untouched (a paused curator): no attempt counted, optional delay. */
|
|
166
|
+
release(claimed: ClaimedItem, notBefore?: number): Promise<boolean>;
|
|
167
|
+
/** Record a failed attempt and apply the retry policy (10.5.5). */
|
|
168
|
+
fail(claimed: ClaimedItem, failure: QueueFailure): Promise<FailResult | null>;
|
|
169
|
+
/**
|
|
170
|
+
* Common frame of a claimed item's exit: under the lock, only if the claim is still ours (the
|
|
171
|
+
* file is still in OUR worker directory - a recovery that took it away makes this a no-op),
|
|
172
|
+
* run move, then tidy up. False when the claim was lost or the lock stayed busy.
|
|
173
|
+
*/
|
|
174
|
+
private settleClaimed;
|
|
175
|
+
private applyFailure;
|
|
176
|
+
/**
|
|
177
|
+
* `returnedToPending`: the item itself now lives in `pending/` under this very name, so the
|
|
178
|
+
* stray sweep must not run - it would delete the item we just handed back.
|
|
179
|
+
*/
|
|
180
|
+
private cleanupAfterSettle;
|
|
181
|
+
/**
|
|
182
|
+
* Return claimed items whose worker is gone to `pending` with `attempt + 1` (10.5.5): no
|
|
183
|
+
* heartbeat for `claimStaleMs`, or the owning pid is dead. A poison item that keeps killing
|
|
184
|
+
* its worker reaches `QUEUE_MAX_ATTEMPTS` and is quarantined instead of looping forever.
|
|
185
|
+
*/
|
|
186
|
+
recoverStale(): Promise<RecoveredItem[]>;
|
|
187
|
+
private recoverOne;
|
|
188
|
+
/** No heartbeat for `claimStaleMs`, or the owning process is gone (a pid that is ours is alive). */
|
|
189
|
+
private isAbandoned;
|
|
190
|
+
private recoverLocked;
|
|
191
|
+
/** A `.cancel` marker whose item is gone (settled elsewhere) is just litter. */
|
|
192
|
+
private sweepOrphanMarkers;
|
|
193
|
+
/** A person committed `newVersion`: proposals built on an older basis are obsolete (I-10). */
|
|
194
|
+
supersedeBelow(geneId: string, newVersion: number): Promise<FenceResult>;
|
|
195
|
+
/** The gene was deleted or forgotten: nothing aimed at it can be applied (I-17). */
|
|
196
|
+
cancelForGene(geneId: string, reason: 'target_gone' | 'forgotten', detail?: string): Promise<FenceResult>;
|
|
197
|
+
private settleMatching;
|
|
198
|
+
private settlePending;
|
|
199
|
+
/** Counts per state, cached for one second (12.8); the queue's own writes drop the cache. */
|
|
200
|
+
counts(): Promise<QueueCounts>;
|
|
201
|
+
/** Entries of one state. `pending` is in scheduling order; `done` / `dead` newest first. */
|
|
202
|
+
list(state: QueueState): Promise<QueueEntry[]>;
|
|
203
|
+
/** Move a dead item back to `pending` with a clean slate (UI "Retry"). */
|
|
204
|
+
retryDead(proposalId: string): Promise<boolean>;
|
|
205
|
+
/** Drop a pending or dead item (UI "Discard"); a trace stays in `done/` until it ages out. */
|
|
206
|
+
discard(proposalId: string): Promise<boolean>;
|
|
207
|
+
/** Age out `done/` (7 days, 1000 entries) and `dead/` (30 days). Returns how many files went. */
|
|
208
|
+
prune(): Promise<number>;
|
|
209
|
+
private parsedPending;
|
|
210
|
+
private scheduleCompare;
|
|
211
|
+
private scheduleOrder;
|
|
212
|
+
private listFlat;
|
|
213
|
+
private listClaimed;
|
|
214
|
+
private entryOf;
|
|
215
|
+
private countNames;
|
|
216
|
+
private countClaimed;
|
|
217
|
+
private cancelMarker;
|
|
218
|
+
private invalidateCounts;
|
|
219
|
+
/**
|
|
220
|
+
* `absent` covers "not there" AND "cannot be read right now" (a Windows scanner holding the
|
|
221
|
+
* file): neither may quarantine a healthy item. Only bytes we DID read and could not parse
|
|
222
|
+
* are `corrupt`.
|
|
223
|
+
*/
|
|
224
|
+
private readState;
|
|
225
|
+
private readRecord;
|
|
226
|
+
/** Atomic rewrite, then stamp the mtime with the INJECTED clock (it is the heartbeat). */
|
|
227
|
+
private rewrite;
|
|
228
|
+
private touch;
|
|
229
|
+
/** `rename` that reports a lost race (source vanished) as false instead of throwing. */
|
|
230
|
+
private tryMove;
|
|
231
|
+
/** An unreadable file cannot be given a `lastError`; it is moved to `dead/` as it is. */
|
|
232
|
+
private quarantine;
|
|
233
|
+
}
|
|
234
|
+
/** One row of the queue page. Unreadable files still get a row so the user can discard them. */
|
|
235
|
+
export declare function toQueueEntryView(entry: QueueEntry): GeneQueueEntryView | null;
|