@aragon-agent/cli 0.6.55 → 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 -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 +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/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,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The publish gate (gene-bank spec 10.7.4; I-6, I-10, I-12, I-17, I-18, I-25).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* `evaluatePublishGate` is the LAST code that runs before a candidate becomes current. It is pure
|
|
7
|
+
* data in, a verdict out: it never commits, so the same function guards the `gene_publish` tool,
|
|
8
|
+
* the merge tool and the resume-from-validation path, and a test can exercise every refusal
|
|
9
|
+
* without a library. Whoever commits must have an `ok: true` verdict in hand.
|
|
10
|
+
*
|
|
11
|
+
* THE SEVEN CONDITIONS, IN THE ORDER THEY ARE CHEAPEST TO REFUSE:
|
|
12
|
+
* 1 a validation exists for THIS exact content (its hash), and every required check passed
|
|
13
|
+
* 2 `autoLearn` is still on - the stricter of the live and the persisted config, read NOW,
|
|
14
|
+
* not when the task started (checkpoint three of three)
|
|
15
|
+
* 3 the basis still matches: the candidate is the head's newest version, nothing newer exists,
|
|
16
|
+
* and no person edited the gene after the proposal was made
|
|
17
|
+
* 4 trust is not downgraded: a person-owned gene is never replaced by an agent version without
|
|
18
|
+
* a person deciding (`needs_human: conflict_with_human`)
|
|
19
|
+
* 5 the tombstones are re-checked: a gene forgotten while the task ran is not published
|
|
20
|
+
* 6 a tool gene needs the probe policy: the curator probed a read-only command itself, or a
|
|
21
|
+
* person's approval for exactly this content is recorded (I-25)
|
|
22
|
+
* 7 capacity is enforced by the commit itself (`evictToFit` makes room first and refuses with
|
|
23
|
+
* `GENE_CAP_PINNED_FULL` when nothing may go); the gate maps that refusal, it does not guess
|
|
24
|
+
*
|
|
25
|
+
* A REFUSAL SAYS WHAT TO DO WITH THE TASK, not just that it failed: `abandon` ends it as
|
|
26
|
+
* superseded, `needsHuman` parks it for a person, neither means the model may fix and retry.
|
|
27
|
+
*/
|
|
28
|
+
import type { GeneHead, GeneNeedsHuman, GeneValidation, GeneVersion } from '@aragon-agent/tui/model/gene/types';
|
|
29
|
+
import type { ProposalSource, SwitchGuard } from './switches.js';
|
|
30
|
+
import type { AbandonReason, StoredValidation } from './task-context.js';
|
|
31
|
+
import type { ForgottenQuery } from '../tombstones.js';
|
|
32
|
+
export interface GateDeps {
|
|
33
|
+
switches: Pick<SwitchGuard, 'check'> & Partial<Pick<SwitchGuard, 'checkFor'>>;
|
|
34
|
+
isForgotten(query: ForgottenQuery): Promise<unknown>;
|
|
35
|
+
}
|
|
36
|
+
export interface GateInput {
|
|
37
|
+
head: GeneHead;
|
|
38
|
+
/** The version being published (a candidate), or the survivor content of a merge. */
|
|
39
|
+
version: Pick<GeneVersion, 'n' | 'contentHash' | 'content'>;
|
|
40
|
+
stored: StoredValidation | undefined;
|
|
41
|
+
/** What the caller believes the head's latest version is. */
|
|
42
|
+
expectedVersion: number;
|
|
43
|
+
/** `candidate`: the version is `head.candidateVersion`. `direct`: a merge writes a new current. */
|
|
44
|
+
mode: 'candidate' | 'direct';
|
|
45
|
+
/** The proposal's creation time: a person's edit after it wins. */
|
|
46
|
+
proposalCreatedAt: number;
|
|
47
|
+
/** Where the proposal came from, for the per-project learning switch (I3-5). */
|
|
48
|
+
originProjectKey?: string | null;
|
|
49
|
+
originSource?: ProposalSource;
|
|
50
|
+
}
|
|
51
|
+
export type GateVerdict = {
|
|
52
|
+
ok: true;
|
|
53
|
+
validation: GeneValidation;
|
|
54
|
+
} | {
|
|
55
|
+
ok: false;
|
|
56
|
+
code: string;
|
|
57
|
+
message: string;
|
|
58
|
+
abandon?: AbandonReason;
|
|
59
|
+
needsHuman?: GeneNeedsHuman['reason'];
|
|
60
|
+
/** The basis moved: counts toward the "re-read once" allowance. */
|
|
61
|
+
stale?: boolean;
|
|
62
|
+
};
|
|
63
|
+
/** Decide whether this write may go ahead. Never throws; a throwing dependency refuses the publish. */
|
|
64
|
+
export declare function evaluatePublishGate(deps: GateDeps, input: GateInput): Promise<GateVerdict>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { canPublishTool } from './probe.js';
|
|
2
|
+
function refuse(code, message, extra = {}) {
|
|
3
|
+
return { ok: false, code, message, ...extra };
|
|
4
|
+
}
|
|
5
|
+
function toolPayloadOf(version) {
|
|
6
|
+
const payload = version.content.payload;
|
|
7
|
+
return payload.exec !== undefined && typeof payload.risk === 'string' ? payload : null;
|
|
8
|
+
}
|
|
9
|
+
function validationRefusal(input) {
|
|
10
|
+
const stored = input.stored;
|
|
11
|
+
if (stored === undefined || stored.contentHash !== input.version.contentHash) {
|
|
12
|
+
return refuse('GENE_VALIDATION_REQUIRED', 'Run gene_validate on this exact version first.');
|
|
13
|
+
}
|
|
14
|
+
if (stored.outcome.verdict !== 'pass' || !stored.outcome.validation.ok) {
|
|
15
|
+
return refuse('GENE_VALIDATION_FAILED', 'The last validation did not pass; fix the draft or finish rejected.');
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function basisRefusal(input) {
|
|
20
|
+
const { head, version, expectedVersion } = input;
|
|
21
|
+
if (head.humanTouchedAt !== undefined && head.humanTouchedAt > input.proposalCreatedAt) {
|
|
22
|
+
return refuse('GENE_STALE_BASIS', 'A person edited this gene after the proposal was made.', {
|
|
23
|
+
abandon: 'human_edit',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const moved = expectedVersion !== head.latestVersion;
|
|
27
|
+
const notNewest = input.mode === 'candidate' && (head.candidateVersion !== version.n || head.latestVersion !== version.n);
|
|
28
|
+
if (moved || notNewest) {
|
|
29
|
+
return refuse('GENE_STALE_BASIS', 'The gene changed since it was read; re-read it once.', { stale: true });
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function toolRefusal(input, stored) {
|
|
34
|
+
const payload = toolPayloadOf(input.version);
|
|
35
|
+
if (payload === null)
|
|
36
|
+
return null;
|
|
37
|
+
const risk = stored.outcome.derived?.risk ?? payload.risk;
|
|
38
|
+
if (canPublishTool(stored.outcome.validation, risk, stored.outcome.autoProbed, input.version.contentHash)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const reason = risk === 'high' ? 'high_risk_tool' : 'probe_approval';
|
|
42
|
+
return refuse('GENE_PROBE_NEEDS_APPROVAL', 'A person must approve a live probe of this tool first.', {
|
|
43
|
+
needsHuman: reason,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** The refusals that need nothing but the inputs: basis, oversight, trust. */
|
|
47
|
+
function localRefusal(input) {
|
|
48
|
+
const basis = basisRefusal(input);
|
|
49
|
+
if (basis !== null)
|
|
50
|
+
return basis;
|
|
51
|
+
if (input.head.class === 'oversight') {
|
|
52
|
+
return refuse('GENE_OVERSIGHT_HUMAN_ONLY', 'Only a person may change an oversight gene.');
|
|
53
|
+
}
|
|
54
|
+
if (input.head.trust === 'human') {
|
|
55
|
+
return refuse('GENE_CONFLICT_WITH_HUMAN', 'A person-owned gene needs a person to decide.', {
|
|
56
|
+
needsHuman: 'conflict_with_human',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/** The per-project switch, re-read at publish time: the switch may have flipped while the task ran. */
|
|
62
|
+
async function projectRefusal(deps, input) {
|
|
63
|
+
if (input.originSource === undefined || deps.switches.checkFor === undefined)
|
|
64
|
+
return null;
|
|
65
|
+
const verdict = await deps.switches.checkFor({
|
|
66
|
+
projectKey: input.originProjectKey ?? null,
|
|
67
|
+
source: input.originSource,
|
|
68
|
+
});
|
|
69
|
+
if (verdict.on)
|
|
70
|
+
return null;
|
|
71
|
+
return refuse('GENE_LEARNING_OFF', 'Learning is switched off for the project this came from.', {
|
|
72
|
+
abandon: 'project_excluded',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async function isForgottenNow(deps, head) {
|
|
76
|
+
const hit = await deps.isForgotten({
|
|
77
|
+
fingerprint: head.fingerprint,
|
|
78
|
+
...(head.brief.vec === undefined ? {} : { vec: head.brief.vec }),
|
|
79
|
+
scope: head.scope,
|
|
80
|
+
type: head.type,
|
|
81
|
+
});
|
|
82
|
+
return hit !== null && hit !== undefined;
|
|
83
|
+
}
|
|
84
|
+
/** Decide whether this write may go ahead. Never throws; a throwing dependency refuses the publish. */
|
|
85
|
+
export async function evaluatePublishGate(deps, input) {
|
|
86
|
+
try {
|
|
87
|
+
const invalid = validationRefusal(input);
|
|
88
|
+
if (invalid !== null)
|
|
89
|
+
return invalid;
|
|
90
|
+
const switches = await deps.switches.check();
|
|
91
|
+
if (!switches.on) {
|
|
92
|
+
const abandon = switches.reason === 'learning_off' ? 'learning_off' : switches.reason;
|
|
93
|
+
return refuse('GENE_LEARNING_OFF', 'Automatic learning is switched off.', { abandon });
|
|
94
|
+
}
|
|
95
|
+
const project = await projectRefusal(deps, input);
|
|
96
|
+
if (project !== null)
|
|
97
|
+
return project;
|
|
98
|
+
const local = localRefusal(input);
|
|
99
|
+
if (local !== null)
|
|
100
|
+
return local;
|
|
101
|
+
if (await isForgottenNow(deps, input.head)) {
|
|
102
|
+
return refuse('GENE_FORGOTTEN', 'This gene was forgotten on purpose.', { abandon: 'forgotten' });
|
|
103
|
+
}
|
|
104
|
+
const stored = input.stored;
|
|
105
|
+
const tool = toolRefusal(input, stored);
|
|
106
|
+
if (tool !== null)
|
|
107
|
+
return tool;
|
|
108
|
+
return { ok: true, validation: stored.outcome.validation };
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return refuse('GENE_UNAVAILABLE', 'The publish gate could not complete; nothing was published.');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `recheck` of a published gene (gene-bank spec 10.9; RV-1; I-7, I-25).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* WHAT IS RE-RUN. Knowledge: K2 (the evidence still resolves and still says what the gene says).
|
|
7
|
+
* Tool: T1-T6. Skill: S2 (every dependency still exists, is published, visible, healthy, and
|
|
8
|
+
* interface-compatible, with no cycle). All of it is deterministic code: a recheck costs no tokens.
|
|
9
|
+
*
|
|
10
|
+
* THE OUTCOME IS A HEALTH MARK, NOTHING MORE. `ok` when everything passes; `recheck` on the first
|
|
11
|
+
* failure; `broken` on the second consecutive failure, or at once when a tool's example fails
|
|
12
|
+
* live. A PINNED gene gets the same mark and `markOnly: true`: a recheck never revokes or archives
|
|
13
|
+
* anything, and for a pinned gene it never even suggests it (I-7, G-07) - a person decides.
|
|
14
|
+
*
|
|
15
|
+
* THE PROBE POLICY APPLIES TO RECHECKS TOO (RV-1). The background run executes a tool only when
|
|
16
|
+
* `probe.ts` says it is a read-only whitelisted command. For every other tool the live part is
|
|
17
|
+
* SKIPPED and recorded as `live_check: skipped_needs_approval`; that is not a failure. When the
|
|
18
|
+
* user presses "recheck now" the manager passes an `approval` for this exact content, and then the
|
|
19
|
+
* approved probe runs instead.
|
|
20
|
+
*
|
|
21
|
+
* "CONSECUTIVE" IS REMEMBERED IN `healthReason`. The head has no failure counter, so a failed
|
|
22
|
+
* recheck writes `recheck_failed:<code>` and the next run reads it back. A `recheck` mark that came
|
|
23
|
+
* from a dependency change carries a different reason and does NOT count as a prior failure.
|
|
24
|
+
*/
|
|
25
|
+
import type { GeneEvidence, GeneHead, GeneHealth, GeneValidationCheck, GeneVersion } from '@aragon-agent/tui/model/gene/types';
|
|
26
|
+
import type { ProbeApproval, ProbeDeps } from './probe.js';
|
|
27
|
+
import type { ValidatorPorts } from './validate/ports.js';
|
|
28
|
+
export interface RecheckInput {
|
|
29
|
+
ports: ValidatorPorts;
|
|
30
|
+
head: GeneHead;
|
|
31
|
+
/** The SERVED (published) version. */
|
|
32
|
+
version: GeneVersion;
|
|
33
|
+
/** Evidence already loaded for the gene, when the caller has it; refs are read otherwise. */
|
|
34
|
+
evidence?: readonly GeneEvidence[];
|
|
35
|
+
/** Consecutive failures before this run. Derived from `head.healthReason` when absent. */
|
|
36
|
+
priorFailures?: number;
|
|
37
|
+
scriptText?: string;
|
|
38
|
+
/** A person's approval for THIS content ("recheck now"): lets a non-whitelisted tool run. */
|
|
39
|
+
approval?: ProbeApproval;
|
|
40
|
+
probeDeps?: ProbeDeps;
|
|
41
|
+
}
|
|
42
|
+
export interface RecheckOutcome {
|
|
43
|
+
health: GeneHealth;
|
|
44
|
+
/** `recheck_failed:<codes>` / `broken:<codes>`; undefined when healthy. */
|
|
45
|
+
healthReason?: string;
|
|
46
|
+
checks: GeneValidationCheck[];
|
|
47
|
+
/** The gene is pinned: apply the mark and nothing else. */
|
|
48
|
+
markOnly: boolean;
|
|
49
|
+
/** Only for a non-pinned gene whose dependency's tool interface moved. */
|
|
50
|
+
suggest?: 'revise';
|
|
51
|
+
/** Consecutive failures including this run. */
|
|
52
|
+
failures: number;
|
|
53
|
+
}
|
|
54
|
+
/** Re-run the deterministic checks of a published gene. Never throws; a thrown port is a failure. */
|
|
55
|
+
export declare function recheckGene(input: RecheckInput): Promise<RecheckOutcome>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { runApprovedProbe } from './probe.js';
|
|
2
|
+
import { NEEDS_HUMAN_CODES, failCheck, isSkippedCheck, okCheck, runStaticChecks } from './validate/common.js';
|
|
3
|
+
import { checkSource } from './validate/knowledge.js';
|
|
4
|
+
import { checkDependencies } from './validate/skill.js';
|
|
5
|
+
import { validateTool } from './validate/tool.js';
|
|
6
|
+
const FAILED_PREFIX = 'recheck_failed:';
|
|
7
|
+
function priorFailuresOf(head, given) {
|
|
8
|
+
if (given !== undefined)
|
|
9
|
+
return Math.max(0, given);
|
|
10
|
+
if (head.health === 'broken')
|
|
11
|
+
return 2;
|
|
12
|
+
return head.health === 'recheck' && head.healthReason?.startsWith(FAILED_PREFIX) ? 1 : 0;
|
|
13
|
+
}
|
|
14
|
+
/** The rule checks of a tool: validateTool's first check is the shared static K1 and its last the trust gate. */
|
|
15
|
+
function toolRuleChecks(checks) {
|
|
16
|
+
return checks.slice(1).filter((c) => c.code !== 'K6' && c.code !== 'KNOWLEDGE_UNTRUSTED_ONLY');
|
|
17
|
+
}
|
|
18
|
+
/** Turn "a person has not approved a live probe" into a recorded skip, never a failure. */
|
|
19
|
+
function skipUnapprovedProbe(checks, at) {
|
|
20
|
+
const out = checks.filter((c) => c.code !== 'GENE_PROBE_NEEDS_APPROVAL' && c.code !== 'SKIPPED_T6');
|
|
21
|
+
const skipped = out.length !== checks.length;
|
|
22
|
+
return skipped ? [...out, okCheck('live_check', at, 'skipped_needs_approval')] : out;
|
|
23
|
+
}
|
|
24
|
+
async function recheckTool(input, at) {
|
|
25
|
+
const ctx = {
|
|
26
|
+
ports: input.ports,
|
|
27
|
+
type: 'tool',
|
|
28
|
+
scope: input.head.scope,
|
|
29
|
+
content: input.version.content,
|
|
30
|
+
evidence: [],
|
|
31
|
+
geneId: input.head.id,
|
|
32
|
+
...(input.scriptText === undefined ? {} : { scriptText: input.scriptText }),
|
|
33
|
+
...(input.probeDeps === undefined ? {} : { probeDeps: input.probeDeps }),
|
|
34
|
+
};
|
|
35
|
+
const report = runStaticChecks({ type: 'tool', content: ctx.content, scope: ctx.scope });
|
|
36
|
+
const result = await validateTool(ctx, report);
|
|
37
|
+
const rules = skipUnapprovedProbe(toolRuleChecks(result.checks), at);
|
|
38
|
+
if (input.approval === undefined || !rules.some((c) => c.code === 'live_check'))
|
|
39
|
+
return rules;
|
|
40
|
+
const approved = await runApprovedProbe(input.head, input.version, input.approval, {
|
|
41
|
+
...(input.probeDeps ?? {}),
|
|
42
|
+
...(input.scriptText === undefined ? {} : { scriptText: input.scriptText }),
|
|
43
|
+
});
|
|
44
|
+
if (!approved.ok)
|
|
45
|
+
return rules;
|
|
46
|
+
return [...rules.filter((c) => c.code !== 'live_check'), ...approved.validation.checks];
|
|
47
|
+
}
|
|
48
|
+
async function runRules(input, at) {
|
|
49
|
+
const { head, version, ports } = input;
|
|
50
|
+
if (head.type === 'knowledge') {
|
|
51
|
+
return checkSource({
|
|
52
|
+
ports,
|
|
53
|
+
scope: head.scope,
|
|
54
|
+
geneId: head.id,
|
|
55
|
+
content: version.content,
|
|
56
|
+
evidence: input.evidence ?? [],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (head.type === 'skill') {
|
|
60
|
+
return checkDependencies({ ports, scope: head.scope, geneId: head.id, content: version.content });
|
|
61
|
+
}
|
|
62
|
+
return recheckTool(input, at);
|
|
63
|
+
}
|
|
64
|
+
/** A failure that is a real defect, as opposed to "a person must decide". */
|
|
65
|
+
function realFailures(checks) {
|
|
66
|
+
return checks.filter((c) => !c.ok && !isSkippedCheck(c) && !NEEDS_HUMAN_CODES.has(c.code));
|
|
67
|
+
}
|
|
68
|
+
function decideHealth(failures, prior) {
|
|
69
|
+
if (failures.length === 0)
|
|
70
|
+
return { health: 'ok', count: 0 };
|
|
71
|
+
const liveToolFailure = failures.some((c) => c.code === 'TOOL_EXAMPLE_FAILED' && c.detail?.startsWith('T4'));
|
|
72
|
+
const count = prior + 1;
|
|
73
|
+
return { health: liveToolFailure || count >= 2 ? 'broken' : 'recheck', count };
|
|
74
|
+
}
|
|
75
|
+
function suggestionFor(failures, pinned) {
|
|
76
|
+
if (pinned)
|
|
77
|
+
return undefined;
|
|
78
|
+
return failures.some((c) => c.detail?.includes('different tool interface')) ? 'revise' : undefined;
|
|
79
|
+
}
|
|
80
|
+
/** Re-run the deterministic checks of a published gene. Never throws; a thrown port is a failure. */
|
|
81
|
+
export async function recheckGene(input) {
|
|
82
|
+
const at = input.ports.now();
|
|
83
|
+
const prior = priorFailuresOf(input.head, input.priorFailures);
|
|
84
|
+
let checks;
|
|
85
|
+
try {
|
|
86
|
+
checks = await runRules(input, at);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
checks = [failCheck('VALIDATOR_ERROR', at, 'a recheck rule could not complete')];
|
|
90
|
+
}
|
|
91
|
+
const failures = realFailures(checks);
|
|
92
|
+
const { health, count } = decideHealth(failures, prior);
|
|
93
|
+
const codes = [...new Set(failures.map((c) => c.code))].slice(0, 2).join(',');
|
|
94
|
+
const suggest = suggestionFor(failures, input.head.pinned);
|
|
95
|
+
return {
|
|
96
|
+
health,
|
|
97
|
+
...(health === 'ok' ? {} : { healthReason: health === 'broken' ? `broken:${codes}` : `${FAILED_PREFIX}${codes}` }),
|
|
98
|
+
checks,
|
|
99
|
+
markOnly: input.head.pinned,
|
|
100
|
+
failures: count,
|
|
101
|
+
...(suggest === undefined ? {} : { suggest }),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the curator writes its processing record (gene-bank spec 10.3, 12.8, I-19, I-23).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`.
|
|
5
|
+
*
|
|
6
|
+
* ONE DOOR TO THE RUN LOG. Every record the curator writes goes through `CuratorEvents.emit`, which
|
|
7
|
+
* takes ids, an enum and a short machine `detail`, and nothing else: there is no parameter that
|
|
8
|
+
* could carry a gene body, an evidence quote or a model reply (I-19). `GeneRunLog.append`
|
|
9
|
+
* validates and scrubs again; this layer is the first of the two fences.
|
|
10
|
+
*
|
|
11
|
+
* THE HUB READS THESE RECORDS. `claimed` / `distilling` / `deduping` / `validating` start work,
|
|
12
|
+
* `published` and its siblings end it, and `paused` carries its reason as the FIRST WORD of
|
|
13
|
+
* `detail` (the activity hub folds records into the chip and reads exactly that). `name=<slug>`
|
|
14
|
+
* and `stage=publishing` are the two optional conventions the hub documents.
|
|
15
|
+
*
|
|
16
|
+
* THE VERSION SERVICE ALSO LOGS. A commit records `published`, `merged`, `archived`, `revoked`,
|
|
17
|
+
* `rolled_back`, `rejected` and `needs_human` itself, so the curator emits those events only for
|
|
18
|
+
* decisions that did NOT go through a commit (a deterministic refusal, a suggestion). Writing
|
|
19
|
+
* them again for committed work would show every outcome twice in the processing record.
|
|
20
|
+
*
|
|
21
|
+
* TOKENS RIDE ON THE NEXT STAGE RECORD. The daily budget is summed from `tokens` fields. Spend is
|
|
22
|
+
* accumulated in a `TokenLedger` and attached to the next record the curator writes (a task's
|
|
23
|
+
* first record carries the previous task's trailing spend), and `drain` writes what is left when
|
|
24
|
+
* the curator stops. No record is written just to carry tokens, because every event type means
|
|
25
|
+
* something to the hub.
|
|
26
|
+
*/
|
|
27
|
+
import type { GeneRunEvent, GeneScope, GeneTokenComponent, GeneType } from '@aragon-agent/tui/model/gene/types';
|
|
28
|
+
import type { GeneRunLog, RunLogEntry } from '../runlog.js';
|
|
29
|
+
export declare class TokenLedger {
|
|
30
|
+
private readonly pending;
|
|
31
|
+
add(component: GeneTokenComponent, usage: {
|
|
32
|
+
in: number;
|
|
33
|
+
out: number;
|
|
34
|
+
}): void;
|
|
35
|
+
/** Remove and return the spend of one component, or undefined when there is none. */
|
|
36
|
+
take(component: GeneTokenComponent): RunLogEntry['tokens'] | undefined;
|
|
37
|
+
/** The next spend to write: the curator's first, then the validators'. */
|
|
38
|
+
takeAny(): RunLogEntry['tokens'] | undefined;
|
|
39
|
+
has(): boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface EventFields {
|
|
42
|
+
proposalId?: string;
|
|
43
|
+
geneId?: string;
|
|
44
|
+
version?: number;
|
|
45
|
+
scope?: GeneScope;
|
|
46
|
+
type?: GeneType;
|
|
47
|
+
/** Stable machine tokens only. */
|
|
48
|
+
detail?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface EventDeps {
|
|
51
|
+
log: Pick<GeneRunLog, 'append'>;
|
|
52
|
+
ledger: TokenLedger;
|
|
53
|
+
/** The curator holds the lease right now; stamped on every record. */
|
|
54
|
+
holdsLease(): boolean;
|
|
55
|
+
}
|
|
56
|
+
export declare class CuratorEvents {
|
|
57
|
+
private readonly deps;
|
|
58
|
+
constructor(deps: EventDeps);
|
|
59
|
+
/** Append one record, carrying whatever curator spend is waiting. Never throws. */
|
|
60
|
+
emit(ev: GeneRunEvent, fields?: EventFields): Promise<void>;
|
|
61
|
+
/** Write whatever spend is still waiting (a stopping curator), one record per component. */
|
|
62
|
+
drain(fields?: EventFields): Promise<void>;
|
|
63
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export class TokenLedger {
|
|
2
|
+
pending = new Map();
|
|
3
|
+
add(component, usage) {
|
|
4
|
+
const total = this.pending.get(component) ?? { in: 0, out: 0 };
|
|
5
|
+
total.in += Math.max(0, Math.trunc(usage.in) || 0);
|
|
6
|
+
total.out += Math.max(0, Math.trunc(usage.out) || 0);
|
|
7
|
+
this.pending.set(component, total);
|
|
8
|
+
}
|
|
9
|
+
/** Remove and return the spend of one component, or undefined when there is none. */
|
|
10
|
+
take(component) {
|
|
11
|
+
const total = this.pending.get(component);
|
|
12
|
+
this.pending.delete(component);
|
|
13
|
+
if (total === undefined || total.in + total.out === 0)
|
|
14
|
+
return undefined;
|
|
15
|
+
return { in: total.in, out: total.out, component };
|
|
16
|
+
}
|
|
17
|
+
/** The next spend to write: the curator's first, then the validators'. */
|
|
18
|
+
takeAny() {
|
|
19
|
+
return this.take('curator') ?? this.take('validation');
|
|
20
|
+
}
|
|
21
|
+
has() {
|
|
22
|
+
for (const total of this.pending.values())
|
|
23
|
+
if (total.in + total.out > 0)
|
|
24
|
+
return true;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class CuratorEvents {
|
|
29
|
+
deps;
|
|
30
|
+
constructor(deps) {
|
|
31
|
+
this.deps = deps;
|
|
32
|
+
}
|
|
33
|
+
/** Append one record, carrying whatever curator spend is waiting. Never throws. */
|
|
34
|
+
async emit(ev, fields = {}) {
|
|
35
|
+
const tokens = this.deps.ledger.takeAny();
|
|
36
|
+
const entry = {
|
|
37
|
+
ev,
|
|
38
|
+
...fields,
|
|
39
|
+
...(tokens === undefined ? {} : { tokens }),
|
|
40
|
+
...(this.deps.holdsLease() ? { lease: true } : {}),
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
await this.deps.log.append(entry);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// The record is best effort (I-24); the work it describes has already happened.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Write whatever spend is still waiting (a stopping curator), one record per component. */
|
|
50
|
+
async drain(fields = {}) {
|
|
51
|
+
for (let guard = 0; guard < 4 && this.deps.ledger.has(); guard += 1) {
|
|
52
|
+
await this.emit('lease_lost', { ...fields, detail: 'released' });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GeneIndexRow } from '@aragon-agent/tui/model/gene/types';
|
|
2
|
+
export interface PreparedVec {
|
|
3
|
+
row: GeneIndexRow;
|
|
4
|
+
vec: Int8Array;
|
|
5
|
+
/** 1 / ||vec||, or 0 for a zero vector. */
|
|
6
|
+
inv: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function prepareVectors(rows: readonly GeneIndexRow[]): PreparedVec[];
|
|
9
|
+
export declare function cosinePrepared(a: PreparedVec, b: PreparedVec): number;
|
|
10
|
+
/** Rows of one scope and type: the only peers a duplicate or a uniqueness score may use. */
|
|
11
|
+
export declare function peersOf(rows: readonly GeneIndexRow[], like: Pick<GeneIndexRow, 'scope' | 'type'>): GeneIndexRow[];
|
|
12
|
+
/** `1 - maxCosine` against `peers` (other than itself). 1 when there is nothing to compare. */
|
|
13
|
+
export declare function uniquenessAmong(target: PreparedVec, peers: readonly PreparedVec[]): number;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector helpers shared by the lifecycle and the maintenance planner
|
|
3
|
+
* (gene-bank spec 7.4.2 `uniqueness`, 10.10 duplicate detection).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`. PURE.
|
|
6
|
+
*
|
|
7
|
+
* `cosineInt8` recomputes both norms on every call; a maintenance pass compares thousands of
|
|
8
|
+
* pairs, so vectors are decoded once and their inverse norms cached here. The result is the same
|
|
9
|
+
* cosine, three times cheaper. Rows without a usable vector are simply absent from the prepared
|
|
10
|
+
* set: "no vector" means "nothing is known to be similar to it", never "identical".
|
|
11
|
+
*/
|
|
12
|
+
import { decodeVec, normInt8 } from '@aragon-agent/tui/model/gene/hashvec';
|
|
13
|
+
import { sameScope } from '@aragon-agent/tui/model/gene/ids';
|
|
14
|
+
export function prepareVectors(rows) {
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const row of rows) {
|
|
17
|
+
const vec = row.brief.vec === undefined ? null : decodeVec(row.brief.vec);
|
|
18
|
+
if (vec === null)
|
|
19
|
+
continue;
|
|
20
|
+
const norm = normInt8(vec);
|
|
21
|
+
out.push({ row, vec, inv: norm === 0 ? 0 : 1 / norm });
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
export function cosinePrepared(a, b) {
|
|
26
|
+
if (a.inv === 0 || b.inv === 0 || a.vec.length !== b.vec.length)
|
|
27
|
+
return 0;
|
|
28
|
+
let dot = 0;
|
|
29
|
+
for (let i = 0; i < a.vec.length; i += 1)
|
|
30
|
+
dot += a.vec[i] * b.vec[i];
|
|
31
|
+
return dot * a.inv * b.inv;
|
|
32
|
+
}
|
|
33
|
+
/** Rows of one scope and type: the only peers a duplicate or a uniqueness score may use. */
|
|
34
|
+
export function peersOf(rows, like) {
|
|
35
|
+
return rows.filter((r) => r.type === like.type && sameScope(r.scope, like.scope));
|
|
36
|
+
}
|
|
37
|
+
/** `1 - maxCosine` against `peers` (other than itself). 1 when there is nothing to compare. */
|
|
38
|
+
export function uniquenessAmong(target, peers) {
|
|
39
|
+
let max = 0;
|
|
40
|
+
for (const peer of peers) {
|
|
41
|
+
if (peer.row.id === target.row.id)
|
|
42
|
+
continue;
|
|
43
|
+
max = Math.max(max, cosinePrepared(target, peer));
|
|
44
|
+
}
|
|
45
|
+
return Math.max(0, Math.min(1, 1 - max));
|
|
46
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type GeneConfig } from '@aragon-agent/tui/model/config/schema';
|
|
2
|
+
import type { GeneProposal } from '@aragon-agent/tui/model/gene/types';
|
|
3
|
+
import type { ProjectLearningPolicy } from '../policy.js';
|
|
4
|
+
/** Returns the on-disk `gene` section, or null when there is none to read. */
|
|
5
|
+
export type PersistedGeneConfigReader = () => Promise<Partial<GeneConfig> | null>;
|
|
6
|
+
export type SwitchOffReason = 'disabled' | 'learning_off' | 'redteam';
|
|
7
|
+
export type SwitchVerdict = {
|
|
8
|
+
on: true;
|
|
9
|
+
config: GeneConfig;
|
|
10
|
+
} | {
|
|
11
|
+
on: false;
|
|
12
|
+
reason: SwitchOffReason;
|
|
13
|
+
config: GeneConfig;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* `min` / `and` of the live and the persisted value. Only the settings that gate safety or spend
|
|
17
|
+
* are tightened; `curatorModel` and the manager-facing knobs stay as the live process has them.
|
|
18
|
+
*/
|
|
19
|
+
export declare function stricterGeneConfig(live: GeneConfig, persisted: Partial<GeneConfig> | null): GeneConfig;
|
|
20
|
+
/** Why a proposal's SOURCE PROJECT may not be learned from (I3-5). Kept apart from SwitchOffReason. */
|
|
21
|
+
export type ProjectVerdictForOrigin = {
|
|
22
|
+
on: true;
|
|
23
|
+
} | {
|
|
24
|
+
on: false;
|
|
25
|
+
reason: 'project_excluded';
|
|
26
|
+
};
|
|
27
|
+
export type ProposalSource = GeneProposal['origin']['source'];
|
|
28
|
+
/**
|
|
29
|
+
* Does this origin carry SESSION or PROJECT content, so that the per-project switch applies?
|
|
30
|
+
* An exhaustive switch (no `default`) on purpose: a new source is a compile error until someone
|
|
31
|
+
* decides which side of the privacy line it is on.
|
|
32
|
+
*/
|
|
33
|
+
export declare function sourceCarriesProjectContent(source: ProposalSource): boolean;
|
|
34
|
+
export interface ProjectGate {
|
|
35
|
+
policy: Pick<ProjectLearningPolicy, 'refresh'>;
|
|
36
|
+
/** The project root recorded in `project.json`, or null when it cannot be read. */
|
|
37
|
+
rootOf(projectKey: string): Promise<string | null>;
|
|
38
|
+
}
|
|
39
|
+
export interface SwitchGuardDeps {
|
|
40
|
+
/** This process's live config; read at EVERY checkpoint, never captured. */
|
|
41
|
+
live(): GeneConfig;
|
|
42
|
+
persisted?: PersistedGeneConfigReader;
|
|
43
|
+
/** Red-team mode armed: learning is paused (10.6). */
|
|
44
|
+
redteam?(): boolean;
|
|
45
|
+
/** The per-project learning switch; absent = no project is ever excluded here. */
|
|
46
|
+
projects?: ProjectGate;
|
|
47
|
+
}
|
|
48
|
+
/** One object the host, the tools and the publish gate all ask, so there is one definition. */
|
|
49
|
+
export declare class SwitchGuard {
|
|
50
|
+
private readonly deps;
|
|
51
|
+
constructor(deps: SwitchGuardDeps);
|
|
52
|
+
effective(): Promise<GeneConfig>;
|
|
53
|
+
check(): Promise<SwitchVerdict>;
|
|
54
|
+
/**
|
|
55
|
+
* The per-project switch for ONE proposal's origin. Deliberately NOT part of `check()`: the
|
|
56
|
+
* global verdict pauses the whole curator, whereas a project exclusion must only drop the
|
|
57
|
+
* proposals that came from that project and leave every other project's work running.
|
|
58
|
+
*
|
|
59
|
+
* `projectKey === null` (an origin that predates the field) cannot be judged and is allowed;
|
|
60
|
+
* the learner, which holds the project root, is the authority at the moment content would leave
|
|
61
|
+
* the machine. A repository marker is only visible when `project.json` names the root.
|
|
62
|
+
*/
|
|
63
|
+
checkFor(origin: {
|
|
64
|
+
projectKey: string | null;
|
|
65
|
+
source: ProposalSource;
|
|
66
|
+
}): Promise<ProjectVerdictForOrigin>;
|
|
67
|
+
}
|
|
68
|
+
export interface PersistedReaderOptions {
|
|
69
|
+
/** Absolute path of `config.json`. */
|
|
70
|
+
path: string;
|
|
71
|
+
/** Observability for tests: called whenever the file is actually re-parsed. */
|
|
72
|
+
onParse?(): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reads the `gene` section of the user's config file, caching on `size:mtime`. A missing or
|
|
76
|
+
* unparsable file reads as null (the live config then decides alone).
|
|
77
|
+
*/
|
|
78
|
+
export declare function createPersistedGeneConfigReader(options: PersistedReaderOptions): PersistedGeneConfigReader;
|