@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,170 @@
|
|
|
1
|
+
import { rowFromHead } from '@aragon-agent/tui/model/gene/row';
|
|
2
|
+
import { geneOk } from './gene-errors.js';
|
|
3
|
+
import { enrichRows } from './manager-view.js';
|
|
4
|
+
import { auditProjectScopes } from './orphan-scopes.js';
|
|
5
|
+
const ALL_STATUSES = [
|
|
6
|
+
'candidate',
|
|
7
|
+
'published',
|
|
8
|
+
'archived',
|
|
9
|
+
'rejected',
|
|
10
|
+
'revoked',
|
|
11
|
+
];
|
|
12
|
+
const SEARCH_CHUNK = 1000;
|
|
13
|
+
const PAGE_MAX = 200;
|
|
14
|
+
const ARCHIVE_READ_CEILING = 500;
|
|
15
|
+
const TYPES = ['knowledge', 'tool', 'skill'];
|
|
16
|
+
export function decodeCursor(cursor) {
|
|
17
|
+
const match = /^o(\d{1,7})$/.exec(cursor ?? '');
|
|
18
|
+
return match === null ? 0 : Number.parseInt(match[1], 10);
|
|
19
|
+
}
|
|
20
|
+
function encodeCursor(offset) {
|
|
21
|
+
return `o${offset}`;
|
|
22
|
+
}
|
|
23
|
+
/** The filters the search index cannot express, one predicate each. */
|
|
24
|
+
const EXTRA_FILTERS = [
|
|
25
|
+
(row, f) => f.health === undefined || f.health === 'any' || row.health === f.health,
|
|
26
|
+
(row, f) => f.pinned !== 'yes' || row.pinned,
|
|
27
|
+
(row, f) => f.pinned !== 'no' || !row.pinned,
|
|
28
|
+
(row, f) => f.trust === undefined || f.trust === 'any' || row.trust === f.trust,
|
|
29
|
+
(row, f) => f.unconfirmed !== true || row.unconfirmed === true,
|
|
30
|
+
(row, f) => f.depWarning !== true || row.health === 'recheck',
|
|
31
|
+
];
|
|
32
|
+
function passesFilter(row, filter) {
|
|
33
|
+
return EXTRA_FILTERS.every((predicate) => predicate(row, filter));
|
|
34
|
+
}
|
|
35
|
+
function matchesShape(row, filter) {
|
|
36
|
+
if (filter.type !== undefined && row.type !== filter.type)
|
|
37
|
+
return false;
|
|
38
|
+
if (filter.scope !== undefined && filter.scope !== 'all' && row.scope.kind !== filter.scope) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return passesFilter(row, filter);
|
|
42
|
+
}
|
|
43
|
+
/** One chunk of the privileged ranking, from `from` on. */
|
|
44
|
+
function searchChunk(core, req, statuses, from) {
|
|
45
|
+
const { filter } = req;
|
|
46
|
+
const options = {
|
|
47
|
+
query: (filter.query ?? '').trim(),
|
|
48
|
+
type: filter.type ?? 'all',
|
|
49
|
+
scope: filter.scope ?? 'all',
|
|
50
|
+
limit: SEARCH_CHUNK,
|
|
51
|
+
offset: from,
|
|
52
|
+
privileged: true,
|
|
53
|
+
statuses,
|
|
54
|
+
now: core.now(),
|
|
55
|
+
};
|
|
56
|
+
return req.catalog.search(options, core.callerFor(req.scopes, []));
|
|
57
|
+
}
|
|
58
|
+
async function collectIndexed(core, req, into) {
|
|
59
|
+
const indexed = req.statuses.filter((status) => status !== 'archived');
|
|
60
|
+
if (indexed.length === 0)
|
|
61
|
+
return;
|
|
62
|
+
let from = 0;
|
|
63
|
+
for (;;) {
|
|
64
|
+
const result = searchChunk(core, req, indexed, from);
|
|
65
|
+
for (const hit of result.hits)
|
|
66
|
+
if (passesFilter(hit.row, req.filter))
|
|
67
|
+
into.rows.push(hit.row);
|
|
68
|
+
from += result.hits.length;
|
|
69
|
+
const exhausted = result.hits.length < SEARCH_CHUNK || from >= result.total;
|
|
70
|
+
if (exhausted || into.rows.length >= into.need)
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function textMatches(row, query) {
|
|
75
|
+
if (query.length === 0)
|
|
76
|
+
return true;
|
|
77
|
+
const { name, purpose, trigger } = row.brief;
|
|
78
|
+
const hay = [name, purpose, trigger, ...row.tags].join(' ').toLowerCase();
|
|
79
|
+
return query
|
|
80
|
+
.toLowerCase()
|
|
81
|
+
.split(/\s+/)
|
|
82
|
+
.filter((word) => word.length > 0)
|
|
83
|
+
.every((word) => hay.includes(word));
|
|
84
|
+
}
|
|
85
|
+
async function collectArchived(core, scopes, filter, into) {
|
|
86
|
+
const found = [];
|
|
87
|
+
let reads = 0;
|
|
88
|
+
for (const scope of scopes) {
|
|
89
|
+
for (const id of await core.lib.store.listArchivedIds(scope)) {
|
|
90
|
+
if (reads >= ARCHIVE_READ_CEILING)
|
|
91
|
+
break;
|
|
92
|
+
reads += 1;
|
|
93
|
+
const read = await core.lib.store.readArchivedHead(scope, id);
|
|
94
|
+
if (read === null)
|
|
95
|
+
continue;
|
|
96
|
+
const row = rowFromHead(read.head, read);
|
|
97
|
+
if (matchesShape(row, filter) && textMatches(row, filter.query ?? ''))
|
|
98
|
+
found.push(row);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
found.sort((a, b) => b.updatedAt - a.updatedAt || a.id.localeCompare(b.id));
|
|
102
|
+
into.rows.push(...found);
|
|
103
|
+
}
|
|
104
|
+
async function countsOf(core, catalog) {
|
|
105
|
+
const loaded = catalog.libraryCounts();
|
|
106
|
+
const counts = {
|
|
107
|
+
knowledge: loaded.knowledge,
|
|
108
|
+
tool: loaded.tool,
|
|
109
|
+
skill: loaded.skill,
|
|
110
|
+
candidates: loaded.candidates,
|
|
111
|
+
pinned: loaded.pinned,
|
|
112
|
+
overCap: {},
|
|
113
|
+
};
|
|
114
|
+
const totals = await core.lib.versions.totals();
|
|
115
|
+
const cap = core.config().capPerType;
|
|
116
|
+
for (const type of TYPES) {
|
|
117
|
+
const over = totals.published[type] - cap;
|
|
118
|
+
if (over > 0)
|
|
119
|
+
counts.overCap[type] = over;
|
|
120
|
+
}
|
|
121
|
+
return counts;
|
|
122
|
+
}
|
|
123
|
+
/** `list`: one page of rows for a target, a filter and a cursor. */
|
|
124
|
+
export async function listGenes(core, req) {
|
|
125
|
+
const scopes = await core.scopesOf(req.target);
|
|
126
|
+
if (!scopes.ok)
|
|
127
|
+
return scopes;
|
|
128
|
+
const catalog = await core.pool.acquire(scopes.value);
|
|
129
|
+
const filter = req.filter ?? {};
|
|
130
|
+
const statuses = filter.status !== undefined && filter.status.length > 0 ? filter.status : [...ALL_STATUSES];
|
|
131
|
+
const limit = Math.min(PAGE_MAX, Math.max(1, Math.trunc(req.limit) || 1));
|
|
132
|
+
const offset = decodeCursor(req.cursor);
|
|
133
|
+
const collected = { rows: [], need: offset + limit + 1 };
|
|
134
|
+
await collectIndexed(core, { catalog, scopes: scopes.value, filter, statuses }, collected);
|
|
135
|
+
if (statuses.includes('archived'))
|
|
136
|
+
await collectArchived(core, scopes.value, filter, collected);
|
|
137
|
+
const page = collected.rows.slice(offset, offset + limit);
|
|
138
|
+
const more = collected.rows.length > offset + limit;
|
|
139
|
+
const result = {
|
|
140
|
+
rows: await enrichRows(core, page),
|
|
141
|
+
counts: await countsOf(core, catalog),
|
|
142
|
+
};
|
|
143
|
+
if (more)
|
|
144
|
+
result.next = encodeCursor(offset + limit);
|
|
145
|
+
if (catalog.state() !== 'ready')
|
|
146
|
+
result.degraded = 'index_rebuilding';
|
|
147
|
+
return geneOk(result);
|
|
148
|
+
}
|
|
149
|
+
/** `projects`: every project scope on disk, labelled from `project.json`, with its counts. */
|
|
150
|
+
export async function listProjects(core) {
|
|
151
|
+
const views = [];
|
|
152
|
+
const orphans = new Map((await auditProjectScopes(core.lib.store)).orphans.map((o) => [o.key, o.reason]));
|
|
153
|
+
for (const scope of await core.lib.store.listScopes()) {
|
|
154
|
+
if (scope.kind !== 'project' || scope.key === undefined)
|
|
155
|
+
continue;
|
|
156
|
+
const meta = await core.lib.store.readProjectMeta(scope);
|
|
157
|
+
const counts = await core.lib.store.readCounts(scope);
|
|
158
|
+
views.push({
|
|
159
|
+
key: scope.key,
|
|
160
|
+
label: meta?.label ?? scope.key,
|
|
161
|
+
counts: {
|
|
162
|
+
knowledge: counts?.published.knowledge ?? 0,
|
|
163
|
+
tool: counts?.published.tool ?? 0,
|
|
164
|
+
skill: counts?.published.skill ?? 0,
|
|
165
|
+
},
|
|
166
|
+
...(orphans.has(scope.key) ? { orphan: orphans.get(scope.key) } : {}),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return geneOk(views.sort((a, b) => a.label.localeCompare(b.label) || a.key.localeCompare(b.key)));
|
|
170
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { GeneActivityPage, GeneActivityRequest, GeneCandidateView, GeneQueueView, GeneTarget } from '@aragon-agent/tui/model/gene/port';
|
|
2
|
+
import type { GeneResult } from '@aragon-agent/tui/model/gene/types';
|
|
3
|
+
import type { ManagerCore } from './manager-context.js';
|
|
4
|
+
/** `queue`: pending, claimed and dead items, each as a path-free row. */
|
|
5
|
+
export declare function queueView(core: ManagerCore): Promise<GeneResult<GeneQueueView>>;
|
|
6
|
+
/** `queueAction`: retry a dead item or discard a pending / dead one. */
|
|
7
|
+
export declare function queueAction(core: ManagerCore, req: {
|
|
8
|
+
id: string;
|
|
9
|
+
action: 'retry' | 'discard';
|
|
10
|
+
}): Promise<GeneResult<{
|
|
11
|
+
id: string;
|
|
12
|
+
}>>;
|
|
13
|
+
/** `activity`: the run log, newest first, with an opaque cursor. */
|
|
14
|
+
export declare function activityPage(core: ManagerCore, req: GeneActivityRequest): Promise<GeneResult<GeneActivityPage>>;
|
|
15
|
+
/** `candidates`: candidates and revisions that wait on a person, oldest decision first. */
|
|
16
|
+
export declare function candidateViews(core: ManagerCore, target: GeneTarget): Promise<GeneResult<GeneCandidateView[]>>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The manager's processing pages: the queue, the activity feed and the candidates
|
|
3
|
+
* (gene-bank spec 12.2, 12.4, 16.6).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* NOTHING HERE PROCESSES ANYTHING. The queue and the run log belong to the curator; this file only
|
|
8
|
+
* shows them, and offers the two things a person may do to a stuck item: retry it (a dead item
|
|
9
|
+
* goes back to `pending` with a clean slate) or discard it. Both are the queue's own methods, which
|
|
10
|
+
* take the item's lock, so they are safe while a curator in another process is running.
|
|
11
|
+
*
|
|
12
|
+
* THE CANDIDATE PAGE CARRIES WHAT MUST BE READ BEFORE APPROVING. For an item waiting on a probe
|
|
13
|
+
* approval or a high-risk confirmation, `probePreview` is the FULL argv, script or composite steps
|
|
14
|
+
* that approving would run (RV-1): the person approves what they saw, not a summary of it. The
|
|
15
|
+
* `risk` and `permissions` shown are RECOMPUTED by the static screen, never the gene's own claim.
|
|
16
|
+
*/
|
|
17
|
+
import { isValidProposalId } from '@aragon-agent/tui/model/gene/ids';
|
|
18
|
+
import { geneFail, geneOk } from './gene-errors.js';
|
|
19
|
+
import { rowViewOfHead } from './manager-view.js';
|
|
20
|
+
import { toQueueEntryView } from './queue.js';
|
|
21
|
+
import { screenToolExec } from './tool-screen.js';
|
|
22
|
+
const CANDIDATES_SHOWN = 200;
|
|
23
|
+
const PAGE_MAX = 500;
|
|
24
|
+
/** `queue`: pending, claimed and dead items, each as a path-free row. */
|
|
25
|
+
export async function queueView(core) {
|
|
26
|
+
const view = { pending: [], claimed: [], dead: [] };
|
|
27
|
+
for (const state of ['pending', 'claimed', 'dead']) {
|
|
28
|
+
for (const entry of await core.lib.queue.list(state)) {
|
|
29
|
+
const row = toQueueEntryView(entry);
|
|
30
|
+
if (row !== null)
|
|
31
|
+
view[state].push(row);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return geneOk(view);
|
|
35
|
+
}
|
|
36
|
+
/** `queueAction`: retry a dead item or discard a pending / dead one. */
|
|
37
|
+
export async function queueAction(core, req) {
|
|
38
|
+
if (!isValidProposalId(req.id)) {
|
|
39
|
+
return geneFail('GENE_INVALID_ID', 'That is not a valid queue item id.');
|
|
40
|
+
}
|
|
41
|
+
const done = req.action === 'retry'
|
|
42
|
+
? await core.lib.queue.retryDead(req.id)
|
|
43
|
+
: await core.lib.queue.discard(req.id);
|
|
44
|
+
if (!done)
|
|
45
|
+
return geneFail('GENE_NOT_FOUND', 'No such queue item in that state.', req.action);
|
|
46
|
+
return geneOk({ id: req.id });
|
|
47
|
+
}
|
|
48
|
+
/** `activity`: the run log, newest first, with an opaque cursor. */
|
|
49
|
+
export async function activityPage(core, req) {
|
|
50
|
+
const page = await core.lib.runLog.read({
|
|
51
|
+
limit: Math.min(PAGE_MAX, Math.max(1, Math.trunc(req.limit) || 1)),
|
|
52
|
+
...(req.cursor === undefined ? {} : { cursor: req.cursor }),
|
|
53
|
+
...(req.events === undefined ? {} : { events: req.events }),
|
|
54
|
+
});
|
|
55
|
+
return geneOk(page.next === undefined
|
|
56
|
+
? { records: page.records }
|
|
57
|
+
: { records: page.records, next: page.next });
|
|
58
|
+
}
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// candidates
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
function previewText(exec, script) {
|
|
63
|
+
if (exec.kind === 'command')
|
|
64
|
+
return { kind: 'command', text: exec.argv.join(' ') };
|
|
65
|
+
if (exec.kind === 'composite') {
|
|
66
|
+
return { kind: 'composite', text: JSON.stringify(exec.steps, null, 2) };
|
|
67
|
+
}
|
|
68
|
+
const head = `${exec.interpreter} ${exec.args.join(' ')}`.trim();
|
|
69
|
+
const body = script === undefined ? '(the script text is not stored)' : script;
|
|
70
|
+
return { kind: 'script', text: `${head}\n\n${body}` };
|
|
71
|
+
}
|
|
72
|
+
async function probePreviewOf(core, scope, head, version) {
|
|
73
|
+
const reason = head.needsHuman?.reason;
|
|
74
|
+
const needsApproval = reason === 'probe_approval' || reason === 'high_risk_tool';
|
|
75
|
+
if (head.type !== 'tool' || !needsApproval)
|
|
76
|
+
return undefined;
|
|
77
|
+
const payload = version.content.payload;
|
|
78
|
+
if (payload.exec === undefined)
|
|
79
|
+
return undefined;
|
|
80
|
+
const script = payload.exec.kind === 'script'
|
|
81
|
+
? (await core.lib.store.readEvidence(scope, head.id, payload.exec.evidence))?.text
|
|
82
|
+
: undefined;
|
|
83
|
+
const screened = screenToolExec(payload.exec, script);
|
|
84
|
+
const shown = previewText(payload.exec, script);
|
|
85
|
+
return { ...shown, risk: screened.risk, permissions: screened.permissions };
|
|
86
|
+
}
|
|
87
|
+
async function candidateOf(core, scope, id) {
|
|
88
|
+
const read = await core.lib.store.readHead(scope, id);
|
|
89
|
+
if (read === null)
|
|
90
|
+
return null;
|
|
91
|
+
const head = read.head;
|
|
92
|
+
const number = head.candidateVersion ?? (head.status === 'candidate' ? head.latestVersion : null);
|
|
93
|
+
if (number === null)
|
|
94
|
+
return null;
|
|
95
|
+
const version = await core.lib.store.readVersion(scope, id, number);
|
|
96
|
+
const view = { row: rowViewOfHead(read) };
|
|
97
|
+
if (head.needsHuman !== undefined) {
|
|
98
|
+
view.needsHuman = { reason: head.needsHuman.reason, at: head.needsHuman.at };
|
|
99
|
+
}
|
|
100
|
+
if (version === null)
|
|
101
|
+
return view;
|
|
102
|
+
if (version.validation !== undefined)
|
|
103
|
+
view.validation = version.validation;
|
|
104
|
+
const preview = await probePreviewOf(core, scope, head, version);
|
|
105
|
+
if (preview !== undefined)
|
|
106
|
+
view.probePreview = preview;
|
|
107
|
+
return view;
|
|
108
|
+
}
|
|
109
|
+
/** `candidates`: candidates and revisions that wait on a person, oldest decision first. */
|
|
110
|
+
export async function candidateViews(core, target) {
|
|
111
|
+
const scopes = await core.scopesOf(target);
|
|
112
|
+
if (!scopes.ok)
|
|
113
|
+
return scopes;
|
|
114
|
+
const catalog = await core.pool.acquire(scopes.value);
|
|
115
|
+
const wanted = [...catalog.rows()].filter((row) => row.status === 'candidate' || row.needsHuman === true);
|
|
116
|
+
wanted.sort((a, b) => a.updatedAt - b.updatedAt || a.id.localeCompare(b.id));
|
|
117
|
+
const views = [];
|
|
118
|
+
for (const row of wanted.slice(0, CANDIDATES_SHOWN)) {
|
|
119
|
+
const view = await candidateOf(core, row.scope, row.id);
|
|
120
|
+
if (view !== null)
|
|
121
|
+
views.push(view);
|
|
122
|
+
}
|
|
123
|
+
return geneOk(views);
|
|
124
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The manager's numbers: the evaluation summary and the token meter (gene-bank spec 13.4, 12.8).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* THE SUMMARY IS `summarize()` OVER `eval/*.jsonl`, NOTHING MORE. The arithmetic (Wilson interval,
|
|
7
|
+
* recurrence, overhead share, "not enough runs") lives in the pure model so the stats page and a
|
|
8
|
+
* test compute it identically; this file only feeds it records and the two optional facts that
|
|
9
|
+
* turn two of its rates from `null` into numbers:
|
|
10
|
+
*
|
|
11
|
+
* - `coveredSigs`: the error signatures a PUBLISHED knowledge gene claims to resolve, so a
|
|
12
|
+
* recurrence can be split into "covered by a gene" and "not covered". Reading them means
|
|
13
|
+
* opening the current version of each knowledge gene, which is bounded (`COVERAGE_READS`)
|
|
14
|
+
* and skipped past the bound: a partial set would label real coverage "uncovered".
|
|
15
|
+
* - `harmedByGene`: the per-gene `harmed` counters, from the statistics the catalog already
|
|
16
|
+
* caches, for the "most often harmful" list.
|
|
17
|
+
*
|
|
18
|
+
* THE LOOK-BACK. A recurrence ("have I seen this error before") needs runs from BEFORE the window,
|
|
19
|
+
* so records are read 30 days further back than the window starts; `summarize` uses them only as
|
|
20
|
+
* look-back.
|
|
21
|
+
*/
|
|
22
|
+
import type { GeneEvalSummary, GeneStatsRequest } from '@aragon-agent/tui/model/gene/port';
|
|
23
|
+
import type { GeneResult } from '@aragon-agent/tui/model/gene/types';
|
|
24
|
+
import type { ManagerCore } from './manager-context.js';
|
|
25
|
+
/** `stats`: the rolled-up evaluation for a window. */
|
|
26
|
+
export declare function statsView(core: ManagerCore, req: GeneStatsRequest): Promise<GeneResult<GeneEvalSummary>>;
|
|
27
|
+
/** Tokens the learning machinery spent in the last 24 hours, summed over every process. */
|
|
28
|
+
export declare function tokensToday(core: ManagerCore): Promise<number>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { summarize } from '@aragon-agent/tui/model/gene/eval';
|
|
2
|
+
import { geneOk } from './gene-errors.js';
|
|
3
|
+
const DAY_MS = 86_400_000;
|
|
4
|
+
const LOOK_BACK_DAYS = 30;
|
|
5
|
+
const COVERAGE_READS = 1500;
|
|
6
|
+
const WINDOW_DAYS = {
|
|
7
|
+
'7d': 7,
|
|
8
|
+
'30d': 30,
|
|
9
|
+
all: null,
|
|
10
|
+
};
|
|
11
|
+
/** Error signatures the published knowledge genes of the visible scopes claim to resolve. */
|
|
12
|
+
async function coveredSignatures(core) {
|
|
13
|
+
const catalog = await core.pool.acquire(core.visibleScopes());
|
|
14
|
+
const rows = [...catalog.rows()].filter((row) => row.type === 'knowledge' && row.status === 'published');
|
|
15
|
+
if (rows.length > COVERAGE_READS)
|
|
16
|
+
return undefined;
|
|
17
|
+
const covered = new Set();
|
|
18
|
+
for (const row of rows) {
|
|
19
|
+
const version = await core.lib.store.readVersion(row.scope, row.id, row.v);
|
|
20
|
+
const resolves = version?.content.payload?.resolves;
|
|
21
|
+
for (const signature of Array.isArray(resolves) ? resolves : [])
|
|
22
|
+
covered.add(signature);
|
|
23
|
+
}
|
|
24
|
+
return covered;
|
|
25
|
+
}
|
|
26
|
+
async function harmedCounts(core) {
|
|
27
|
+
const catalog = await core.pool.acquire(core.visibleScopes());
|
|
28
|
+
const harmed = new Map();
|
|
29
|
+
for (const row of catalog.rows()) {
|
|
30
|
+
const count = catalog.statsOf(row.id)?.harmed ?? 0;
|
|
31
|
+
if (count > 0)
|
|
32
|
+
harmed.set(row.id, count);
|
|
33
|
+
}
|
|
34
|
+
return harmed;
|
|
35
|
+
}
|
|
36
|
+
/** `stats`: the rolled-up evaluation for a window. */
|
|
37
|
+
export async function statsView(core, req) {
|
|
38
|
+
const windowDays = WINDOW_DAYS[req.window] ?? null;
|
|
39
|
+
const now = core.now();
|
|
40
|
+
const since = windowDays === null ? 0 : now - (windowDays + LOOK_BACK_DAYS) * DAY_MS;
|
|
41
|
+
const records = await core.lib.evals.readSince(since);
|
|
42
|
+
const coveredSigs = await coveredSignatures(core);
|
|
43
|
+
return geneOk(summarize(records, {
|
|
44
|
+
now,
|
|
45
|
+
windowDays,
|
|
46
|
+
...(coveredSigs === undefined ? {} : { coveredSigs }),
|
|
47
|
+
harmedByGene: await harmedCounts(core),
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/** Tokens the learning machinery spent in the last 24 hours, summed over every process. */
|
|
51
|
+
export function tokensToday(core) {
|
|
52
|
+
return core.lib.runLog.tokensSince(core.now() - DAY_MS);
|
|
53
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GeneDependencyView, GeneEvidenceEntryView, GeneRowView, GeneVersionRowView } from '@aragon-agent/tui/model/gene/port';
|
|
2
|
+
import type { GeneContent, GeneEvidence, GeneHead, GeneIndexRow, GeneScope, GeneVersion } from '@aragon-agent/tui/model/gene/types';
|
|
3
|
+
import type { ManagerCore } from './manager-context.js';
|
|
4
|
+
import type { HeadRead } from './store-port.js';
|
|
5
|
+
/**
|
|
6
|
+
* The row view of an index row. `head` is optional: the index row carries no `healthReason` and
|
|
7
|
+
* only a boolean for `needsHuman`, so a list fills those in from the head for the few rows that
|
|
8
|
+
* have them (`enrichRows`).
|
|
9
|
+
*/
|
|
10
|
+
export declare function rowViewOf(row: GeneIndexRow, head?: GeneHead): GeneRowView;
|
|
11
|
+
/** The row view of a head read straight from disk (a detail page, an archived gene). */
|
|
12
|
+
export declare function rowViewOfHead(read: HeadRead): GeneRowView;
|
|
13
|
+
/** Rows that have something a head knows and an index row does not get their head read. */
|
|
14
|
+
export declare function enrichRows(core: ManagerCore, rows: readonly GeneIndexRow[]): Promise<GeneRowView[]>;
|
|
15
|
+
/** Newest first, so the page opens on what is current. */
|
|
16
|
+
export declare function versionRows(versions: readonly GeneVersion[]): GeneVersionRowView[];
|
|
17
|
+
/** What a dependency edge points at, or the honest `missing`. */
|
|
18
|
+
export declare function dependencyView(dep: {
|
|
19
|
+
id: string;
|
|
20
|
+
kind: GeneDependencyView['kind'];
|
|
21
|
+
}, target: GeneHead | null): GeneDependencyView;
|
|
22
|
+
/** Size and trust of each evidence piece; the text stays behind `evidence()`. */
|
|
23
|
+
export declare function evidenceEntries(evidence: readonly GeneEvidence[]): GeneEvidenceEntryView[];
|
|
24
|
+
/** `project:demo-1a2b3c4d` or `user`: a scope as one short token for CLI and log-free output. */
|
|
25
|
+
export declare function scopeLabel(scope: GeneScope): string;
|
|
26
|
+
/** The content a version serves, or null. */
|
|
27
|
+
export declare function contentOf(version: GeneVersion | null): GeneContent | null;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning stored shapes into the path-free DTOs of the manager port (gene-bank spec 12.4, 16.6).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* ONE BUILDER PER SHAPE, SO TWO PAGES CANNOT DESCRIBE THE SAME GENE DIFFERENTLY. A row on the
|
|
7
|
+
* list, a row on the candidates page and a row in `/gene search` all come from `rowViewOf`; the
|
|
8
|
+
* tier-1 `line` is `geneBriefLine`, the one function the prompt block and the hints use too.
|
|
9
|
+
*
|
|
10
|
+
* NOTHING HERE CARRIES A PATH. A row names a scope by kind and key; a version names its author by
|
|
11
|
+
* kind. The evidence list says how big a piece is, never what is in it (that is `evidence()`).
|
|
12
|
+
*/
|
|
13
|
+
import { geneBriefLine } from '@aragon-agent/tui/model/gene/brief';
|
|
14
|
+
import { rowFromHead } from '@aragon-agent/tui/model/gene/row';
|
|
15
|
+
/**
|
|
16
|
+
* The row view of an index row. `head` is optional: the index row carries no `healthReason` and
|
|
17
|
+
* only a boolean for `needsHuman`, so a list fills those in from the head for the few rows that
|
|
18
|
+
* have them (`enrichRows`).
|
|
19
|
+
*/
|
|
20
|
+
export function rowViewOf(row, head) {
|
|
21
|
+
const view = {
|
|
22
|
+
id: row.id,
|
|
23
|
+
type: row.type,
|
|
24
|
+
scope: row.scope,
|
|
25
|
+
status: row.status,
|
|
26
|
+
health: row.health,
|
|
27
|
+
trust: row.trust,
|
|
28
|
+
class: row.class,
|
|
29
|
+
pinned: row.pinned,
|
|
30
|
+
version: row.v,
|
|
31
|
+
name: row.brief.name,
|
|
32
|
+
purpose: row.brief.purpose,
|
|
33
|
+
trigger: row.brief.trigger,
|
|
34
|
+
unconfirmed: row.unconfirmed === true,
|
|
35
|
+
probation: row.probation === true,
|
|
36
|
+
updatedAt: row.updatedAt,
|
|
37
|
+
line: geneBriefLine(row),
|
|
38
|
+
};
|
|
39
|
+
if (row.pinReason !== undefined)
|
|
40
|
+
view.pinReason = row.pinReason;
|
|
41
|
+
if (head?.healthReason !== undefined)
|
|
42
|
+
view.healthReason = head.healthReason;
|
|
43
|
+
if (head?.needsHuman !== undefined)
|
|
44
|
+
view.needsHuman = head.needsHuman.reason;
|
|
45
|
+
else if (row.needsHuman === true)
|
|
46
|
+
view.needsHuman = 'pending';
|
|
47
|
+
return view;
|
|
48
|
+
}
|
|
49
|
+
/** The row view of a head read straight from disk (a detail page, an archived gene). */
|
|
50
|
+
export function rowViewOfHead(read) {
|
|
51
|
+
return rowViewOf(rowFromHead(read.head, read), read.head);
|
|
52
|
+
}
|
|
53
|
+
/** Rows that have something a head knows and an index row does not get their head read. */
|
|
54
|
+
export async function enrichRows(core, rows) {
|
|
55
|
+
const views = [];
|
|
56
|
+
for (const row of rows) {
|
|
57
|
+
const needsHead = row.needsHuman === true || row.health !== 'ok';
|
|
58
|
+
const read = needsHead ? await core.lib.store.readHead(row.scope, row.id) : null;
|
|
59
|
+
views.push(rowViewOf(row, read?.head));
|
|
60
|
+
}
|
|
61
|
+
return views;
|
|
62
|
+
}
|
|
63
|
+
/** `Alice` for a label, else the author kind: who wrote this version, in one word. */
|
|
64
|
+
function authorOf(version) {
|
|
65
|
+
const label = version.author.label;
|
|
66
|
+
return label !== undefined && label.length > 0 ? label : version.author.kind;
|
|
67
|
+
}
|
|
68
|
+
/** Newest first, so the page opens on what is current. */
|
|
69
|
+
export function versionRows(versions) {
|
|
70
|
+
return [...versions]
|
|
71
|
+
.sort((a, b) => b.n - a.n)
|
|
72
|
+
.map((version) => {
|
|
73
|
+
const row = {
|
|
74
|
+
n: version.n,
|
|
75
|
+
state: version.state,
|
|
76
|
+
createdAt: version.createdAt,
|
|
77
|
+
author: authorOf(version),
|
|
78
|
+
reason: version.reason,
|
|
79
|
+
validationOk: version.validation === undefined ? null : version.validation.ok,
|
|
80
|
+
};
|
|
81
|
+
if (version.proposalId !== undefined)
|
|
82
|
+
row.proposalId = version.proposalId;
|
|
83
|
+
return row;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** What a dependency edge points at, or the honest `missing`. */
|
|
87
|
+
export function dependencyView(dep, target) {
|
|
88
|
+
if (target === null) {
|
|
89
|
+
return {
|
|
90
|
+
id: dep.id,
|
|
91
|
+
name: dep.id,
|
|
92
|
+
type: 'knowledge',
|
|
93
|
+
kind: dep.kind,
|
|
94
|
+
health: 'missing',
|
|
95
|
+
status: 'missing',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
id: dep.id,
|
|
100
|
+
name: target.brief.name,
|
|
101
|
+
type: target.type,
|
|
102
|
+
kind: dep.kind,
|
|
103
|
+
health: target.health,
|
|
104
|
+
status: target.status,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Size and trust of each evidence piece; the text stays behind `evidence()`. */
|
|
108
|
+
export function evidenceEntries(evidence) {
|
|
109
|
+
return evidence.map((piece) => ({
|
|
110
|
+
ref: piece.ref,
|
|
111
|
+
kind: piece.kind,
|
|
112
|
+
trust: piece.trust,
|
|
113
|
+
bytes: Buffer.byteLength(piece.text),
|
|
114
|
+
redacted: piece.redacted,
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
/** `project:demo-1a2b3c4d` or `user`: a scope as one short token for CLI and log-free output. */
|
|
118
|
+
export function scopeLabel(scope) {
|
|
119
|
+
return scope.key === undefined ? scope.kind : `${scope.kind}:${scope.key}`;
|
|
120
|
+
}
|
|
121
|
+
/** The content a version serves, or null. */
|
|
122
|
+
export function contentOf(version) {
|
|
123
|
+
return version === null ? null : version.content;
|
|
124
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { GeneManagerPort } from '@aragon-agent/tui/model/gene/port';
|
|
2
|
+
import type { GeneResult, GeneScope } from '@aragon-agent/tui/model/gene/types';
|
|
3
|
+
import { type ImportOutcome, type ImportPreview, type ImportSource } from './import-plan.js';
|
|
4
|
+
import { type FsckReport } from './fsck.js';
|
|
5
|
+
import { type GeneManagerOptions } from './manager-context.js';
|
|
6
|
+
import { type GeneGcReport } from './manager-gc.js';
|
|
7
|
+
import { type DiagBundle, type DiagOptions, type DiagWrite } from './diag.js';
|
|
8
|
+
import { type ProjectScopeAudit } from './orphan-scopes.js';
|
|
9
|
+
import { type ProjectLearningChange, type ProjectLearningState } from './project-learning.js';
|
|
10
|
+
import { type GenePack, type ImportReport } from './transfer.js';
|
|
11
|
+
export type { GeneManagerOptions } from './manager-context.js';
|
|
12
|
+
export interface DiagWriteRequest {
|
|
13
|
+
file?: string;
|
|
14
|
+
overwrite?: boolean;
|
|
15
|
+
options?: DiagOptions;
|
|
16
|
+
}
|
|
17
|
+
export interface GeneManagerExtras {
|
|
18
|
+
/** Tokens spent by learning, curation and validation in the last 24 hours (all processes). */
|
|
19
|
+
tokensToday(): Promise<number>;
|
|
20
|
+
/** Reclaim space now: archive over-cap genes, age out the trash, queue, run log and eval rows. */
|
|
21
|
+
gc(): Promise<GeneResult<GeneGcReport>>;
|
|
22
|
+
/** The pack of published genes in `scopes` (default: the user scope and this project). */
|
|
23
|
+
buildPack(scopes?: GeneScope[]): Promise<GeneResult<GenePack>>;
|
|
24
|
+
/** Import a decoded pack as candidates (all or nothing). */
|
|
25
|
+
importPack(pack: GenePack): Promise<GeneResult<ImportReport>>;
|
|
26
|
+
/** What a cold-start import of memory notes or skills would queue. Writes nothing. */
|
|
27
|
+
previewImport(source: ImportSource, limit?: number): Promise<GeneResult<ImportPreview>>;
|
|
28
|
+
/** Queue what a preview chose (single use, ten minutes). */
|
|
29
|
+
commitImport(previewId: string): Promise<GeneResult<ImportOutcome>>;
|
|
30
|
+
/** Check every scope against its head files; with `repair`, fix what can be fixed. */
|
|
31
|
+
fsck(options: {
|
|
32
|
+
repair: boolean;
|
|
33
|
+
}): Promise<FsckReport>;
|
|
34
|
+
/** A typed reference (an id, or a name unique among the visible genes) to an id. */
|
|
35
|
+
resolveRef(ref: string): Promise<GeneResult<string>>;
|
|
36
|
+
/** The scopes this session sees, for display. */
|
|
37
|
+
scopes(): GeneScope[];
|
|
38
|
+
/** Project scopes not found at their recorded path (read only, I3-6). */
|
|
39
|
+
projectScopeAudit(): Promise<ProjectScopeAudit>;
|
|
40
|
+
/** The diagnostic bundle: numbers, enums and eight-hex ids only (I3-7). Never throws. */
|
|
41
|
+
diagnostics(options?: DiagOptions): Promise<DiagBundle>;
|
|
42
|
+
/**
|
|
43
|
+
* Write the diagnostic bundle to `file` (absolute), or to `<genes>/diag/gene-diag.json` when
|
|
44
|
+
* none is named. A named file is never overwritten unless `overwrite`. Never throws.
|
|
45
|
+
*/
|
|
46
|
+
writeDiagnostics(request: DiagWriteRequest): Promise<DiagWrite>;
|
|
47
|
+
/** Is learning on for this session's project, and which layer says so? null = no project. */
|
|
48
|
+
projectLearning(): Promise<GeneResult<ProjectLearningState | null>>;
|
|
49
|
+
/** Switch learning on or off for this session's project (the user-private layer only). */
|
|
50
|
+
setProjectLearning(learn: boolean): Promise<GeneResult<ProjectLearningChange>>;
|
|
51
|
+
/** Drop the in-memory catalogs. The library handle is process-wide and stays. */
|
|
52
|
+
dispose(): void;
|
|
53
|
+
}
|
|
54
|
+
export type GeneManager = GeneManagerPort & GeneManagerExtras;
|
|
55
|
+
/** Build the manager for one session. Never throws. */
|
|
56
|
+
export declare function createGeneManager(options: GeneManagerOptions): GeneManager;
|