@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
package/dist/gene/hub.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { emptyGeneSessionView, viewsEqual } from '@aragon-agent/tui/model/gene/activity';
|
|
2
|
+
import { GENE_LIMITS } from '@aragon-agent/tui/model/gene/limits';
|
|
3
|
+
import { defaultIsPidAlive, readLock } from './fs.js';
|
|
4
|
+
import { curatorLeaseFile, dayStamp } from './paths.js';
|
|
5
|
+
export const HUB_POLL_MS = 1500;
|
|
6
|
+
export const HUB_MIN_EMIT_MS = 250;
|
|
7
|
+
const INIT_TAIL_BYTES = 64 * 1024;
|
|
8
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
9
|
+
export const realScheduler = {
|
|
10
|
+
every(ms, fn) {
|
|
11
|
+
const handle = setInterval(fn, ms);
|
|
12
|
+
handle.unref?.();
|
|
13
|
+
return () => clearInterval(handle);
|
|
14
|
+
},
|
|
15
|
+
after(ms, fn) {
|
|
16
|
+
const handle = setTimeout(fn, ms);
|
|
17
|
+
handle.unref?.();
|
|
18
|
+
return () => clearTimeout(handle);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const STAGE_OF = {
|
|
22
|
+
distilling: 'distilling',
|
|
23
|
+
deduping: 'deduping',
|
|
24
|
+
validating: 'validating',
|
|
25
|
+
};
|
|
26
|
+
/** Events that end the item the curator was working on. */
|
|
27
|
+
const ENDS_ITEM = new Set([
|
|
28
|
+
'published', 'merged', 'archived', 'revoked', 'rolled_back', 'rejected', 'validation_failed',
|
|
29
|
+
'needs_human', 'superseded', 'skipped', 'retry_scheduled', 'dead', 'error', 'recheck_flagged',
|
|
30
|
+
'lease_lost',
|
|
31
|
+
]);
|
|
32
|
+
/** Events worth showing as "the last thing that happened" (12.8). */
|
|
33
|
+
const LAST_EVENTS = new Set([
|
|
34
|
+
'merged', 'published', 'validation_failed', 'rolled_back',
|
|
35
|
+
]);
|
|
36
|
+
const PAUSED_REASONS = [
|
|
37
|
+
'no_fast_tier', 'daily_budget', 'curator_failing', 'learner_failing', 'learn_off', 'redteam', 'print_mode',
|
|
38
|
+
'project_excluded',
|
|
39
|
+
];
|
|
40
|
+
const STAGES = ['distilling', 'deduping', 'validating', 'publishing'];
|
|
41
|
+
function geneNameOf(detail) {
|
|
42
|
+
return detail ? /\bname=([a-z0-9][a-z0-9-]{2,59})\b/.exec(detail)?.[1] : undefined;
|
|
43
|
+
}
|
|
44
|
+
function stageOf(record) {
|
|
45
|
+
const base = STAGE_OF[record.ev];
|
|
46
|
+
if (base === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
const marked = /\bstage=([a-z]+)\b/.exec(record.detail ?? '')?.[1];
|
|
49
|
+
return STAGES.find((s) => s === marked) ?? base;
|
|
50
|
+
}
|
|
51
|
+
function pausedReasonOf(record) {
|
|
52
|
+
const first = (record.detail ?? '').trim().split(/[\s:,]/)[0];
|
|
53
|
+
return PAUSED_REASONS.find((r) => r === first) ?? 'curator_failing';
|
|
54
|
+
}
|
|
55
|
+
/** Does this record finish the item the fold believes is in progress? */
|
|
56
|
+
function finishesCurrent(fold, record) {
|
|
57
|
+
return record.proposalId === undefined || fold.proposalId === undefined || record.proposalId === fold.proposalId;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Apply one run record to the curator state. Learner-side events (`reviewing`, `reviewed_none`,
|
|
61
|
+
* `proposed`, `queued`, `merged_into_pending`) deliberately change nothing here: they describe
|
|
62
|
+
* the session that wrote them, not the curator.
|
|
63
|
+
*/
|
|
64
|
+
export function foldCuratorRecord(fold, record) {
|
|
65
|
+
const next = { ...fold };
|
|
66
|
+
if (LAST_EVENTS.has(record.ev)) {
|
|
67
|
+
next.last = { ev: record.ev, t: record.t, ...(record.detail ? { detail: record.detail } : {}) };
|
|
68
|
+
}
|
|
69
|
+
const stage = stageOf(record);
|
|
70
|
+
if (record.ev === 'claimed' || stage !== undefined)
|
|
71
|
+
startWorking(next, fold, record, stage);
|
|
72
|
+
else if (record.ev === 'paused' || record.ev === 'budget_exhausted')
|
|
73
|
+
pause(next, record);
|
|
74
|
+
else if (record.ev === 'resumed')
|
|
75
|
+
next.paused = undefined;
|
|
76
|
+
else if (ENDS_ITEM.has(record.ev) && finishesCurrent(fold, record))
|
|
77
|
+
finishItem(next);
|
|
78
|
+
return next;
|
|
79
|
+
}
|
|
80
|
+
function startWorking(next, prev, record, stage) {
|
|
81
|
+
next.working = true;
|
|
82
|
+
next.paused = undefined;
|
|
83
|
+
next.stage = stage;
|
|
84
|
+
if (record.proposalId)
|
|
85
|
+
next.proposalId = record.proposalId;
|
|
86
|
+
next.geneName = geneNameOf(record.detail) ?? (record.ev === 'claimed' ? undefined : prev.geneName);
|
|
87
|
+
}
|
|
88
|
+
function pause(next, record) {
|
|
89
|
+
next.paused = record.ev === 'budget_exhausted' ? 'daily_budget' : pausedReasonOf(record);
|
|
90
|
+
next.working = false;
|
|
91
|
+
next.stage = undefined;
|
|
92
|
+
next.geneName = undefined;
|
|
93
|
+
}
|
|
94
|
+
function finishItem(next) {
|
|
95
|
+
next.working = false;
|
|
96
|
+
next.stage = undefined;
|
|
97
|
+
next.geneName = undefined;
|
|
98
|
+
next.proposalId = undefined;
|
|
99
|
+
}
|
|
100
|
+
/** The stage and gene name, when the record has them. */
|
|
101
|
+
function workingDetail(fold) {
|
|
102
|
+
return {
|
|
103
|
+
...(fold.stage ? { stage: fold.stage } : {}),
|
|
104
|
+
...(fold.geneName ? { geneName: fold.geneName } : {}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function curatorState(a) {
|
|
108
|
+
if (a.off)
|
|
109
|
+
return 'off';
|
|
110
|
+
if (a.paused !== undefined)
|
|
111
|
+
return 'paused';
|
|
112
|
+
return a.working ? 'working' : 'idle';
|
|
113
|
+
}
|
|
114
|
+
export class GeneActivityHub {
|
|
115
|
+
deps;
|
|
116
|
+
scheduler;
|
|
117
|
+
isPidAlive;
|
|
118
|
+
listeners = new Set();
|
|
119
|
+
fold = { working: false };
|
|
120
|
+
fileFacts = { holder: 'none', counts: { pending: 0, claimed: 0, dead: 0, done: 0 } };
|
|
121
|
+
tail = null;
|
|
122
|
+
latest = emptyGeneSessionView();
|
|
123
|
+
revision = 0;
|
|
124
|
+
notifiedRevision = 0;
|
|
125
|
+
lastEmitAt = Number.NEGATIVE_INFINITY;
|
|
126
|
+
stopPolling = null;
|
|
127
|
+
cancelTrailing = null;
|
|
128
|
+
refreshing = null;
|
|
129
|
+
refreshAgain = false;
|
|
130
|
+
disposed = false;
|
|
131
|
+
/** A first publish or first queued proposal was seen LIVE (not in the initial tail). */
|
|
132
|
+
hintTrigger = false;
|
|
133
|
+
hint;
|
|
134
|
+
constructor(deps) {
|
|
135
|
+
this.deps = deps;
|
|
136
|
+
this.scheduler = deps.scheduler ?? realScheduler;
|
|
137
|
+
this.isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;
|
|
138
|
+
}
|
|
139
|
+
// ---- the view ----------------------------------------------------------
|
|
140
|
+
/** The current view: local facts read now, file facts as of the last `refresh()`. */
|
|
141
|
+
view() {
|
|
142
|
+
const candidate = this.compose();
|
|
143
|
+
if (!viewsEqual(candidate, this.latest)) {
|
|
144
|
+
this.revision += 1;
|
|
145
|
+
this.latest = { ...candidate, revision: this.revision };
|
|
146
|
+
}
|
|
147
|
+
return this.latest;
|
|
148
|
+
}
|
|
149
|
+
compose() {
|
|
150
|
+
const facts = this.deps.facts;
|
|
151
|
+
return emptyGeneSessionView({
|
|
152
|
+
available: facts.available(),
|
|
153
|
+
use: facts.use(),
|
|
154
|
+
autoLearn: facts.autoLearn(),
|
|
155
|
+
library: facts.library(),
|
|
156
|
+
context: facts.context(),
|
|
157
|
+
retrieving: facts.retrieving(),
|
|
158
|
+
learner: facts.learner(),
|
|
159
|
+
curator: this.curatorView(),
|
|
160
|
+
...(this.fold.last ? { last: this.fold.last } : {}),
|
|
161
|
+
...(this.hint !== undefined ? { hint: this.hint } : {}),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
curatorView() {
|
|
165
|
+
const { holder, counts } = this.fileFacts;
|
|
166
|
+
const facts = this.deps.facts;
|
|
167
|
+
// With nobody holding the lease, a remembered "working" is a corpse: believe only the
|
|
168
|
+
// facts this process can verify itself.
|
|
169
|
+
const alive = holder !== 'none';
|
|
170
|
+
const paused = (alive ? this.fold.paused : undefined) ?? facts.curatorPausedReason?.();
|
|
171
|
+
const working = alive && this.fold.working && paused === undefined;
|
|
172
|
+
const off = !facts.available() || !facts.autoLearn();
|
|
173
|
+
return {
|
|
174
|
+
holder,
|
|
175
|
+
state: curatorState({ off, paused, working }),
|
|
176
|
+
...(paused !== undefined && !off ? { pausedReason: paused } : {}),
|
|
177
|
+
queued: counts.pending,
|
|
178
|
+
claimed: counts.claimed,
|
|
179
|
+
dead: counts.dead,
|
|
180
|
+
...(working ? workingDetail(this.fold) : {}),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** Paged processing log for the "expand" views; newest first. */
|
|
184
|
+
records(options) {
|
|
185
|
+
return this.deps.runLog.read(options);
|
|
186
|
+
}
|
|
187
|
+
// ---- subscription ------------------------------------------------------
|
|
188
|
+
/** Listen for changes. The first listener starts polling; the last one's removal stops it. */
|
|
189
|
+
subscribe(listener) {
|
|
190
|
+
if (this.disposed)
|
|
191
|
+
return () => undefined;
|
|
192
|
+
this.listeners.add(listener);
|
|
193
|
+
if (this.stopPolling === null)
|
|
194
|
+
this.startPolling();
|
|
195
|
+
return () => {
|
|
196
|
+
this.listeners.delete(listener);
|
|
197
|
+
if (this.listeners.size === 0)
|
|
198
|
+
this.stopAll();
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** Whether any file work is scheduled; the test for "no listener, no background I/O". */
|
|
202
|
+
isPolling() {
|
|
203
|
+
return this.stopPolling !== null;
|
|
204
|
+
}
|
|
205
|
+
/** A local synchronous event happened (search started, learner state changed). */
|
|
206
|
+
notify() {
|
|
207
|
+
this.requestEmit();
|
|
208
|
+
}
|
|
209
|
+
/** Re-read the file facts now and emit if anything changed. Never rejects. */
|
|
210
|
+
refresh() {
|
|
211
|
+
if (this.disposed)
|
|
212
|
+
return Promise.resolve();
|
|
213
|
+
if (this.refreshing !== null) {
|
|
214
|
+
this.refreshAgain = true;
|
|
215
|
+
return this.refreshing;
|
|
216
|
+
}
|
|
217
|
+
this.refreshing = this.refreshOnce().finally(() => {
|
|
218
|
+
this.refreshing = null;
|
|
219
|
+
if (this.refreshAgain && !this.disposed) {
|
|
220
|
+
this.refreshAgain = false;
|
|
221
|
+
void this.refresh();
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return this.refreshing;
|
|
225
|
+
}
|
|
226
|
+
dispose() {
|
|
227
|
+
this.disposed = true;
|
|
228
|
+
this.listeners.clear();
|
|
229
|
+
this.stopAll();
|
|
230
|
+
}
|
|
231
|
+
startPolling() {
|
|
232
|
+
void this.refresh();
|
|
233
|
+
this.stopPolling = this.scheduler.every(this.deps.pollMs ?? HUB_POLL_MS, () => {
|
|
234
|
+
void this.refresh();
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
stopAll() {
|
|
238
|
+
this.stopPolling?.();
|
|
239
|
+
this.stopPolling = null;
|
|
240
|
+
this.cancelTrailing?.();
|
|
241
|
+
this.cancelTrailing = null;
|
|
242
|
+
}
|
|
243
|
+
// ---- emitting ----------------------------------------------------------
|
|
244
|
+
requestEmit() {
|
|
245
|
+
if (this.cancelTrailing !== null)
|
|
246
|
+
return;
|
|
247
|
+
const min = this.deps.minEmitMs ?? HUB_MIN_EMIT_MS;
|
|
248
|
+
const wait = this.lastEmitAt + min - this.deps.now();
|
|
249
|
+
if (wait <= 0) {
|
|
250
|
+
this.flush();
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
this.cancelTrailing = this.scheduler.after(wait, () => {
|
|
254
|
+
this.cancelTrailing = null;
|
|
255
|
+
this.flush();
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/** Notify listeners if the view changed since they were last told. */
|
|
259
|
+
flush() {
|
|
260
|
+
const current = this.view();
|
|
261
|
+
if (current.revision === this.notifiedRevision)
|
|
262
|
+
return;
|
|
263
|
+
this.notifiedRevision = current.revision;
|
|
264
|
+
this.lastEmitAt = this.deps.now();
|
|
265
|
+
for (const listener of [...this.listeners]) {
|
|
266
|
+
try {
|
|
267
|
+
listener();
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
// A broken listener must not stop the others or the poll loop.
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// ---- file facts --------------------------------------------------------
|
|
275
|
+
async refreshOnce() {
|
|
276
|
+
try {
|
|
277
|
+
await this.deps.facts.refresh?.();
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
// The facts' own file work failing must not stop the lease, queue and run-log reads.
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const [holder, counts] = await Promise.all([this.readHolder(), this.deps.queue.counts()]);
|
|
284
|
+
await this.advanceTail();
|
|
285
|
+
this.fileFacts = { holder, counts };
|
|
286
|
+
await this.raiseHint();
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
// Reads fail open (I-24): keep showing the last known facts rather than blanking the UI.
|
|
290
|
+
}
|
|
291
|
+
if (!this.disposed)
|
|
292
|
+
this.requestEmit();
|
|
293
|
+
}
|
|
294
|
+
/** `self` / `other` / `none` from the lease file; a stale heartbeat or a dead pid is `none`. */
|
|
295
|
+
async readHolder() {
|
|
296
|
+
const info = this.deps.readLease
|
|
297
|
+
? await this.deps.readLease()
|
|
298
|
+
: await readLock(curatorLeaseFile(this.deps.ctx));
|
|
299
|
+
if (info === null)
|
|
300
|
+
return 'none';
|
|
301
|
+
const stale = this.deps.now() - info.heartbeatAt >= (this.deps.leaseStaleMs ?? GENE_LIMITS.leaseStaleMs);
|
|
302
|
+
if (stale)
|
|
303
|
+
return 'none';
|
|
304
|
+
if (info.pid === this.deps.pid)
|
|
305
|
+
return 'self';
|
|
306
|
+
return this.isPidAlive(info.pid) ? 'other' : 'none';
|
|
307
|
+
}
|
|
308
|
+
async advanceTail() {
|
|
309
|
+
const day = dayStamp(this.deps.now());
|
|
310
|
+
if (this.tail === null) {
|
|
311
|
+
await this.initTail(day);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (this.tail.day !== day) {
|
|
315
|
+
// Drain the last of the old day before moving on, or a curator that finished at 23:59:59
|
|
316
|
+
// would look busy until the next record.
|
|
317
|
+
const drained = await this.deps.runLog.tailFrom(this.tail.day, this.tail.offset);
|
|
318
|
+
if (!drained.reset)
|
|
319
|
+
this.apply(drained.records, true);
|
|
320
|
+
this.tail = { day, offset: 0 };
|
|
321
|
+
}
|
|
322
|
+
const result = await this.deps.runLog.tailFrom(day, this.tail.offset);
|
|
323
|
+
if (result.reset) {
|
|
324
|
+
// The file shrank (pruned, replaced): what we folded may no longer be true.
|
|
325
|
+
this.fold = { working: false };
|
|
326
|
+
await this.initTail(day);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
this.apply(result.records, true);
|
|
330
|
+
this.tail.offset = result.nextOffset;
|
|
331
|
+
}
|
|
332
|
+
/** `live`: the records are new since the last look, not the history read at start-up. */
|
|
333
|
+
apply(records, live = false) {
|
|
334
|
+
for (const record of records) {
|
|
335
|
+
this.fold = foldCuratorRecord(this.fold, record);
|
|
336
|
+
if (live && (record.ev === 'published' || record.ev === 'queued'))
|
|
337
|
+
this.hintTrigger = true;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* U-1: the first publish or queued proposal tells the user once how to open the manager. The hint
|
|
342
|
+
* is recorded as seen BEFORE it is raised, so a second process or a later session stays quiet; an
|
|
343
|
+
* unreadable state file reads as "already seen" (see `GeneUiHints`). Off or unavailable: never.
|
|
344
|
+
*/
|
|
345
|
+
async raiseHint() {
|
|
346
|
+
const hints = this.deps.hints;
|
|
347
|
+
if (hints === undefined || !this.hintTrigger || this.hint !== undefined)
|
|
348
|
+
return;
|
|
349
|
+
this.hintTrigger = false;
|
|
350
|
+
if (!this.deps.facts.available())
|
|
351
|
+
return;
|
|
352
|
+
try {
|
|
353
|
+
if (!(await hints.shouldShow('open-manager')))
|
|
354
|
+
return;
|
|
355
|
+
await hints.markSeen('open-manager');
|
|
356
|
+
this.hint = 'open-manager';
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
// Bookkeeping only: no hint is better than a failed refresh.
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/** First look at a day: fold the last stretch of the file so the CURRENT state is known. */
|
|
363
|
+
async initTail(day) {
|
|
364
|
+
const yesterday = dayStamp(this.deps.now() - DAY_MS);
|
|
365
|
+
const earlier = await this.deps.runLog.tailInit(yesterday, INIT_TAIL_BYTES / 4);
|
|
366
|
+
const today = await this.deps.runLog.tailInit(day, INIT_TAIL_BYTES);
|
|
367
|
+
this.apply(earlier.records);
|
|
368
|
+
this.apply(today.records);
|
|
369
|
+
this.tail = { day, offset: today.nextOffset };
|
|
370
|
+
}
|
|
371
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { GeneResult } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
import { type ImportItem, type SkillSourcePort, type SkipReason } from './import-sources.js';
|
|
3
|
+
import type { ManagerCore } from './manager-context.js';
|
|
4
|
+
export type ImportSource = 'memory' | 'skills';
|
|
5
|
+
/** Items held back for the reviewer's live proposals (the queue is never filled by an import). */
|
|
6
|
+
export declare const QUEUE_RESERVE = 100;
|
|
7
|
+
/** Prompt, tools and the drafted answer, on top of reading the source (a planning estimate). */
|
|
8
|
+
export declare const IMPORT_TOKEN_OVERHEAD = 1500;
|
|
9
|
+
export interface ImportPreview {
|
|
10
|
+
previewId: string;
|
|
11
|
+
source: ImportSource;
|
|
12
|
+
/** Sources that passed every screen (before the three limits). */
|
|
13
|
+
eligible: number;
|
|
14
|
+
/** What a commit would queue now. */
|
|
15
|
+
willQueue: number;
|
|
16
|
+
/** Eligible but over a limit: a later import picks them up. */
|
|
17
|
+
leftForLater: number;
|
|
18
|
+
skipped: Partial<Record<SkipReason, number>>;
|
|
19
|
+
estimatedTokens: number;
|
|
20
|
+
budget: {
|
|
21
|
+
dailyTokens: number;
|
|
22
|
+
remaining: number;
|
|
23
|
+
allowed: number;
|
|
24
|
+
exceeded: boolean;
|
|
25
|
+
};
|
|
26
|
+
queueRoom: number;
|
|
27
|
+
/** The first few titles, one line each, so the confirmation shows what is about to happen. */
|
|
28
|
+
titles: string[];
|
|
29
|
+
/** The fast model the texts will be sent to, or null when there is none (the curator pauses). */
|
|
30
|
+
provider: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface ImportOutcome {
|
|
33
|
+
queued: number;
|
|
34
|
+
/** Folded into an identical pending proposal by the queue itself. */
|
|
35
|
+
merged: number;
|
|
36
|
+
/** The source changed or vanished between the preview and the commit. */
|
|
37
|
+
changed: number;
|
|
38
|
+
leftForLater: number;
|
|
39
|
+
failed: number;
|
|
40
|
+
skipped: Partial<Record<SkipReason, number>>;
|
|
41
|
+
}
|
|
42
|
+
export interface ImporterDeps {
|
|
43
|
+
core: ManagerCore;
|
|
44
|
+
/** The session's skills; null/absent when the caller has none (headless, CLI). */
|
|
45
|
+
skills?: () => SkillSourcePort | null;
|
|
46
|
+
provider: () => string | null;
|
|
47
|
+
tokensToday: () => Promise<number>;
|
|
48
|
+
/**
|
|
49
|
+
* May the CURRENT project's notes and project-level skills be learned from (I3-5)? Absent =
|
|
50
|
+
* yes. Judged at preview AND at commit, so a switch flipped in between still holds.
|
|
51
|
+
*/
|
|
52
|
+
projectMayLearn?: () => Promise<boolean>;
|
|
53
|
+
random?: (n: number) => number;
|
|
54
|
+
}
|
|
55
|
+
export declare function estimateImportTokens(item: Pick<ImportItem, 'text'>): number;
|
|
56
|
+
export declare class GeneImporter {
|
|
57
|
+
private readonly deps;
|
|
58
|
+
private readonly previews;
|
|
59
|
+
private readonly tombstones;
|
|
60
|
+
constructor(deps: ImporterDeps);
|
|
61
|
+
private read;
|
|
62
|
+
/** Dedupe keys of every proposal in any queue state, and every ledger reference. */
|
|
63
|
+
private knownKeys;
|
|
64
|
+
private ledgerRefs;
|
|
65
|
+
private isForgotten;
|
|
66
|
+
/** Drop what was imported before or was forgotten on purpose; count each reason. */
|
|
67
|
+
private admissible;
|
|
68
|
+
private queueRoom;
|
|
69
|
+
private budgetOf;
|
|
70
|
+
/** The newest sources that fit the count, the room and the token allowance. */
|
|
71
|
+
private trim;
|
|
72
|
+
/** Report what a commit would queue. Writes nothing. */
|
|
73
|
+
preview(source: ImportSource, limit?: number): Promise<GeneResult<ImportPreview>>;
|
|
74
|
+
private remember;
|
|
75
|
+
/** Queue what the preview chose, minus what changed since. A preview is single-use. */
|
|
76
|
+
commit(previewId: string): Promise<GeneResult<ImportOutcome>>;
|
|
77
|
+
private enqueueAll;
|
|
78
|
+
/** A ledger write failing only means a later import may re-check the queue states instead. */
|
|
79
|
+
private record;
|
|
80
|
+
}
|