@aragon-agent/cli 0.6.54 → 0.6.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2912 -2838
- package/README.md +4226 -4042
- package/dist/agent/controller.d.ts +119 -0
- package/dist/agent/controller.js +365 -2
- package/dist/agent/governance-wiring.js +8 -1
- package/dist/agent/redteam-prompt.d.ts +47 -0
- package/dist/agent/redteam-prompt.js +161 -0
- package/dist/agent/redteam-wiring.d.ts +159 -0
- package/dist/agent/redteam-wiring.js +349 -0
- package/dist/agent/system-prompt.d.ts +39 -0
- package/dist/agent/system-prompt.js +18 -0
- package/dist/app/App.d.ts +10 -1
- package/dist/app/App.js +233 -24
- package/dist/app/use-redteam-mode.d.ts +56 -0
- package/dist/app/use-redteam-mode.js +121 -0
- package/dist/cli.js +82 -4
- package/dist/commands/builtins.js +43 -1
- package/dist/commands/catalog.js +5 -0
- package/dist/commands/index-build.js +2 -1
- package/dist/commands/redteam-command.d.ts +22 -0
- package/dist/commands/redteam-command.js +141 -0
- package/dist/commands/registry.d.ts +8 -0
- package/dist/config/app-paths.d.ts +10 -0
- package/dist/config/app-paths.js +12 -0
- package/dist/config/cli-commands.d.ts +29 -0
- package/dist/config/cli-commands.js +76 -1
- package/dist/config/env.d.ts +3 -1
- package/dist/config/env.js +23 -1
- package/dist/config/load.d.ts +22 -0
- package/dist/config/load.js +22 -2
- package/dist/config/redteam-launch.d.ts +77 -0
- package/dist/config/redteam-launch.js +58 -0
- package/dist/config/store.js +21 -1
- package/dist/config/ui-state.d.ts +44 -0
- package/dist/config/ui-state.js +38 -0
- package/dist/exec/bridge/server.d.ts +7 -0
- package/dist/exec/bridge/server.js +6 -2
- package/dist/exec/cli-commands.js +4 -0
- package/dist/exec/index.js +2 -0
- package/dist/exec/options.d.ts +11 -0
- package/dist/exec/options.js +21 -1
- package/dist/gene/block.d.ts +33 -0
- package/dist/gene/block.js +51 -0
- package/dist/gene/capacity.d.ts +74 -0
- package/dist/gene/capacity.js +169 -0
- package/dist/gene/catalog-reconcile.d.ts +13 -0
- package/dist/gene/catalog-reconcile.js +105 -0
- package/dist/gene/catalog-stats.d.ts +27 -0
- package/dist/gene/catalog-stats.js +89 -0
- package/dist/gene/catalog-sync.d.ts +82 -0
- package/dist/gene/catalog-sync.js +324 -0
- package/dist/gene/catalog.d.ts +160 -0
- package/dist/gene/catalog.js +433 -0
- package/dist/gene/cli-commands.d.ts +50 -0
- package/dist/gene/cli-commands.js +500 -0
- package/dist/gene/command-report.d.ts +40 -0
- package/dist/gene/command-report.js +246 -0
- package/dist/gene/command.d.ts +29 -0
- package/dist/gene/command.js +561 -0
- package/dist/gene/commit-apply-types.d.ts +13 -0
- package/dist/gene/commit-apply-types.js +1 -0
- package/dist/gene/commit-compound.d.ts +34 -0
- package/dist/gene/commit-compound.js +212 -0
- package/dist/gene/commit-counts.d.ts +41 -0
- package/dist/gene/commit-counts.js +70 -0
- package/dist/gene/commit-exec.d.ts +42 -0
- package/dist/gene/commit-exec.js +134 -0
- package/dist/gene/commit-head.d.ts +52 -0
- package/dist/gene/commit-head.js +97 -0
- package/dist/gene/commit-plan.d.ts +95 -0
- package/dist/gene/commit-plan.js +68 -0
- package/dist/gene/commit-prepare.d.ts +63 -0
- package/dist/gene/commit-prepare.js +159 -0
- package/dist/gene/commit-types.d.ts +234 -0
- package/dist/gene/commit-types.js +3 -0
- package/dist/gene/curator/agent.d.ts +137 -0
- package/dist/gene/curator/agent.js +203 -0
- package/dist/gene/curator/budget.d.ts +69 -0
- package/dist/gene/curator/budget.js +131 -0
- package/dist/gene/curator/conflicts.d.ts +54 -0
- package/dist/gene/curator/conflicts.js +143 -0
- package/dist/gene/curator/curator.d.ts +170 -0
- package/dist/gene/curator/curator.js +617 -0
- package/dist/gene/curator/deps.d.ts +34 -0
- package/dist/gene/curator/deps.js +48 -0
- package/dist/gene/curator/deterministic.d.ts +62 -0
- package/dist/gene/curator/deterministic.js +287 -0
- package/dist/gene/curator/executors.d.ts +36 -0
- package/dist/gene/curator/executors.js +379 -0
- package/dist/gene/curator/lanes.d.ts +52 -0
- package/dist/gene/curator/lanes.js +99 -0
- package/dist/gene/curator/lease.d.ts +76 -0
- package/dist/gene/curator/lease.js +171 -0
- package/dist/gene/curator/library.d.ts +36 -0
- package/dist/gene/curator/library.js +169 -0
- package/dist/gene/curator/lifecycle.d.ts +52 -0
- package/dist/gene/curator/lifecycle.js +109 -0
- package/dist/gene/curator/maintenance.d.ts +71 -0
- package/dist/gene/curator/maintenance.js +213 -0
- package/dist/gene/curator/probation.d.ts +51 -0
- package/dist/gene/curator/probation.js +71 -0
- package/dist/gene/curator/probe.d.ts +131 -0
- package/dist/gene/curator/probe.js +534 -0
- package/dist/gene/curator/prompt.d.ts +18 -0
- package/dist/gene/curator/prompt.js +128 -0
- package/dist/gene/curator/publish.d.ts +64 -0
- package/dist/gene/curator/publish.js +113 -0
- package/dist/gene/curator/recheck.d.ts +55 -0
- package/dist/gene/curator/recheck.js +103 -0
- package/dist/gene/curator/run-events.d.ts +63 -0
- package/dist/gene/curator/run-events.js +55 -0
- package/dist/gene/curator/similarity.d.ts +13 -0
- package/dist/gene/curator/similarity.js +46 -0
- package/dist/gene/curator/switches.d.ts +78 -0
- package/dist/gene/curator/switches.js +146 -0
- package/dist/gene/curator/task-context.d.ts +93 -0
- package/dist/gene/curator/task-context.js +63 -0
- package/dist/gene/curator/task-runner.d.ts +56 -0
- package/dist/gene/curator/task-runner.js +257 -0
- package/dist/gene/curator/tool-support.d.ts +112 -0
- package/dist/gene/curator/tool-support.js +197 -0
- package/dist/gene/curator/toolkit.d.ts +49 -0
- package/dist/gene/curator/toolkit.js +104 -0
- package/dist/gene/curator/tools-read.d.ts +4 -0
- package/dist/gene/curator/tools-read.js +177 -0
- package/dist/gene/curator/tools-release.d.ts +73 -0
- package/dist/gene/curator/tools-release.js +287 -0
- package/dist/gene/curator/tools-verify.d.ts +47 -0
- package/dist/gene/curator/tools-verify.js +202 -0
- package/dist/gene/curator/tools-write.d.ts +26 -0
- package/dist/gene/curator/tools-write.js +394 -0
- package/dist/gene/curator/tools.d.ts +23 -0
- package/dist/gene/curator/tools.js +21 -0
- package/dist/gene/curator/validate/common.d.ts +87 -0
- package/dist/gene/curator/validate/common.js +132 -0
- package/dist/gene/curator/validate/evidence-tokens.d.ts +36 -0
- package/dist/gene/curator/validate/evidence-tokens.js +139 -0
- package/dist/gene/curator/validate/index.d.ts +23 -0
- package/dist/gene/curator/validate/index.js +62 -0
- package/dist/gene/curator/validate/knowledge.d.ts +25 -0
- package/dist/gene/curator/validate/knowledge.js +216 -0
- package/dist/gene/curator/validate/live-check.d.ts +14 -0
- package/dist/gene/curator/validate/live-check.js +144 -0
- package/dist/gene/curator/validate/ports.d.ts +67 -0
- package/dist/gene/curator/validate/ports.js +1 -0
- package/dist/gene/curator/validate/prompts.d.ts +41 -0
- package/dist/gene/curator/validate/prompts.js +161 -0
- package/dist/gene/curator/validate/skill.d.ts +15 -0
- package/dist/gene/curator/validate/skill.js +251 -0
- package/dist/gene/curator/validate/tool.d.ts +6 -0
- package/dist/gene/curator/validate/tool.js +217 -0
- package/dist/gene/curator/validate/types.d.ts +90 -0
- package/dist/gene/curator/validate/types.js +1 -0
- package/dist/gene/curator/validator-ports.d.ts +38 -0
- package/dist/gene/curator/validator-ports.js +29 -0
- package/dist/gene/diag.d.ts +209 -0
- package/dist/gene/diag.js +549 -0
- package/dist/gene/env.d.ts +10 -0
- package/dist/gene/env.js +214 -0
- package/dist/gene/eval-recorder.d.ts +84 -0
- package/dist/gene/eval-recorder.js +222 -0
- package/dist/gene/explain-transport.d.ts +3 -0
- package/dist/gene/explain-transport.js +39 -0
- package/dist/gene/explain.d.ts +96 -0
- package/dist/gene/explain.js +293 -0
- package/dist/gene/fs.d.ts +39 -0
- package/dist/gene/fs.js +139 -0
- package/dist/gene/fsck.d.ts +68 -0
- package/dist/gene/fsck.js +134 -0
- package/dist/gene/gc-library-sweeps.d.ts +9 -0
- package/dist/gene/gc-library-sweeps.js +220 -0
- package/dist/gene/gc-rejected-set.d.ts +15 -0
- package/dist/gene/gc-rejected-set.js +63 -0
- package/dist/gene/gc-safe.d.ts +12 -0
- package/dist/gene/gc-safe.js +74 -0
- package/dist/gene/gc-scope-sweeps.d.ts +18 -0
- package/dist/gene/gc-scope-sweeps.js +297 -0
- package/dist/gene/gc-types.d.ts +55 -0
- package/dist/gene/gc-types.js +26 -0
- package/dist/gene/gc.d.ts +42 -0
- package/dist/gene/gc.js +129 -0
- package/dist/gene/gene-errors.d.ts +23 -0
- package/dist/gene/gene-errors.js +29 -0
- package/dist/gene/hints.d.ts +91 -0
- package/dist/gene/hints.js +394 -0
- package/dist/gene/hub.d.ts +149 -0
- package/dist/gene/hub.js +371 -0
- package/dist/gene/import-plan.d.ts +80 -0
- package/dist/gene/import-plan.js +294 -0
- package/dist/gene/import-proposal.d.ts +23 -0
- package/dist/gene/import-proposal.js +101 -0
- package/dist/gene/import-skill-port.d.ts +6 -0
- package/dist/gene/import-skill-port.js +53 -0
- package/dist/gene/import-sources.d.ts +48 -0
- package/dist/gene/import-sources.js +140 -0
- package/dist/gene/index-writer.d.ts +36 -0
- package/dist/gene/index-writer.js +101 -0
- package/dist/gene/learn/learn-call.d.ts +63 -0
- package/dist/gene/learn/learn-call.js +157 -0
- package/dist/gene/learn/learn-prompt.d.ts +51 -0
- package/dist/gene/learn/learn-prompt.js +245 -0
- package/dist/gene/learn/learner.d.ts +181 -0
- package/dist/gene/learn/learner.js +426 -0
- package/dist/gene/learn/ledger.d.ts +220 -0
- package/dist/gene/learn/ledger.js +394 -0
- package/dist/gene/learn/proposal-build.d.ts +83 -0
- package/dist/gene/learn/proposal-build.js +211 -0
- package/dist/gene/learn/proposal-guard.d.ts +43 -0
- package/dist/gene/learn/proposal-guard.js +37 -0
- package/dist/gene/learn/signals-port.d.ts +47 -0
- package/dist/gene/learn/signals-port.js +86 -0
- package/dist/gene/maintenance-paths.d.ts +7 -0
- package/dist/gene/maintenance-paths.js +20 -0
- package/dist/gene/maintenance-probation.d.ts +33 -0
- package/dist/gene/maintenance-probation.js +127 -0
- package/dist/gene/maintenance-proposals.d.ts +24 -0
- package/dist/gene/maintenance-proposals.js +68 -0
- package/dist/gene/maintenance-runner.d.ts +92 -0
- package/dist/gene/maintenance-runner.js +262 -0
- package/dist/gene/maintenance-tasks.d.ts +37 -0
- package/dist/gene/maintenance-tasks.js +95 -0
- package/dist/gene/manager-actions.d.ts +12 -0
- package/dist/gene/manager-actions.js +279 -0
- package/dist/gene/manager-approve.d.ts +29 -0
- package/dist/gene/manager-approve.js +84 -0
- package/dist/gene/manager-context.d.ts +90 -0
- package/dist/gene/manager-context.js +201 -0
- package/dist/gene/manager-detail.d.ts +17 -0
- package/dist/gene/manager-detail.js +313 -0
- package/dist/gene/manager-gc.d.ts +13 -0
- package/dist/gene/manager-gc.js +81 -0
- package/dist/gene/manager-library.d.ts +39 -0
- package/dist/gene/manager-library.js +90 -0
- package/dist/gene/manager-list.d.ts +27 -0
- package/dist/gene/manager-list.js +170 -0
- package/dist/gene/manager-queue.d.ts +16 -0
- package/dist/gene/manager-queue.js +124 -0
- package/dist/gene/manager-stats.d.ts +28 -0
- package/dist/gene/manager-stats.js +53 -0
- package/dist/gene/manager-view.d.ts +27 -0
- package/dist/gene/manager-view.js +124 -0
- package/dist/gene/manager.d.ts +56 -0
- package/dist/gene/manager.js +179 -0
- package/dist/gene/orphan-scopes.d.ts +37 -0
- package/dist/gene/orphan-scopes.js +150 -0
- package/dist/gene/paths.d.ts +73 -0
- package/dist/gene/paths.js +239 -0
- package/dist/gene/plan-content.d.ts +73 -0
- package/dist/gene/plan-content.js +522 -0
- package/dist/gene/plan-lifecycle.d.ts +29 -0
- package/dist/gene/plan-lifecycle.js +310 -0
- package/dist/gene/policy.d.ts +71 -0
- package/dist/gene/policy.js +313 -0
- package/dist/gene/project-learning.d.ts +25 -0
- package/dist/gene/project-learning.js +54 -0
- package/dist/gene/propagation.d.ts +48 -0
- package/dist/gene/propagation.js +45 -0
- package/dist/gene/queue-lock.d.ts +22 -0
- package/dist/gene/queue-lock.js +99 -0
- package/dist/gene/queue-record.d.ts +57 -0
- package/dist/gene/queue-record.js +145 -0
- package/dist/gene/queue.d.ts +235 -0
- package/dist/gene/queue.js +764 -0
- package/dist/gene/read.d.ts +61 -0
- package/dist/gene/read.js +252 -0
- package/dist/gene/runlog.d.ts +101 -0
- package/dist/gene/runlog.js +404 -0
- package/dist/gene/schema-lite.d.ts +24 -0
- package/dist/gene/schema-lite.js +159 -0
- package/dist/gene/scope-guard.d.ts +23 -0
- package/dist/gene/scope-guard.js +9 -0
- package/dist/gene/scope-lock.d.ts +48 -0
- package/dist/gene/scope-lock.js +222 -0
- package/dist/gene/scope-verify.d.ts +63 -0
- package/dist/gene/scope-verify.js +123 -0
- package/dist/gene/secrets.d.ts +43 -0
- package/dist/gene/secrets.js +161 -0
- package/dist/gene/service-context.d.ts +43 -0
- package/dist/gene/service-context.js +79 -0
- package/dist/gene/service-prepare.d.ts +25 -0
- package/dist/gene/service-prepare.js +219 -0
- package/dist/gene/service-types.d.ts +196 -0
- package/dist/gene/service-types.js +1 -0
- package/dist/gene/service-view.d.ts +41 -0
- package/dist/gene/service-view.js +69 -0
- package/dist/gene/service.d.ts +114 -0
- package/dist/gene/service.js +761 -0
- package/dist/gene/session-start.d.ts +36 -0
- package/dist/gene/session-start.js +212 -0
- package/dist/gene/store-port.d.ts +88 -0
- package/dist/gene/store-port.js +10 -0
- package/dist/gene/store-rows.d.ts +36 -0
- package/dist/gene/store-rows.js +72 -0
- package/dist/gene/store.d.ts +125 -0
- package/dist/gene/store.js +622 -0
- package/dist/gene/tombstones.d.ts +47 -0
- package/dist/gene/tombstones.js +61 -0
- package/dist/gene/tool-runner.d.ts +47 -0
- package/dist/gene/tool-runner.js +154 -0
- package/dist/gene/tool-screen.d.ts +41 -0
- package/dist/gene/tool-screen.js +227 -0
- package/dist/gene/tools.d.ts +112 -0
- package/dist/gene/tools.js +539 -0
- package/dist/gene/transfer.d.ts +85 -0
- package/dist/gene/transfer.js +433 -0
- package/dist/gene/ui-hints.d.ts +15 -0
- package/dist/gene/ui-hints.js +67 -0
- package/dist/gene/usage-fold-cursor.d.ts +24 -0
- package/dist/gene/usage-fold-cursor.js +115 -0
- package/dist/gene/usage-fold.d.ts +49 -0
- package/dist/gene/usage-fold.js +397 -0
- package/dist/gene/usage.d.ts +67 -0
- package/dist/gene/usage.js +231 -0
- package/dist/gene/version-service.d.ts +118 -0
- package/dist/gene/version-service.js +453 -0
- package/dist/gene/wiring-events.d.ts +43 -0
- package/dist/gene/wiring-events.js +113 -0
- package/dist/gene/wiring-models.d.ts +46 -0
- package/dist/gene/wiring-models.js +81 -0
- package/dist/gene/wiring.d.ts +200 -0
- package/dist/gene/wiring.js +764 -0
- package/dist/governance/prompts/orchestrator-block.js +3 -2
- package/dist/host/controller-factory.d.ts +8 -0
- package/dist/host/controller-factory.js +7 -0
- package/dist/host/gene.d.ts +26 -0
- package/dist/host/gene.js +24 -0
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/session/checkpoint.d.ts +15 -0
- package/dist/session/checkpoint.js +18 -0
- package/dist/session/persist.d.ts +21 -0
- package/dist/session/persist.js +10 -0
- package/dist/session/startup-session.d.ts +11 -2
- package/dist/session/startup-session.js +12 -2
- package/dist/session/validate-session.js +31 -0
- package/dist/team/runtime.d.ts +16 -0
- package/dist/team/runtime.js +29 -0
- package/dist/team/subagent.d.ts +55 -0
- package/dist/team/subagent.js +46 -2
- package/dist/tools/index.d.ts +60 -2
- package/dist/tools/index.js +68 -10
- package/package.json +3 -3
- package/skills/project-indexer/SKILL.md +275 -147
- package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -0
- package/skills/project-indexer/templates/config-template.md +12 -0
- package/skills/project-indexer/templates/index-template.md +4 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aragon gene diag`: a diagnostic bundle that is safe to attach to an issue (gene-bank spec I3-7,
|
|
3
|
+
* AC-55, RV-46, RV-55).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* SAFETY IS STRUCTURAL, NOT A MATTER OF REMEMBERING. `buildDiagBundle` constructs the bundle one
|
|
8
|
+
* field at a time through five coercers, and each can only produce a value of a closed kind:
|
|
9
|
+
*
|
|
10
|
+
* count(x) a finite non-negative whole number (anything else becomes 0)
|
|
11
|
+
* flag(x) a boolean (only `true` is true)
|
|
12
|
+
* pick(x, T) a member of a fixed vocabulary (anything else becomes `other`)
|
|
13
|
+
* ref8(x) exactly eight lowercase hex characters (anything else becomes null)
|
|
14
|
+
* triple(x) a version as three numbers (`1.2.3` -> [1, 2, 3], else null)
|
|
15
|
+
*
|
|
16
|
+
* There is no string pass-through. A gene's name, body or evidence, a proposal's text, a project's
|
|
17
|
+
* label or its full key, a path, a user name, an environment value or a session snippet cannot get
|
|
18
|
+
* into the output even if a caller hands one over by mistake: the coercer for that slot simply has
|
|
19
|
+
* no way to carry it. Project scopes appear only as `projectRef`, the last eight hex characters of
|
|
20
|
+
* the key (the part before it is `slugOf(label)`, which is the user's folder name).
|
|
21
|
+
*
|
|
22
|
+
* KEYS ARE FIXED TOO. Every object key comes from a table in this file, never from data, so a
|
|
23
|
+
* scope key or a config key found on disk cannot become a property name.
|
|
24
|
+
*
|
|
25
|
+
* WHAT IS NOT HERE: the result of `fsck`. It is not persisted, and running it for a bundle would
|
|
26
|
+
* walk every gene of a 15 000-gene library (RV-55). The bundle says "run fsck separately".
|
|
27
|
+
*
|
|
28
|
+
* COLLECTION NEVER THROWS AND NEVER WRITES. Each section is gathered on its own; a section that
|
|
29
|
+
* fails is left out and named in `unavailable`, so a broken queue directory does not cost the
|
|
30
|
+
* person the rest of the report.
|
|
31
|
+
*/
|
|
32
|
+
import { promises as nodeFs, readFileSync } from 'node:fs';
|
|
33
|
+
import { dirname, join } from 'node:path';
|
|
34
|
+
import process from 'node:process';
|
|
35
|
+
import { fileURLToPath } from 'node:url';
|
|
36
|
+
import { readConfigFile } from '../config/store.js';
|
|
37
|
+
import { readLock, sha1Hex } from './fs.js';
|
|
38
|
+
import { tokensToday } from './manager-stats.js';
|
|
39
|
+
import { auditProjectScopes } from './orphan-scopes.js';
|
|
40
|
+
import { curatorLeaseFile, geneRoot } from './paths.js';
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// Vocabularies: the ONLY strings a bundle can contain besides eight-hex references
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
const TYPES = ['knowledge', 'tool', 'skill'];
|
|
45
|
+
const OS_NAMES = ['win32', 'darwin', 'linux'];
|
|
46
|
+
const ARCHES = ['x64', 'arm64'];
|
|
47
|
+
const LEASE_STATES = ['none', 'self', 'other'];
|
|
48
|
+
const LEASE_KINDS = ['tui', 'desktop'];
|
|
49
|
+
const SCOPE_KINDS = ['user', 'project', 'task', 'team'];
|
|
50
|
+
const CONFIG_SOURCES = ['default', 'file', 'env'];
|
|
51
|
+
const POLICY_SOURCES = ['none', 'user', 'repo', 'unreadable'];
|
|
52
|
+
const SECTIONS = [
|
|
53
|
+
'versions',
|
|
54
|
+
'config',
|
|
55
|
+
'library',
|
|
56
|
+
'scopes',
|
|
57
|
+
'index',
|
|
58
|
+
'queue',
|
|
59
|
+
'curator',
|
|
60
|
+
'tokens',
|
|
61
|
+
'recent',
|
|
62
|
+
'orphans',
|
|
63
|
+
];
|
|
64
|
+
const OTHER = 'other';
|
|
65
|
+
/** The one line RV-55 asks for. A constant of this file, never data. */
|
|
66
|
+
const FSCK_NOTE = 'run aragon gene fsck separately';
|
|
67
|
+
/** Every `GeneRunEvent`; typed as a record so a new event is a compile error here. */
|
|
68
|
+
const RUN_EVENTS = {
|
|
69
|
+
reviewing: true,
|
|
70
|
+
reviewed_none: true,
|
|
71
|
+
proposed: true,
|
|
72
|
+
queued: true,
|
|
73
|
+
merged_into_pending: true,
|
|
74
|
+
claimed: true,
|
|
75
|
+
distilling: true,
|
|
76
|
+
deduping: true,
|
|
77
|
+
validating: true,
|
|
78
|
+
validation_failed: true,
|
|
79
|
+
needs_human: true,
|
|
80
|
+
merged: true,
|
|
81
|
+
published: true,
|
|
82
|
+
rejected: true,
|
|
83
|
+
archived: true,
|
|
84
|
+
revoked: true,
|
|
85
|
+
rolled_back: true,
|
|
86
|
+
recheck_flagged: true,
|
|
87
|
+
superseded: true,
|
|
88
|
+
skipped: true,
|
|
89
|
+
paused: true,
|
|
90
|
+
resumed: true,
|
|
91
|
+
retry_scheduled: true,
|
|
92
|
+
dead: true,
|
|
93
|
+
budget_exhausted: true,
|
|
94
|
+
lease_acquired: true,
|
|
95
|
+
lease_lost: true,
|
|
96
|
+
error: true,
|
|
97
|
+
};
|
|
98
|
+
const RUN_EVENT_NAMES = Object.keys(RUN_EVENTS);
|
|
99
|
+
/** How each gene setting is serialised. `teamPath` is a path, so it is reported as a boolean. */
|
|
100
|
+
const CONFIG_SPECS = {
|
|
101
|
+
enabled: 'boolean',
|
|
102
|
+
use: 'boolean',
|
|
103
|
+
autoLearn: 'boolean',
|
|
104
|
+
capPerType: 'number',
|
|
105
|
+
pinnedMax: 'number',
|
|
106
|
+
candidateMax: 'number',
|
|
107
|
+
versionsKept: 'number',
|
|
108
|
+
archiveMaxMB: 'number',
|
|
109
|
+
reviewerMaxItems: 'number',
|
|
110
|
+
reviewerMaxTokens: 'number',
|
|
111
|
+
mainMaxItems: 'number',
|
|
112
|
+
mainMaxTokens: 'number',
|
|
113
|
+
subagentMaxItems: 'number',
|
|
114
|
+
subagentMaxTokens: 'number',
|
|
115
|
+
hints: 'boolean',
|
|
116
|
+
reviewerModel: ['fast', 'main'],
|
|
117
|
+
curatorModel: ['fast', 'main'],
|
|
118
|
+
curatorConcurrency: 'number',
|
|
119
|
+
curatorTaskTokens: 'number',
|
|
120
|
+
dailyTokens: 'number',
|
|
121
|
+
learnMinIntervalSec: 'number',
|
|
122
|
+
learnMaxPerSession: 'number',
|
|
123
|
+
toolsAllowNetwork: 'boolean',
|
|
124
|
+
probeMode: ['readonly', 'off'],
|
|
125
|
+
teamTrusted: 'boolean',
|
|
126
|
+
key: ['ctrl+q', 'ctrl+y', 'none'],
|
|
127
|
+
explainLanguage: ['auto', 'zh', 'off'],
|
|
128
|
+
holdoutPercent: 'number',
|
|
129
|
+
importMaxItems: 'number',
|
|
130
|
+
};
|
|
131
|
+
const CONFIG_KEYS = Object.keys(CONFIG_SPECS);
|
|
132
|
+
/**
|
|
133
|
+
* Every string a bundle may hold other than a `projectRef` / `holderRef`. The tests assert that a
|
|
134
|
+
* generated bundle uses nothing outside this set, which keeps the vocabulary the single place a
|
|
135
|
+
* new word has to be added.
|
|
136
|
+
*/
|
|
137
|
+
export const DIAG_STRING_VOCABULARY = new Set([
|
|
138
|
+
OTHER,
|
|
139
|
+
FSCK_NOTE,
|
|
140
|
+
...TYPES,
|
|
141
|
+
...OS_NAMES,
|
|
142
|
+
...ARCHES,
|
|
143
|
+
...LEASE_STATES,
|
|
144
|
+
...LEASE_KINDS,
|
|
145
|
+
...SCOPE_KINDS,
|
|
146
|
+
...CONFIG_SOURCES,
|
|
147
|
+
...POLICY_SOURCES,
|
|
148
|
+
...SECTIONS,
|
|
149
|
+
...RUN_EVENT_NAMES,
|
|
150
|
+
...Object.values(CONFIG_SPECS).flatMap((spec) => (Array.isArray(spec) ? spec : [])),
|
|
151
|
+
]);
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// The coercers
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
const COUNT_CEILING = 1e13;
|
|
156
|
+
const REF8 = /^[0-9a-f]{8}$/;
|
|
157
|
+
const VERSION = /^(\d{1,5})\.(\d{1,5})\.(\d{1,5})(?:[-+][0-9A-Za-z.-]{0,40})?$/;
|
|
158
|
+
function count(value) {
|
|
159
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
|
|
160
|
+
return 0;
|
|
161
|
+
return Math.min(COUNT_CEILING, Math.trunc(value));
|
|
162
|
+
}
|
|
163
|
+
function flag(value) {
|
|
164
|
+
return value === true;
|
|
165
|
+
}
|
|
166
|
+
function pick(value, allowed) {
|
|
167
|
+
return typeof value === 'string' && allowed.includes(value)
|
|
168
|
+
? value
|
|
169
|
+
: OTHER;
|
|
170
|
+
}
|
|
171
|
+
function ref8(value) {
|
|
172
|
+
return typeof value === 'string' && REF8.test(value) ? value : null;
|
|
173
|
+
}
|
|
174
|
+
/** The last eight hex characters of a project key (`<slug>-<8 hex>`), or null. */
|
|
175
|
+
export function projectRefOf(key) {
|
|
176
|
+
return ref8(key.slice(-8));
|
|
177
|
+
}
|
|
178
|
+
function triple(value) {
|
|
179
|
+
if (typeof value !== 'string')
|
|
180
|
+
return null;
|
|
181
|
+
const match = VERSION.exec(value.trim());
|
|
182
|
+
return match === null ? null : [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
183
|
+
}
|
|
184
|
+
function byType(value) {
|
|
185
|
+
const source = (value ?? {});
|
|
186
|
+
return { knowledge: count(source.knowledge), tool: count(source.tool), skill: count(source.skill) };
|
|
187
|
+
}
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
// The whitelist serializer
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
function ageOrNull(value) {
|
|
192
|
+
return typeof value === 'number' && Number.isFinite(value) ? count(value) : null;
|
|
193
|
+
}
|
|
194
|
+
function configSection(facts) {
|
|
195
|
+
const values = {};
|
|
196
|
+
const sources = {};
|
|
197
|
+
for (const key of CONFIG_KEYS) {
|
|
198
|
+
const spec = CONFIG_SPECS[key];
|
|
199
|
+
const raw = facts.values?.[key];
|
|
200
|
+
if (spec === 'number')
|
|
201
|
+
values[key] = count(raw);
|
|
202
|
+
else if (spec === 'boolean')
|
|
203
|
+
values[key] = flag(raw);
|
|
204
|
+
else
|
|
205
|
+
values[key] = pick(raw, spec);
|
|
206
|
+
const source = facts.sources?.[key];
|
|
207
|
+
sources[key] = CONFIG_SOURCES.includes(source)
|
|
208
|
+
? source
|
|
209
|
+
: 'default';
|
|
210
|
+
}
|
|
211
|
+
return { values, sources, teamPathSet: flag(facts.teamPathSet) };
|
|
212
|
+
}
|
|
213
|
+
function policySection(policy) {
|
|
214
|
+
const projectRef = ref8(policy?.projectRef);
|
|
215
|
+
if (policy === null || policy === undefined || projectRef === null)
|
|
216
|
+
return null;
|
|
217
|
+
return {
|
|
218
|
+
projectRef,
|
|
219
|
+
learn: flag(policy.learn),
|
|
220
|
+
source: pick(policy.source, POLICY_SOURCES),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function scopeSection(scope) {
|
|
224
|
+
const kind = pick(scope.kind, SCOPE_KINDS);
|
|
225
|
+
const projectRef = kind === 'project' && typeof scope.projectKey === 'string' ? projectRefOf(scope.projectKey) : null;
|
|
226
|
+
const index = scope.index ?? {};
|
|
227
|
+
return {
|
|
228
|
+
kind,
|
|
229
|
+
projectRef,
|
|
230
|
+
scopeCount: count(scope.scopeCount),
|
|
231
|
+
current: flag(scope.current),
|
|
232
|
+
published: byType(scope.published),
|
|
233
|
+
pinned: byType(scope.pinned),
|
|
234
|
+
candidates: count(scope.candidates),
|
|
235
|
+
archived: count(scope.archived),
|
|
236
|
+
archivedBytes: count(scope.archivedBytes),
|
|
237
|
+
index: {
|
|
238
|
+
present: flag(index.present),
|
|
239
|
+
generation: count(index.generation),
|
|
240
|
+
rows: count(index.rows),
|
|
241
|
+
journalBytes: count(index.journalBytes),
|
|
242
|
+
builtAgeSec: ageOrNull(index.builtAgeSec),
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function curatorSection(facts) {
|
|
247
|
+
const held = facts.lease === 'self' || facts.lease === 'other';
|
|
248
|
+
if (!held)
|
|
249
|
+
return { lease: 'none', holderRef: null, kind: null, heartbeatAgeSec: null };
|
|
250
|
+
const kind = pick(facts.kind, LEASE_KINDS);
|
|
251
|
+
return {
|
|
252
|
+
lease: facts.lease,
|
|
253
|
+
holderRef: typeof facts.holderPid === 'number' ? hashPid(facts.holderPid) : null,
|
|
254
|
+
kind: kind === OTHER ? null : kind,
|
|
255
|
+
heartbeatAgeSec: ageOrNull(facts.heartbeatAgeSec),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/** A process id, hashed: stable within one report and across reports, not reversible by reading. */
|
|
259
|
+
function hashPid(pid) {
|
|
260
|
+
return sha1Hex(`gene-diag-holder:${count(pid)}`).slice(0, 8);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Build the bundle from collected facts. PURE. Every value in the result went through a coercer
|
|
264
|
+
* above; see the file header for what that rules out.
|
|
265
|
+
*/
|
|
266
|
+
export function buildDiagBundle(facts) {
|
|
267
|
+
const queue = facts.queue ?? {};
|
|
268
|
+
const library = facts.library ?? {};
|
|
269
|
+
const unavailable = (facts.unavailable ?? [])
|
|
270
|
+
.filter((name) => SECTIONS.includes(name))
|
|
271
|
+
.filter((name, index, all) => all.indexOf(name) === index);
|
|
272
|
+
return {
|
|
273
|
+
schema: 1,
|
|
274
|
+
generatedAt: count(facts.now),
|
|
275
|
+
versions: {
|
|
276
|
+
cli: triple(facts.versions.cli),
|
|
277
|
+
core: triple(facts.versions.core),
|
|
278
|
+
tui: triple(facts.versions.tui),
|
|
279
|
+
node: triple(facts.versions.node),
|
|
280
|
+
},
|
|
281
|
+
platform: { os: pick(facts.platform.os, OS_NAMES), arch: pick(facts.platform.arch, ARCHES) },
|
|
282
|
+
config: configSection(facts.config),
|
|
283
|
+
switches: { envKillSwitch: flag(facts.envKillSwitch) },
|
|
284
|
+
projectPolicy: policySection(facts.projectPolicy),
|
|
285
|
+
library: {
|
|
286
|
+
published: byType(library.published),
|
|
287
|
+
pinned: byType(library.pinned),
|
|
288
|
+
candidates: byType(library.candidates),
|
|
289
|
+
archivedBytes: count(library.archivedBytes),
|
|
290
|
+
},
|
|
291
|
+
scopes: (facts.scopes ?? []).map(scopeSection),
|
|
292
|
+
scopesOmitted: count(facts.scopesOmitted),
|
|
293
|
+
queue: {
|
|
294
|
+
pending: count(queue.pending),
|
|
295
|
+
claimed: count(queue.claimed),
|
|
296
|
+
dead: count(queue.dead),
|
|
297
|
+
done: count(queue.done),
|
|
298
|
+
oldestPendingAgeSec: ageOrNull(queue.oldestPendingAgeSec),
|
|
299
|
+
oldestClaimedAgeSec: ageOrNull(queue.oldestClaimedAgeSec),
|
|
300
|
+
},
|
|
301
|
+
curator: curatorSection(facts.curator ?? {}),
|
|
302
|
+
tokens: { today: count(facts.tokens?.today), budget: count(facts.tokens?.budget) },
|
|
303
|
+
recent: (facts.recent ?? []).slice(0, RECENT_RUNS).map((record) => {
|
|
304
|
+
const type = pick(record.type, TYPES);
|
|
305
|
+
return {
|
|
306
|
+
t: count(record.t),
|
|
307
|
+
ev: pick(record.ev, RUN_EVENT_NAMES),
|
|
308
|
+
type: type === OTHER ? null : type,
|
|
309
|
+
};
|
|
310
|
+
}),
|
|
311
|
+
orphans: {
|
|
312
|
+
orphanScopes: count(facts.orphans?.orphanScopes),
|
|
313
|
+
unrecordedScopes: count(facts.orphans?.unrecordedScopes),
|
|
314
|
+
},
|
|
315
|
+
unavailable,
|
|
316
|
+
notes: [FSCK_NOTE],
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/** The text that is written to the file: stable key order, two-space indent, trailing newline. */
|
|
320
|
+
export function renderDiagBundle(bundle) {
|
|
321
|
+
return `${JSON.stringify(bundle, null, 2)}\n`;
|
|
322
|
+
}
|
|
323
|
+
// ---------------------------------------------------------------------------
|
|
324
|
+
// Collection
|
|
325
|
+
// ---------------------------------------------------------------------------
|
|
326
|
+
export const RECENT_RUNS = 50;
|
|
327
|
+
/** Project scopes listed individually; the rest are only counted. */
|
|
328
|
+
export const SCOPES_LISTED_MAX = 50;
|
|
329
|
+
function readPackageJsonVersion(file) {
|
|
330
|
+
try {
|
|
331
|
+
const pkg = JSON.parse(readFileSync(file, 'utf-8'));
|
|
332
|
+
return typeof pkg.version === 'string' ? pkg.version : undefined;
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/** The version of an installed `@aragon-agent/<name>`: the first directory up that holds it. */
|
|
339
|
+
function installedVersion(name) {
|
|
340
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
341
|
+
for (let depth = 0; depth < 10; depth += 1) {
|
|
342
|
+
const found = readPackageJsonVersion(join(dir, 'node_modules', '@aragon-agent', name, 'package.json'));
|
|
343
|
+
if (found !== undefined)
|
|
344
|
+
return found;
|
|
345
|
+
const parent = dirname(dir);
|
|
346
|
+
if (parent === dir)
|
|
347
|
+
break;
|
|
348
|
+
dir = parent;
|
|
349
|
+
}
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
function defaultVersions() {
|
|
353
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
354
|
+
return {
|
|
355
|
+
cli: readPackageJsonVersion(join(here, '..', '..', 'package.json')),
|
|
356
|
+
core: installedVersion('core'),
|
|
357
|
+
tui: installedVersion('tui'),
|
|
358
|
+
node: process.versions.node,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function defaultConfigFile() {
|
|
362
|
+
const gene = readConfigFile().config?.gene;
|
|
363
|
+
return typeof gene === 'object' && gene !== null ? gene : null;
|
|
364
|
+
}
|
|
365
|
+
function defaultKillSwitch() {
|
|
366
|
+
const value = process.env.ARAGON_GENE?.trim().toLowerCase();
|
|
367
|
+
return value === '0' || value === 'false' || value === 'off' || value === 'no';
|
|
368
|
+
}
|
|
369
|
+
function configFacts(config, file, killed) {
|
|
370
|
+
const values = {};
|
|
371
|
+
const sources = {};
|
|
372
|
+
for (const key of CONFIG_KEYS) {
|
|
373
|
+
values[key] = config[key];
|
|
374
|
+
const inFile = file !== null && file[key] !== undefined;
|
|
375
|
+
sources[key] = key === 'enabled' && killed ? 'env' : inFile ? 'file' : 'default';
|
|
376
|
+
}
|
|
377
|
+
return { values, sources, teamPathSet: config.teamPath.length > 0 };
|
|
378
|
+
}
|
|
379
|
+
async function indexFacts(store, scope, now) {
|
|
380
|
+
const snapshot = await store.readSnapshot(scope);
|
|
381
|
+
const journal = await store.statIndexFile(scope, 'journal.jsonl');
|
|
382
|
+
return {
|
|
383
|
+
present: snapshot !== null,
|
|
384
|
+
generation: snapshot?.gen ?? 0,
|
|
385
|
+
rows: snapshot?.count ?? 0,
|
|
386
|
+
journalBytes: journal?.size ?? 0,
|
|
387
|
+
builtAgeSec: snapshot === null ? null : Math.max(0, Math.round((now - snapshot.builtAt) / 1000)),
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
async function oneScope(core, scope) {
|
|
391
|
+
const store = core.lib.store;
|
|
392
|
+
const counts = await store.readCounts(scope);
|
|
393
|
+
const archived = await store.listArchivedIds(scope);
|
|
394
|
+
return {
|
|
395
|
+
kind: scope.kind,
|
|
396
|
+
...(scope.kind === 'project' ? { projectKey: scope.key } : {}),
|
|
397
|
+
scopeCount: 1,
|
|
398
|
+
current: scope.kind === 'project' && scope.key === core.project()?.key,
|
|
399
|
+
published: counts?.published,
|
|
400
|
+
pinned: counts?.pinned,
|
|
401
|
+
candidates: counts?.candidates,
|
|
402
|
+
archived: archived.length,
|
|
403
|
+
archivedBytes: counts?.archivedBytes,
|
|
404
|
+
index: await indexFacts(store, scope, core.now()),
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
function addByType(a, b) {
|
|
408
|
+
const x = byType(a);
|
|
409
|
+
const y = byType(b);
|
|
410
|
+
return { knowledge: x.knowledge + y.knowledge, tool: x.tool + y.tool, skill: x.skill + y.skill };
|
|
411
|
+
}
|
|
412
|
+
/** Task and team scopes are keyed by a session id / a folder name: merged, never listed. */
|
|
413
|
+
function mergeScopes(list) {
|
|
414
|
+
const merged = new Map();
|
|
415
|
+
const out = [];
|
|
416
|
+
for (const entry of list) {
|
|
417
|
+
const kind = entry.kind === 'task' || entry.kind === 'team' ? entry.kind : null;
|
|
418
|
+
const target = kind === null ? undefined : merged.get(kind);
|
|
419
|
+
if (kind === null) {
|
|
420
|
+
out.push(entry);
|
|
421
|
+
}
|
|
422
|
+
else if (target === undefined) {
|
|
423
|
+
const first = { ...entry, index: undefined };
|
|
424
|
+
merged.set(kind, first);
|
|
425
|
+
out.push(first);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
target.scopeCount = count(target.scopeCount) + 1;
|
|
429
|
+
target.published = addByType(target.published, entry.published);
|
|
430
|
+
target.pinned = addByType(target.pinned, entry.pinned);
|
|
431
|
+
target.candidates = count(target.candidates) + count(entry.candidates);
|
|
432
|
+
target.archived = count(target.archived) + count(entry.archived);
|
|
433
|
+
target.archivedBytes = count(target.archivedBytes) + count(entry.archivedBytes);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return out;
|
|
437
|
+
}
|
|
438
|
+
async function scopesFacts(core) {
|
|
439
|
+
const all = await core.lib.store.listScopes();
|
|
440
|
+
const listed = all.slice(0, SCOPES_LISTED_MAX * 4);
|
|
441
|
+
const entries = [];
|
|
442
|
+
for (const scope of listed)
|
|
443
|
+
entries.push(await oneScope(core, scope));
|
|
444
|
+
const merged = mergeScopes(entries);
|
|
445
|
+
const shown = merged.slice(0, SCOPES_LISTED_MAX);
|
|
446
|
+
return {
|
|
447
|
+
scopes: shown,
|
|
448
|
+
scopesOmitted: merged.length - shown.length + (all.length - listed.length),
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
async function oldestAgeSec(core, state) {
|
|
452
|
+
const entries = await core.lib.queue.list(state);
|
|
453
|
+
const times = entries.map((entry) => entry.parsed?.createdAt ?? entry.mtimeMs);
|
|
454
|
+
return times.length === 0 ? null : Math.max(0, Math.round((core.now() - Math.min(...times)) / 1000));
|
|
455
|
+
}
|
|
456
|
+
async function queueFacts(core) {
|
|
457
|
+
const counts = await core.lib.queue.counts();
|
|
458
|
+
return {
|
|
459
|
+
...counts,
|
|
460
|
+
oldestPendingAgeSec: await oldestAgeSec(core, 'pending'),
|
|
461
|
+
oldestClaimedAgeSec: await oldestAgeSec(core, 'claimed'),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
async function curatorFacts(core) {
|
|
465
|
+
const info = (await readLock(curatorLeaseFile(core.lib.ctx)));
|
|
466
|
+
if (info === null)
|
|
467
|
+
return { lease: 'none' };
|
|
468
|
+
return {
|
|
469
|
+
lease: info.pid === process.pid ? 'self' : 'other',
|
|
470
|
+
holderPid: info.pid,
|
|
471
|
+
kind: info.kind,
|
|
472
|
+
heartbeatAgeSec: Math.max(0, Math.round((core.now() - info.heartbeatAt) / 1000)),
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
/** Run a section; a failure becomes an `unavailable` entry instead of an exception. */
|
|
476
|
+
async function section(name, facts, run) {
|
|
477
|
+
try {
|
|
478
|
+
Object.assign(facts, await run());
|
|
479
|
+
}
|
|
480
|
+
catch {
|
|
481
|
+
facts.unavailable = [...(facts.unavailable ?? []), name];
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/** Gather the facts of a bundle from the live library. Never throws, never writes. */
|
|
485
|
+
export async function collectDiagFacts(core, options = {}) {
|
|
486
|
+
const killed = (options.envKillSwitch ?? defaultKillSwitch)();
|
|
487
|
+
const facts = {
|
|
488
|
+
now: core.now(),
|
|
489
|
+
versions: (options.versions ?? defaultVersions)(),
|
|
490
|
+
platform: { os: process.platform, arch: process.arch },
|
|
491
|
+
config: configFacts(core.config(), safeFile(options.configFile ?? defaultConfigFile), killed),
|
|
492
|
+
envKillSwitch: killed,
|
|
493
|
+
projectPolicy: options.projectPolicy ?? null,
|
|
494
|
+
unavailable: [],
|
|
495
|
+
};
|
|
496
|
+
await section('scopes', facts, () => scopesFacts(core));
|
|
497
|
+
await section('queue', facts, async () => ({ queue: await queueFacts(core) }));
|
|
498
|
+
await section('curator', facts, async () => ({ curator: await curatorFacts(core) }));
|
|
499
|
+
await section('tokens', facts, async () => ({
|
|
500
|
+
tokens: { today: await tokensToday(core), budget: core.config().dailyTokens },
|
|
501
|
+
}));
|
|
502
|
+
await section('recent', facts, async () => ({
|
|
503
|
+
recent: (await core.lib.runLog.read({ limit: RECENT_RUNS })).records,
|
|
504
|
+
}));
|
|
505
|
+
await section('orphans', facts, async () => {
|
|
506
|
+
const audit = await auditProjectScopes(core.lib.store);
|
|
507
|
+
return {
|
|
508
|
+
orphans: { orphanScopes: audit.orphans.length, unrecordedScopes: audit.unrecorded.length },
|
|
509
|
+
};
|
|
510
|
+
});
|
|
511
|
+
await section('library', facts, async () => ({ library: await core.lib.versions.totals() }));
|
|
512
|
+
return facts;
|
|
513
|
+
}
|
|
514
|
+
function safeFile(read) {
|
|
515
|
+
try {
|
|
516
|
+
return read();
|
|
517
|
+
}
|
|
518
|
+
catch {
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/** Collect and serialise in one step. */
|
|
523
|
+
export async function createDiagBundle(core, options = {}) {
|
|
524
|
+
return buildDiagBundle(await collectDiagFacts(core, options));
|
|
525
|
+
}
|
|
526
|
+
/** `<genes>/diag/gene-diag.json`: where `/gene diag` writes when no file is named. */
|
|
527
|
+
export function defaultDiagFile(root) {
|
|
528
|
+
return join(geneRoot(root === undefined ? undefined : { root }), 'diag', 'gene-diag.json');
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Write the bundle to `path`. A file somebody else named is never overwritten unless `overwrite`:
|
|
532
|
+
* `--out README.md` must not destroy a README. Never throws.
|
|
533
|
+
*/
|
|
534
|
+
export async function writeDiagFile(path, bundle, overwrite) {
|
|
535
|
+
try {
|
|
536
|
+
await nodeFs.mkdir(dirname(path), { recursive: true });
|
|
537
|
+
}
|
|
538
|
+
catch {
|
|
539
|
+
return { ok: false, reason: 'io' };
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
await nodeFs.writeFile(path, renderDiagBundle(bundle), { flag: overwrite ? 'w' : 'wx' });
|
|
543
|
+
return { ok: true, path };
|
|
544
|
+
}
|
|
545
|
+
catch (error) {
|
|
546
|
+
const code = error?.code;
|
|
547
|
+
return { ok: false, reason: code === 'EEXIST' ? 'exists' : 'io' };
|
|
548
|
+
}
|
|
549
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EnvFingerprint } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
/** Never throws; unknown fields are omitted. */
|
|
3
|
+
export declare function captureEnvFingerprint(cwd: string): EnvFingerprint;
|
|
4
|
+
/**
|
|
5
|
+
* `(glob) => boolean`: does anything under `cwd` match? Walks breadth-first, capped at
|
|
6
|
+
* `GLOB_ENTRY_CAP` entries per call, skipping dependency and build directories.
|
|
7
|
+
*/
|
|
8
|
+
export declare function makeGlobMatcher(cwd: string): (glob: string) => boolean;
|
|
9
|
+
/** Do two fingerprints differ in a field a gene may have pinned via `envStamp`? */
|
|
10
|
+
export declare function envStampMismatches(stamp: Record<string, string>, current: EnvFingerprint): string[];
|