@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,61 @@
|
|
|
1
|
+
import { sameScope } from '@aragon-agent/tui/model/gene/ids';
|
|
2
|
+
import { GENE_SCORE } from '@aragon-agent/tui/model/gene/limits';
|
|
3
|
+
import { cosineInt8, decodeVec } from '@aragon-agent/tui/model/gene/hashvec';
|
|
4
|
+
import { tombstonesFile } from './paths.js';
|
|
5
|
+
import { statOrNull } from './fs.js';
|
|
6
|
+
function inRange(tombstone, scope) {
|
|
7
|
+
return tombstone.scope === 'all' || sameScope(tombstone.scope, scope);
|
|
8
|
+
}
|
|
9
|
+
export class TombstoneStore {
|
|
10
|
+
store;
|
|
11
|
+
now;
|
|
12
|
+
cache = null;
|
|
13
|
+
constructor(store, now = Date.now) {
|
|
14
|
+
this.store = store;
|
|
15
|
+
this.now = now;
|
|
16
|
+
}
|
|
17
|
+
async add(tombstone) {
|
|
18
|
+
const full = { schema: 1, ...tombstone, createdAt: this.now() };
|
|
19
|
+
await this.store.appendTombstone(full);
|
|
20
|
+
this.cache = null;
|
|
21
|
+
return full;
|
|
22
|
+
}
|
|
23
|
+
async all() {
|
|
24
|
+
const stat = await statOrNull(tombstonesFile(this.store.ctx));
|
|
25
|
+
const stamp = stat === null ? 'none' : `${stat.size}:${stat.mtimeMs}`;
|
|
26
|
+
if (this.cache !== null && this.cache.stamp === stamp)
|
|
27
|
+
return this.cache.rows;
|
|
28
|
+
const rows = await this.store.readTombstones();
|
|
29
|
+
this.cache = { stamp, rows };
|
|
30
|
+
return rows;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The first tombstone this candidate matches, or `null`. NEVER throws: a read must not block a
|
|
34
|
+
* write path.
|
|
35
|
+
*/
|
|
36
|
+
async isForgotten(query) {
|
|
37
|
+
try {
|
|
38
|
+
return this.match(await this.all(), query);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
match(rows, query) {
|
|
45
|
+
const vec = query.vec === undefined ? null : decodeVec(query.vec);
|
|
46
|
+
for (const row of rows) {
|
|
47
|
+
if (row.type !== query.type || !inRange(row, query.scope))
|
|
48
|
+
continue;
|
|
49
|
+
if (row.fingerprint === query.fingerprint || isNear(vec, row.vec))
|
|
50
|
+
return row;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Is the candidate's vector within the duplicate threshold of the tombstone's? */
|
|
56
|
+
function isNear(vec, tombstoneVec) {
|
|
57
|
+
if (vec === null || tombstoneVec === undefined)
|
|
58
|
+
return false;
|
|
59
|
+
const other = decodeVec(tombstoneVec);
|
|
60
|
+
return other !== null && cosineInt8(vec, other) >= GENE_SCORE.duplicateCosine;
|
|
61
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning a tool gene's stored argv into a command the caller's `bash` tool can run
|
|
3
|
+
* (gene-bank spec 6.3.2, 9.1, RV-4, I-15).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`. The PURE half of the
|
|
6
|
+
* runner: placeholder substitution and shell quoting. The effectful half (the permission
|
|
7
|
+
* comparison, delegation to `bash`, the adoption receipt) lives in `gene/tools.ts`, which is
|
|
8
|
+
* handed the caller's real `bash` tool and holds NO approval logic of its own.
|
|
9
|
+
*
|
|
10
|
+
* WHY QUOTING IS A SECURITY BOUNDARY (RV-4). A tool gene stores `argv: string[]` precisely so
|
|
11
|
+
* that no argument value can become shell syntax. But the `bash` tool runs a STRING:
|
|
12
|
+
* `spawn(command, { shell: true })` - `cmd.exe` on Windows, `/bin/sh` elsewhere. Storing argv
|
|
13
|
+
* does not make EXECUTION safe; the join into a string must. So:
|
|
14
|
+
* - a placeholder may replace only a WHOLE element (never a fragment inside one);
|
|
15
|
+
* - POSIX / PowerShell: every element that is not plainly safe is single-quoted, with the
|
|
16
|
+
* shell's own escape for an embedded quote;
|
|
17
|
+
* - cmd.exe has NO reliable escape (`%VAR%` expands even inside double quotes, `^` and `!`
|
|
18
|
+
* behave differently across contexts), so a value containing any of `% ^ & | < > " !` or
|
|
19
|
+
* a control character is REFUSED rather than escaped. Refusing is the only reliable rule.
|
|
20
|
+
*/
|
|
21
|
+
export type ShellKind = 'posix' | 'powershell' | 'cmd';
|
|
22
|
+
export type SubstituteResult = {
|
|
23
|
+
ok: true;
|
|
24
|
+
argv: string[];
|
|
25
|
+
} | {
|
|
26
|
+
ok: false;
|
|
27
|
+
reason: string;
|
|
28
|
+
};
|
|
29
|
+
export type QuoteResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
command: string;
|
|
32
|
+
} | {
|
|
33
|
+
ok: false;
|
|
34
|
+
reason: string;
|
|
35
|
+
};
|
|
36
|
+
/** Pick the shell the `bash` tool actually uses from the fingerprint's `shell`. */
|
|
37
|
+
export declare function shellKindOf(shell: string): ShellKind;
|
|
38
|
+
/**
|
|
39
|
+
* Replace `{{name}}` elements with argument values. A placeholder inside a LARGER element is a
|
|
40
|
+
* defect in the gene (the validator rejects it at publish time) and is refused here too.
|
|
41
|
+
* Values must be scalars; an array or object is never flattened into a command line.
|
|
42
|
+
*/
|
|
43
|
+
export declare function substituteArgv(argv: readonly string[], args: Record<string, unknown>): SubstituteResult;
|
|
44
|
+
/** Join an argv into one command string for the given shell; refuse what cannot be quoted. */
|
|
45
|
+
export declare function quoteArgv(argv: readonly string[], kind: ShellKind): QuoteResult;
|
|
46
|
+
/** Substitute then quote in one step; the single entry the executor uses. */
|
|
47
|
+
export declare function buildCommand(argv: readonly string[], args: Record<string, unknown>, kind: ShellKind): QuoteResult;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning a tool gene's stored argv into a command the caller's `bash` tool can run
|
|
3
|
+
* (gene-bank spec 6.3.2, 9.1, RV-4, I-15).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`. The PURE half of the
|
|
6
|
+
* runner: placeholder substitution and shell quoting. The effectful half (the permission
|
|
7
|
+
* comparison, delegation to `bash`, the adoption receipt) lives in `gene/tools.ts`, which is
|
|
8
|
+
* handed the caller's real `bash` tool and holds NO approval logic of its own.
|
|
9
|
+
*
|
|
10
|
+
* WHY QUOTING IS A SECURITY BOUNDARY (RV-4). A tool gene stores `argv: string[]` precisely so
|
|
11
|
+
* that no argument value can become shell syntax. But the `bash` tool runs a STRING:
|
|
12
|
+
* `spawn(command, { shell: true })` - `cmd.exe` on Windows, `/bin/sh` elsewhere. Storing argv
|
|
13
|
+
* does not make EXECUTION safe; the join into a string must. So:
|
|
14
|
+
* - a placeholder may replace only a WHOLE element (never a fragment inside one);
|
|
15
|
+
* - POSIX / PowerShell: every element that is not plainly safe is single-quoted, with the
|
|
16
|
+
* shell's own escape for an embedded quote;
|
|
17
|
+
* - cmd.exe has NO reliable escape (`%VAR%` expands even inside double quotes, `^` and `!`
|
|
18
|
+
* behave differently across contexts), so a value containing any of `% ^ & | < > " !` or
|
|
19
|
+
* a control character is REFUSED rather than escaped. Refusing is the only reliable rule.
|
|
20
|
+
*/
|
|
21
|
+
const WHOLE_PLACEHOLDER = /^\{\{([A-Za-z_][A-Za-z0-9_]{0,40})\}\}$/;
|
|
22
|
+
const ANY_PLACEHOLDER = /\{\{[^}]*\}\}/;
|
|
23
|
+
const SAFE_BARE = /^[A-Za-z0-9_@%+=:,./\\-]+$/;
|
|
24
|
+
const CMD_FORBIDDEN = /[%^&|<>"!\u0000-\u001f]/;
|
|
25
|
+
/** Tab is allowed inside a quoted value; CR, LF, NUL and the other controls never are. */
|
|
26
|
+
const CONTROL = /[\u0000-\u0008\u000a-\u001f\u007f]/;
|
|
27
|
+
const MAX_ELEMENT = 4096;
|
|
28
|
+
/** Pick the shell the `bash` tool actually uses from the fingerprint's `shell`. */
|
|
29
|
+
export function shellKindOf(shell) {
|
|
30
|
+
if (shell === 'powershell')
|
|
31
|
+
return 'powershell';
|
|
32
|
+
if (shell === 'cmd')
|
|
33
|
+
return 'cmd';
|
|
34
|
+
return 'posix';
|
|
35
|
+
}
|
|
36
|
+
function scalarText(value) {
|
|
37
|
+
if (typeof value === 'string')
|
|
38
|
+
return value;
|
|
39
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
40
|
+
return String(value);
|
|
41
|
+
if (typeof value === 'boolean')
|
|
42
|
+
return value ? 'true' : 'false';
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Replace `{{name}}` elements with argument values. A placeholder inside a LARGER element is a
|
|
47
|
+
* defect in the gene (the validator rejects it at publish time) and is refused here too.
|
|
48
|
+
* Values must be scalars; an array or object is never flattened into a command line.
|
|
49
|
+
*/
|
|
50
|
+
export function substituteArgv(argv, args) {
|
|
51
|
+
const out = [];
|
|
52
|
+
for (const element of argv) {
|
|
53
|
+
const whole = WHOLE_PLACEHOLDER.exec(element);
|
|
54
|
+
if (whole) {
|
|
55
|
+
const text = scalarText(args[whole[1]]);
|
|
56
|
+
if (text === null)
|
|
57
|
+
return { ok: false, reason: `argument ${whole[1]} is missing or not a scalar` };
|
|
58
|
+
if (text.length > MAX_ELEMENT || CONTROL.test(text))
|
|
59
|
+
return { ok: false, reason: `argument ${whole[1]} contains unsupported characters` };
|
|
60
|
+
out.push(text);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (ANY_PLACEHOLDER.test(element)) {
|
|
64
|
+
return { ok: false, reason: 'a placeholder must be a whole argument, not part of one' };
|
|
65
|
+
}
|
|
66
|
+
out.push(element);
|
|
67
|
+
}
|
|
68
|
+
return { ok: true, argv: out };
|
|
69
|
+
}
|
|
70
|
+
function quotePosix(token) {
|
|
71
|
+
if (token.length > 0 && SAFE_BARE.test(token) && !token.includes('\\'))
|
|
72
|
+
return token;
|
|
73
|
+
return `'${token.replace(/'/g, `'\\''`)}'`;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* POWERSHELL QUOTING (found by the real-shell corpus test, RV-4 / C-4).
|
|
77
|
+
*
|
|
78
|
+
* Doubling the ASCII `'` is NOT enough: PowerShell treats U+2018, U+2019, U+201A and U+201B as
|
|
79
|
+
* single-quote characters too, so a value like `a<U+2019>; echo INJECTED; <U+2018>b` closed the
|
|
80
|
+
* string early and ran `echo INJECTED`. All four are doubled. The curly quotes are written as
|
|
81
|
+
* `\u{...}` code-point escapes with the `u` flag, so no non-ASCII byte appears in this file.
|
|
82
|
+
*/
|
|
83
|
+
const PS_SINGLE_QUOTES = /['\u{2018}\u{2019}\u{201a}\u{201b}]/gu;
|
|
84
|
+
/**
|
|
85
|
+
* A token that may go bare. The FIRST character excludes `@` (splatting) and `%`; the body has no
|
|
86
|
+
* comma (an array argument in PowerShell) and no `$`, backtick, `;`, `&`, `|`, braces, quotes.
|
|
87
|
+
*/
|
|
88
|
+
const PS_BARE = /^[A-Za-z0-9_./\\:+=-][A-Za-z0-9_@%.+=:/\\-]*$/;
|
|
89
|
+
/** `--%` is PowerShell's stop-parsing token and must never be passed bare. */
|
|
90
|
+
const PS_STOP_PARSING = '--%';
|
|
91
|
+
function quotePowerShell(token) {
|
|
92
|
+
// Windows PowerShell 5.1 silently DROPS an empty-string argument to a native command, and
|
|
93
|
+
// strips embedded double quotes: either would change the argument list, so refuse (as cmd.exe
|
|
94
|
+
// does) rather than pass something different from what the gene declared.
|
|
95
|
+
if (token.length === 0)
|
|
96
|
+
return { ok: false, reason: 'an empty value cannot be passed reliably by PowerShell' };
|
|
97
|
+
if (token.includes('"'))
|
|
98
|
+
return { ok: false, reason: 'a value with a double quote cannot be passed reliably by PowerShell' };
|
|
99
|
+
if (/\s/.test(token) && token.endsWith('\\')) {
|
|
100
|
+
return { ok: false, reason: 'a value with spaces that ends in a backslash cannot be passed reliably' };
|
|
101
|
+
}
|
|
102
|
+
// Even QUOTED, `--%` is swallowed by Windows PowerShell 5.1 as its stop-parsing token and the
|
|
103
|
+
// argument vanishes (real-shell corpus): no quoting form delivers it, so it is refused.
|
|
104
|
+
if (token === PS_STOP_PARSING)
|
|
105
|
+
return { ok: false, reason: 'the value --% cannot be passed by PowerShell' };
|
|
106
|
+
if (PS_BARE.test(token))
|
|
107
|
+
return token;
|
|
108
|
+
return `'${token.replace(PS_SINGLE_QUOTES, (q) => q + q)}'`;
|
|
109
|
+
}
|
|
110
|
+
function quoteCmd(token) {
|
|
111
|
+
if (CMD_FORBIDDEN.test(token))
|
|
112
|
+
return { ok: false, reason: 'value contains characters cmd.exe cannot quote safely' };
|
|
113
|
+
if (token.length === 0)
|
|
114
|
+
return '""';
|
|
115
|
+
if (/\s/.test(token) && token.endsWith('\\')) {
|
|
116
|
+
return { ok: false, reason: 'a value with spaces that ends in a backslash cannot be passed reliably' };
|
|
117
|
+
}
|
|
118
|
+
return /\s/.test(token) ? `"${token}"` : token;
|
|
119
|
+
}
|
|
120
|
+
/** Join an argv into one command string for the given shell; refuse what cannot be quoted. */
|
|
121
|
+
export function quoteArgv(argv, kind) {
|
|
122
|
+
if (argv.length === 0)
|
|
123
|
+
return { ok: false, reason: 'empty command' };
|
|
124
|
+
const parts = [];
|
|
125
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
126
|
+
const token = argv[i];
|
|
127
|
+
if (CONTROL.test(token) || token.length > MAX_ELEMENT) {
|
|
128
|
+
return { ok: false, reason: 'value contains unsupported characters' };
|
|
129
|
+
}
|
|
130
|
+
if (kind === 'cmd') {
|
|
131
|
+
const quoted = quoteCmd(token);
|
|
132
|
+
if (typeof quoted !== 'string')
|
|
133
|
+
return quoted;
|
|
134
|
+
parts.push(quoted);
|
|
135
|
+
}
|
|
136
|
+
else if (kind === 'powershell') {
|
|
137
|
+
const quoted = quotePowerShell(token);
|
|
138
|
+
if (typeof quoted !== 'string')
|
|
139
|
+
return quoted;
|
|
140
|
+
parts.push(i === 0 && quoted !== token ? `& ${quoted}` : quoted);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
parts.push(quotePosix(token));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { ok: true, command: parts.join(' ') };
|
|
147
|
+
}
|
|
148
|
+
/** Substitute then quote in one step; the single entry the executor uses. */
|
|
149
|
+
export function buildCommand(argv, args, kind) {
|
|
150
|
+
const substituted = substituteArgv(argv, args);
|
|
151
|
+
if (!substituted.ok)
|
|
152
|
+
return substituted;
|
|
153
|
+
return quoteArgv(substituted.argv, kind);
|
|
154
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static screening of tool genes (gene-bank spec 11.4, 10.7.2 T2/T3/T7, RV-1).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`. PURE: no I/O, no clock.
|
|
5
|
+
*
|
|
6
|
+
* WHAT THIS IS FOR, AND WHAT IT IS NOT. It labels a tool gene with a `risk` and the
|
|
7
|
+
* permissions it needs, and it recognises the one narrow class that may be probed by the
|
|
8
|
+
* background curator without a human: a single READ-ONLY command from a short allow-list.
|
|
9
|
+
*
|
|
10
|
+
* It is NOT a sandbox and NOT a proof of safety (RV-1). Static analysis of an interpreter
|
|
11
|
+
* script is undecidable - obfuscation, dynamic `require`, string concatenation - so a script
|
|
12
|
+
* or a composite is NEVER auto-executed no matter what this returns; they wait for a human who
|
|
13
|
+
* has read the full text. The model's own claim about risk is ignored: `risk` is always
|
|
14
|
+
* recomputed here, and an UNKNOWN command is assumed to write (the conservative direction).
|
|
15
|
+
*
|
|
16
|
+
* The same word list (`UNSAFE_INSTRUCTION_PATTERNS`) backs the SKILL check S5: a skill body
|
|
17
|
+
* may not tell the next agent to bypass a gate.
|
|
18
|
+
*/
|
|
19
|
+
import type { GenePermission, GeneToolRisk, ToolExec } from '@aragon-agent/tui/model/gene/types';
|
|
20
|
+
export interface ToolScreen {
|
|
21
|
+
risk: GeneToolRisk;
|
|
22
|
+
/** Permissions the static analysis derived (the declared set must cover these). */
|
|
23
|
+
permissions: GenePermission[];
|
|
24
|
+
/** Short machine reasons, e.g. 'high:sudo', 'network:curl', 'fs_write:rm'. Never gene text. */
|
|
25
|
+
reasons: string[];
|
|
26
|
+
/** Exactly the class the background curator may probe on its own (T4). */
|
|
27
|
+
autoProbeEligible: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Commands whose first word makes a call read-only, with no other flag inspection needed. */
|
|
30
|
+
export declare const READ_ONLY_COMMANDS: ReadonlySet<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Screen one tool exec. `scriptText` is the tier-3 implementation text for `kind: 'script'`
|
|
33
|
+
* (the caller reads it from the gene's `impl` evidence); without it a script is `high`,
|
|
34
|
+
* because code that cannot be read cannot be judged.
|
|
35
|
+
*/
|
|
36
|
+
export declare function screenToolExec(exec: ToolExec, scriptText?: string): ToolScreen;
|
|
37
|
+
/** Does the declared permission set cover everything the screen derived? (T3) */
|
|
38
|
+
export declare function missingPermissions(declared: readonly GenePermission[], derived: readonly GenePermission[]): GenePermission[];
|
|
39
|
+
/** Phrases a SKILL body must not contain: instructions that bypass a gate (S5). */
|
|
40
|
+
export declare const UNSAFE_INSTRUCTION_PATTERNS: ReadonlyArray<readonly [string, RegExp]>;
|
|
41
|
+
export declare function findUnsafeInstruction(text: string): string | null;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/** Commands whose first word makes a call read-only, with no other flag inspection needed. */
|
|
2
|
+
export const READ_ONLY_COMMANDS = new Set([
|
|
3
|
+
'ls', 'dir', 'cat', 'type', 'head', 'tail', 'wc', 'grep', 'rg', 'pwd', 'echo', 'which', 'where',
|
|
4
|
+
'whoami', 'hostname', 'date', 'uname', 'stat', 'file', 'du', 'df', 'tree', 'sort', 'uniq', 'cut',
|
|
5
|
+
'basename', 'dirname', 'realpath', 'sha1sum', 'sha256sum', 'md5sum', 'get-content', 'get-childitem',
|
|
6
|
+
'select-string', 'measure-object', 'get-location',
|
|
7
|
+
]);
|
|
8
|
+
/** `git <sub>` subcommands that never modify the repository or the working tree. */
|
|
9
|
+
const READ_ONLY_GIT = new Set([
|
|
10
|
+
'status', 'diff', 'log', 'show', 'rev-parse', 'rev-list', 'describe', 'ls-files', 'ls-tree',
|
|
11
|
+
'cat-file', 'blame', 'shortlog', 'remote-v', 'config-get',
|
|
12
|
+
]);
|
|
13
|
+
const WRITE_COMMANDS = new Set([
|
|
14
|
+
'rm', 'rmdir', 'mv', 'cp', 'mkdir', 'touch', 'tee', 'ln', 'chmod', 'chown', 'del', 'erase',
|
|
15
|
+
'rd', 'move', 'copy', 'ren', 'rename', 'xcopy', 'robocopy', 'truncate', 'install',
|
|
16
|
+
'remove-item', 'move-item', 'copy-item', 'new-item', 'set-content', 'add-content', 'out-file',
|
|
17
|
+
'rename-item',
|
|
18
|
+
]);
|
|
19
|
+
const NETWORK_COMMANDS = new Set([
|
|
20
|
+
'curl', 'wget', 'invoke-webrequest', 'iwr', 'invoke-restmethod', 'irm', 'ssh', 'scp', 'sftp',
|
|
21
|
+
'ftp', 'nc', 'ncat', 'telnet', 'ping', 'nslookup', 'dig',
|
|
22
|
+
]);
|
|
23
|
+
const HIGH_COMMANDS = new Set([
|
|
24
|
+
'sudo', 'su', 'runas', 'doas', 'format', 'mkfs', 'dd', 'shutdown', 'reboot', 'diskpart',
|
|
25
|
+
'iex', 'invoke-expression',
|
|
26
|
+
]);
|
|
27
|
+
const PACKAGE_MANAGERS = new Set(['npm', 'pnpm', 'yarn', 'bun', 'pip', 'pip3', 'cargo', 'go', 'gem', 'composer']);
|
|
28
|
+
const PACKAGE_WRITE_SUBS = new Set([
|
|
29
|
+
'install', 'i', 'add', 'remove', 'rm', 'uninstall', 'update', 'upgrade', 'ci', 'link', 'publish',
|
|
30
|
+
'init', 'build', 'run', 'exec', 'dlx', 'x',
|
|
31
|
+
]);
|
|
32
|
+
const GIT_WRITE_SUBS = new Set([
|
|
33
|
+
'add', 'commit', 'checkout', 'switch', 'reset', 'clean', 'stash', 'merge', 'rebase', 'cherry-pick',
|
|
34
|
+
'revert', 'apply', 'am', 'mv', 'rm', 'restore', 'tag', 'branch', 'init', 'config', 'gc', 'prune',
|
|
35
|
+
]);
|
|
36
|
+
const GIT_NETWORK_SUBS = new Set(['clone', 'fetch', 'pull', 'push', 'ls-remote', 'submodule']);
|
|
37
|
+
/** Script-text patterns, by derived effect. Matched case-insensitively against the whole text. */
|
|
38
|
+
const SCRIPT_HIGH = [
|
|
39
|
+
['eval', /\beval\s*\(/i],
|
|
40
|
+
['exec-dynamic', /\b(?:child_process|subprocess|os\.system|Runtime\.getRuntime|Start-Process)\b/i],
|
|
41
|
+
['encoded-command', /-EncodedCommand\b|\bFromBase64String\b|\bbase64\s+(?:-d|--decode)\b|\batob\s*\(/i],
|
|
42
|
+
['pipe-to-shell', /\|\s*(?:sh|bash|zsh|iex|invoke-expression|powershell|pwsh)\b/i],
|
|
43
|
+
['secret-read', /(?:~|\$HOME|%USERPROFILE%|\$env:USERPROFILE)[\\/]+\.(?:ssh|aws|gnupg|kube|docker)|(?:^|[\s"'\\/])\.env(?:\.[a-z]+)?\b/i],
|
|
44
|
+
['secret-env', /\$\{?(?:AWS_|GITHUB_TOKEN|NPM_TOKEN|OPENAI_|ANTHROPIC_)|%[A-Z_]*(?:TOKEN|SECRET|PASSWORD|KEY)[A-Z_]*%|\$env:[A-Z_]*(?:TOKEN|SECRET|PASSWORD|KEY)/i],
|
|
45
|
+
['destructive-root', /\brm\s+-[a-z]*r[a-z]*f?[a-z]*\s+(?:\/|~|\$HOME)(?:\s|$)|Remove-Item\b[^\n]*-Recurse[^\n]*(?:[A-Za-z]:\\\s*$|\\\\|\$HOME|~)/i],
|
|
46
|
+
['registry-write', /\breg\s+(?:add|delete)\b/i],
|
|
47
|
+
];
|
|
48
|
+
const SCRIPT_NETWORK = [
|
|
49
|
+
['net-fetch', /\bfetch\s*\(|\bhttp\.request\b|\bhttps\.request\b|\bhttp\.get\b|\bhttps\.get\b|\brequests\.|\burllib\b|\bnet\.connect\b|\bnew\s+WebSocket\b|\baxios\b|\bInvoke-(?:WebRequest|RestMethod)\b|\bcurl\b|\bwget\b/i],
|
|
50
|
+
];
|
|
51
|
+
const SCRIPT_WRITE = [
|
|
52
|
+
['fs-write', /\bwriteFile(?:Sync)?\b|\bappendFile(?:Sync)?\b|\bunlink(?:Sync)?\b|\brmSync\b|\bmkdir(?:Sync)?\b|\brename(?:Sync)?\b|\bopen\s*\([^)]*['"][wax]\+?['"]|\bshutil\.|\bos\.(?:remove|rename|mkdir|makedirs)\b|\bSet-Content\b|\bOut-File\b|\bRemove-Item\b|\bNew-Item\b|>>?\s*[\w./\\"']/i],
|
|
53
|
+
];
|
|
54
|
+
function baseCommand(token) {
|
|
55
|
+
const name = token.replace(/\\/g, '/').split('/').pop() ?? token;
|
|
56
|
+
return name.toLowerCase().replace(/\.(?:exe|cmd|bat|ps1|com)$/i, '');
|
|
57
|
+
}
|
|
58
|
+
function hasRedirect(argv) {
|
|
59
|
+
return argv.some((t) => t === '>' || t === '>>' || t === '1>' || t === '2>' || /^\d?>>?$/.test(t));
|
|
60
|
+
}
|
|
61
|
+
function pathEscapesWorkspace(token) {
|
|
62
|
+
if (/(^|[\\/])\.\.([\\/]|$)/.test(token))
|
|
63
|
+
return true;
|
|
64
|
+
if (/^(?:[A-Za-z]:[\\/]|\/(?!\/))/.test(token) && token.length > 1)
|
|
65
|
+
return true;
|
|
66
|
+
return token.startsWith('~');
|
|
67
|
+
}
|
|
68
|
+
function note(acc, effect, reason) {
|
|
69
|
+
acc[effect] = true;
|
|
70
|
+
if (!acc.reasons.includes(reason))
|
|
71
|
+
acc.reasons.push(reason);
|
|
72
|
+
}
|
|
73
|
+
function screenGit(argv, acc) {
|
|
74
|
+
const sub = (argv.slice(1).find((t) => !t.startsWith('-')) ?? '').toLowerCase();
|
|
75
|
+
if (GIT_NETWORK_SUBS.has(sub))
|
|
76
|
+
note(acc, 'network', `network:git-${sub}`);
|
|
77
|
+
if (GIT_WRITE_SUBS.has(sub)) {
|
|
78
|
+
// `git branch` / `git tag` / `git config` with no extra operand only list or read.
|
|
79
|
+
const operands = argv.slice(1).filter((t) => !t.startsWith('-'));
|
|
80
|
+
const listing = ['branch', 'tag', 'config'].includes(sub) && operands.length <= 1;
|
|
81
|
+
if (!listing || argv.some((t) => /^-(?:d|D|m|M|f|-delete|-set|-unset|-add)/.test(t))) {
|
|
82
|
+
note(acc, 'write', `fs_write:git-${sub}`);
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!READ_ONLY_GIT.has(sub) && !GIT_NETWORK_SUBS.has(sub))
|
|
87
|
+
note(acc, 'unknown', `unknown:git-${sub || 'none'}`);
|
|
88
|
+
}
|
|
89
|
+
function screenPackageManager(cmd, argv, acc) {
|
|
90
|
+
const sub = (argv.slice(1).find((t) => !t.startsWith('-')) ?? '').toLowerCase();
|
|
91
|
+
if (sub === 'publish')
|
|
92
|
+
note(acc, 'network', `network:${cmd}-publish`);
|
|
93
|
+
if (['--version', '-v', '-V', 'version', 'ls', 'list', 'outdated', 'why', 'view', 'info', 'config'].includes(sub) ||
|
|
94
|
+
argv.length === 2 && /^-{1,2}(?:v|version)$/i.test(argv[1] ?? '')) {
|
|
95
|
+
if (['view', 'info', 'outdated'].includes(sub))
|
|
96
|
+
note(acc, 'network', `network:${cmd}-${sub}`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (PACKAGE_WRITE_SUBS.has(sub))
|
|
100
|
+
note(acc, 'write', `fs_write:${cmd}-${sub}`);
|
|
101
|
+
else
|
|
102
|
+
note(acc, 'unknown', `unknown:${cmd}-${sub || 'none'}`);
|
|
103
|
+
}
|
|
104
|
+
function screenCommandWords(argv, acc) {
|
|
105
|
+
const first = argv[0];
|
|
106
|
+
if (!first) {
|
|
107
|
+
note(acc, 'unknown', 'unknown:empty');
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const cmd = baseCommand(first);
|
|
111
|
+
if (HIGH_COMMANDS.has(cmd))
|
|
112
|
+
note(acc, 'high', `high:${cmd}`);
|
|
113
|
+
else if (cmd === 'git')
|
|
114
|
+
screenGit(argv, acc);
|
|
115
|
+
else if (PACKAGE_MANAGERS.has(cmd))
|
|
116
|
+
screenPackageManager(cmd, argv, acc);
|
|
117
|
+
else if (cmd === 'node' || cmd === 'python' || cmd === 'python3' || cmd === 'tsc' || cmd === 'npx') {
|
|
118
|
+
if (argv.length === 2 && /^-{1,2}(?:v|version)$/i.test(argv[1] ?? ''))
|
|
119
|
+
return;
|
|
120
|
+
note(acc, 'unknown', `unknown:${cmd}`);
|
|
121
|
+
}
|
|
122
|
+
else if (NETWORK_COMMANDS.has(cmd))
|
|
123
|
+
note(acc, 'network', `network:${cmd}`);
|
|
124
|
+
else if (WRITE_COMMANDS.has(cmd))
|
|
125
|
+
note(acc, 'write', `fs_write:${cmd}`);
|
|
126
|
+
else if (cmd === 'sed' && argv.some((t) => /^-[a-z]*i/.test(t)))
|
|
127
|
+
note(acc, 'write', 'fs_write:sed-i');
|
|
128
|
+
else if (cmd === 'find' && argv.some((t) => ['-delete', '-exec', '-execdir', '-fprint', '-ok'].includes(t))) {
|
|
129
|
+
note(acc, 'write', 'fs_write:find-exec');
|
|
130
|
+
}
|
|
131
|
+
else if (cmd === 'rm' || cmd === 'remove-item')
|
|
132
|
+
note(acc, 'write', `fs_write:${cmd}`);
|
|
133
|
+
else if (!READ_ONLY_COMMANDS.has(cmd) && cmd !== 'find' && cmd !== 'sed' && cmd !== 'awk') {
|
|
134
|
+
note(acc, 'unknown', `unknown:${cmd}`);
|
|
135
|
+
}
|
|
136
|
+
if (['sh', 'bash', 'zsh', 'cmd', 'powershell', 'pwsh'].includes(cmd)) {
|
|
137
|
+
note(acc, 'unknown', `unknown:shell-${cmd}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function screenText(text, acc) {
|
|
141
|
+
for (const [reason, re] of SCRIPT_HIGH)
|
|
142
|
+
if (re.test(text))
|
|
143
|
+
note(acc, 'high', `high:${reason}`);
|
|
144
|
+
for (const [reason, re] of SCRIPT_NETWORK)
|
|
145
|
+
if (re.test(text))
|
|
146
|
+
note(acc, 'network', `network:${reason}`);
|
|
147
|
+
for (const [reason, re] of SCRIPT_WRITE)
|
|
148
|
+
if (re.test(text))
|
|
149
|
+
note(acc, 'write', `fs_write:${reason}`);
|
|
150
|
+
}
|
|
151
|
+
function screenArgv(argv, acc) {
|
|
152
|
+
screenCommandWords(argv, acc);
|
|
153
|
+
if (hasRedirect(argv))
|
|
154
|
+
note(acc, 'write', 'fs_write:redirect');
|
|
155
|
+
for (const token of argv.slice(1)) {
|
|
156
|
+
if (!token.startsWith('-') && pathEscapesWorkspace(token) && acc.write)
|
|
157
|
+
note(acc, 'high', 'high:path-outside-workspace');
|
|
158
|
+
}
|
|
159
|
+
screenText(argv.join(' '), acc);
|
|
160
|
+
}
|
|
161
|
+
/** Built-in tools a composite may call without writing; anything else counts as a write. */
|
|
162
|
+
const READ_ONLY_BUILTINS = new Set(['read_file', 'grep', 'glob', 'list_dir', 'ls', 'find_files', 'read']);
|
|
163
|
+
function screenComposite(steps, acc) {
|
|
164
|
+
for (const step of steps) {
|
|
165
|
+
if (step.tool === 'bash' && typeof step.args.command === 'string') {
|
|
166
|
+
screenText(step.args.command, acc);
|
|
167
|
+
screenArgv(step.args.command.trim().split(/\s+/), acc);
|
|
168
|
+
}
|
|
169
|
+
else if (!READ_ONLY_BUILTINS.has(step.tool))
|
|
170
|
+
note(acc, 'write', `fs_write:step-${step.tool}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Screen one tool exec. `scriptText` is the tier-3 implementation text for `kind: 'script'`
|
|
175
|
+
* (the caller reads it from the gene's `impl` evidence); without it a script is `high`,
|
|
176
|
+
* because code that cannot be read cannot be judged.
|
|
177
|
+
*/
|
|
178
|
+
export function screenToolExec(exec, scriptText) {
|
|
179
|
+
const acc = { write: false, network: false, high: false, unknown: false, reasons: [] };
|
|
180
|
+
let eligibleShape = false;
|
|
181
|
+
if (exec.kind === 'command') {
|
|
182
|
+
screenArgv(exec.argv, acc);
|
|
183
|
+
eligibleShape = true;
|
|
184
|
+
}
|
|
185
|
+
else if (exec.kind === 'script') {
|
|
186
|
+
if (scriptText === undefined || scriptText.length === 0)
|
|
187
|
+
note(acc, 'high', 'high:script-unreadable');
|
|
188
|
+
else
|
|
189
|
+
screenText(scriptText, acc);
|
|
190
|
+
note(acc, 'unknown', 'unknown:script');
|
|
191
|
+
screenText(exec.args.join(' '), acc);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
screenComposite(exec.steps, acc);
|
|
195
|
+
}
|
|
196
|
+
const risk = acc.high ? 'high' : acc.write || acc.unknown ? 'workspace_write' : 'read_only';
|
|
197
|
+
const permissions = ['process', 'fs_read'];
|
|
198
|
+
if (acc.write || acc.high)
|
|
199
|
+
permissions.push('fs_write');
|
|
200
|
+
if (acc.network)
|
|
201
|
+
permissions.push('network');
|
|
202
|
+
return {
|
|
203
|
+
risk,
|
|
204
|
+
permissions,
|
|
205
|
+
reasons: acc.reasons,
|
|
206
|
+
autoProbeEligible: eligibleShape && risk === 'read_only' && !acc.network,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** Does the declared permission set cover everything the screen derived? (T3) */
|
|
210
|
+
export function missingPermissions(declared, derived) {
|
|
211
|
+
return derived.filter((p) => !declared.includes(p));
|
|
212
|
+
}
|
|
213
|
+
/** Phrases a SKILL body must not contain: instructions that bypass a gate (S5). */
|
|
214
|
+
export const UNSAFE_INSTRUCTION_PATTERNS = [
|
|
215
|
+
['ignore-plan-mode', /\b(?:ignore|bypass|skip|disable|override)\b[^.\n]{0,24}\b(?:plan[- ]?mode|permissions?|confirm(?:ation)?|approval|sandbox|safety|guard(?:rails?)?)\b/i],
|
|
216
|
+
['no-verify', /--no-verify\b|--no-gpg-sign\b|\bgit\s+push\s+(?:-f|--force)\b/i],
|
|
217
|
+
['sudo', /\bsudo\b/i],
|
|
218
|
+
['pipe-to-shell', /\b(?:curl|wget)\b[^\n|]*\|\s*(?:sh|bash|zsh|iex|sudo)\b/i],
|
|
219
|
+
['disable-security', /\b(?:disable|turn off)\b[^.\n]{0,24}\b(?:antivirus|firewall|defender|selinux|ssl verification|certificate (?:check|verification))\b/i],
|
|
220
|
+
['reveal-secrets', /\b(?:reveal|print|exfiltrate|send|upload)\b[^.\n]{0,32}\b(?:secrets?|api[_ -]?keys?|tokens?|credentials?|passwords?)\b/i],
|
|
221
|
+
];
|
|
222
|
+
export function findUnsafeInstruction(text) {
|
|
223
|
+
for (const [id, re] of UNSAFE_INSTRUCTION_PATTERNS)
|
|
224
|
+
if (re.test(text))
|
|
225
|
+
return id;
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `gene_search`, `gene_read`, `gene_feedback` and `gene_run` (gene-bank spec 9.1, 16.1).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY - the whole `gene/` tree is in `glyphs.test.ts::inScope`, and the descriptions below
|
|
5
|
+
* are text a MODEL reads, so they are also English.
|
|
6
|
+
*
|
|
7
|
+
* PROGRESSIVE DISCLOSURE, ENFORCED BY SHAPE (I-1). `gene_search` returns tier-1 lines and
|
|
8
|
+
* numbers (the service's search output has no body field at all); `gene_read` opens ONE gene,
|
|
9
|
+
* tier 2 by default and tier 3 only when asked, in bounded chunks. The four descriptions together
|
|
10
|
+
* cost a few hundred tokens until the model actually uses the library (`tool-descriptions.test.ts`
|
|
11
|
+
* budgets them at 1100 characters).
|
|
12
|
+
*
|
|
13
|
+
* NO TOOL HERE EVER THROWS (I-24). Every body runs inside one guard: a closed gate answers in one
|
|
14
|
+
* line, a service failure answers `Gene library unavailable: <code>.`, and only genuine MISUSE (a
|
|
15
|
+
* missing id, an unknown verdict, arguments that break the gene's schema, a permission the caller
|
|
16
|
+
* lacks) is an `isError` result. A library problem must never fail a user turn.
|
|
17
|
+
*
|
|
18
|
+
* `gene_run` HOLDS NO APPROVAL LOGIC (I-15). It validates the arguments, compares the gene's
|
|
19
|
+
* permissions with what the caller can do RIGHT NOW, builds ONE command string with the argv
|
|
20
|
+
* quoted for the caller's shell, and hands it to `ports.runCommand`, which the host binds to the
|
|
21
|
+
* caller's REAL `bash` tool (`createToolAccess`). That is the whole trick: every gate `bash`
|
|
22
|
+
* already has - `--confirm`, the bridge approval, the permission mode, the skill ceiling, plan
|
|
23
|
+
* mode, a sub-agent's tool gate - applies to the command without this file knowing it exists, and
|
|
24
|
+
* a new gate added to `bash` tomorrow covers `gene_run` with no change here. A second copy of any
|
|
25
|
+
* of those checks would be a place for the two to drift apart.
|
|
26
|
+
*/
|
|
27
|
+
import { type AgentTool, type ToolExecutionContext, type ToolResult } from '@aragon-agent/core';
|
|
28
|
+
import type { GeneErrorCode, ToolPayload } from '@aragon-agent/tui/model/gene/types';
|
|
29
|
+
import type { GeneService } from './service.js';
|
|
30
|
+
import type { GeneActor } from './service-types.js';
|
|
31
|
+
import { type ShellKind } from './tool-runner.js';
|
|
32
|
+
/** The part of `GeneService` the tools use; a test double implements exactly these. */
|
|
33
|
+
export type GeneToolService = Pick<GeneService, 'gate' | 'search' | 'read' | 'feedback' | 'describeTool' | 'recordToolOutcome'>;
|
|
34
|
+
/** What `gene_run` hands the caller's `bash`. One object so the port stays within five parameters. */
|
|
35
|
+
export interface GeneRunRequest {
|
|
36
|
+
/** The `gene_run` call's own id: the live output card of the delegated command is keyed by it. */
|
|
37
|
+
toolCallId: string;
|
|
38
|
+
/** The finished, quoted command string. */
|
|
39
|
+
command: string;
|
|
40
|
+
/** The gene's own limit; `bash` may only SHRINK it within the executor ceiling. */
|
|
41
|
+
timeoutMs: number;
|
|
42
|
+
/** The `gene_run` call's context, so an Esc reaches the delegated command. */
|
|
43
|
+
ctx: ToolExecutionContext;
|
|
44
|
+
}
|
|
45
|
+
export interface GeneToolPorts {
|
|
46
|
+
service: GeneToolService;
|
|
47
|
+
/** Who is calling. Read PER CALL: the run id changes with every user turn. */
|
|
48
|
+
actor(): GeneActor;
|
|
49
|
+
/**
|
|
50
|
+
* Is `name` registered for this caller RIGHT NOW - after `--deny-tool`, a strict permission
|
|
51
|
+
* mode and a sub-agent's narrowing? Read per call, never cached. `createToolAccess` builds it.
|
|
52
|
+
*/
|
|
53
|
+
hasTool(name: string): boolean;
|
|
54
|
+
/** The shell the caller's `bash` tool uses, as a `ShellKind`; see `shellKindOfDescribed`. */
|
|
55
|
+
shellKind(): ShellKind;
|
|
56
|
+
/** Delegates to the caller's real `bash` tool. */
|
|
57
|
+
runCommand(request: GeneRunRequest): Promise<ToolResult>;
|
|
58
|
+
/** Register `gene_run` at all (the caller has `bash` and the library is on). */
|
|
59
|
+
includeRun: boolean;
|
|
60
|
+
/** Failure sink; the default writes a `warn` line holding the tool name and error text only. */
|
|
61
|
+
warn?(message: string, data?: Record<string, unknown>): void;
|
|
62
|
+
}
|
|
63
|
+
export interface GeneToolAccess {
|
|
64
|
+
hasTool(name: string): boolean;
|
|
65
|
+
runCommand(request: GeneRunRequest): Promise<ToolResult>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `hasTool` and `runCommand` over the caller's FINAL tool array.
|
|
69
|
+
*
|
|
70
|
+
* THE ARRAY MUST BE THE ONE AFTER EVERY WRAPPER AND NARROWING, read lazily through `getTools`:
|
|
71
|
+
* the `bash` found here is the confirmation-wrapped, bridge-gated, plan-gated, ceiling-gated
|
|
72
|
+
* (and, for a governed inspector, the RESTRICTED) tool the model itself would call. Resolving it
|
|
73
|
+
* eagerly would capture the array that exists before the wrappers are applied and give
|
|
74
|
+
* `gene_run` a back door around all of them.
|
|
75
|
+
*/
|
|
76
|
+
export declare function createToolAccess(getTools: () => readonly AgentTool[]): GeneToolAccess;
|
|
77
|
+
/**
|
|
78
|
+
* `gene_run` FOLLOWS `bash` (9.6): without a shell in the same array the tool could only ever be
|
|
79
|
+
* refused, and advertising it would burn a turn. Returns the SAME array (by identity) when there is
|
|
80
|
+
* nothing to remove, so a session that never had the library is provably untouched.
|
|
81
|
+
*/
|
|
82
|
+
export declare function withoutOrphanGeneRun(tools: AgentTool[]): AgentTool[];
|
|
83
|
+
/**
|
|
84
|
+
* `ShellKind` from the string `describeShell()` prints ('PowerShell', 'cmd.exe', '/bin/zsh') or
|
|
85
|
+
* from an `EnvFingerprint.shell` ('powershell', 'cmd', 'bash'). Feeding `describeShell()` straight
|
|
86
|
+
* to `shellKindOf` would classify 'PowerShell' (capital P) as POSIX and quote for the wrong shell.
|
|
87
|
+
*/
|
|
88
|
+
export declare function shellKindOfDescribed(shell: string): ShellKind;
|
|
89
|
+
/**
|
|
90
|
+
* The executor ceiling `gene_run` needs while a human may be answering the delegated command's
|
|
91
|
+
* approval. The executor arms its timer when `gene_run` starts, so the approval wait would be
|
|
92
|
+
* charged to the gene's command exactly as `gatedToolTimeouts` explains for `bash`. NOT added
|
|
93
|
+
* to `gatedToolTimeouts` itself: that map is pinned to `CALLER_GATED_TOOLS`, and adding
|
|
94
|
+
* `gene_run` there would make the bridge ask twice (once for it, once for the `bash` under it).
|
|
95
|
+
*/
|
|
96
|
+
export declare function geneRunTimeoutOverride(toolTimeoutMs: number, decisionBudgetMs: number): Record<string, number>;
|
|
97
|
+
type Params = Record<string, unknown>;
|
|
98
|
+
export declare function unavailableText(code: GeneErrorCode): string;
|
|
99
|
+
/**
|
|
100
|
+
* The permissions this gene needs that the caller cannot exercise right now. The union of what
|
|
101
|
+
* the gene DECLARES and what a fresh static screen of its argv DERIVES: a hand-edited gene file
|
|
102
|
+
* that under-declares `requiredPermissions` is held to what its command visibly does.
|
|
103
|
+
*/
|
|
104
|
+
export declare function missingGenePermissions(payload: ToolPayload, hasTool: (name: string) => boolean): string[];
|
|
105
|
+
/**
|
|
106
|
+
* Is a failed run plainly the arguments' doing? Usage and option errors, or a "no such file"
|
|
107
|
+
* that names one of the string arguments the model passed. Anything else counts against the gene.
|
|
108
|
+
*/
|
|
109
|
+
export declare function classifyToolFailure(text: string, args: Params): 'input' | 'tool';
|
|
110
|
+
/** The tools to register, in registration order. `gene_run` only when the caller has `bash`. */
|
|
111
|
+
export declare function createGeneTools(ports: GeneToolPorts): AgentTool[];
|
|
112
|
+
export {};
|