@octopi-agent/engine 0.86.38 → 0.97.15
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/dist/config-admin/agent-presets.d.ts +70 -0
- package/dist/config-admin/agent-presets.js +243 -0
- package/dist/config-admin/discover.d.ts +30 -0
- package/dist/config-admin/discover.js +48 -0
- package/dist/config-admin/env.d.ts +22 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/index.d.ts +20 -0
- package/dist/config-admin/index.js +15 -0
- package/dist/config-admin/model-presets.d.ts +75 -0
- package/dist/config-admin/model-presets.js +249 -0
- package/dist/config-admin/name-guard.d.ts +14 -0
- package/dist/config-admin/name-guard.js +24 -0
- package/dist/config-admin/patch.d.ts +56 -0
- package/dist/config-admin/patch.js +201 -0
- package/dist/config-admin/port.d.ts +68 -0
- package/dist/config-admin/port.js +21 -0
- package/dist/config-admin/redact.d.ts +39 -0
- package/dist/config-admin/redact.js +42 -0
- package/dist/config-schema/agent.d.ts +43 -1
- package/dist/config-schema/agent.js +12 -5
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +8 -0
- package/dist/config-schema/engine.d.ts +110 -8
- package/dist/config-schema/governance.d.ts +43 -1
- package/dist/config-schema/governance.js +160 -2
- package/dist/config-schema/models.d.ts +7 -4
- package/dist/config-schema/models.js +4 -1
- package/dist/config-schema/observability.d.ts +9 -0
- package/dist/config-schema/observability.js +29 -0
- package/dist/config-schema/run.d.ts +3 -0
- package/dist/config-schema/run.js +14 -0
- package/dist/config-schema/shared.d.ts +3 -0
- package/dist/config-schema/shared.js +12 -0
- package/dist/config-schema/substrate.d.ts +1 -1
- package/dist/config.d.ts +60 -13
- package/dist/config.js +81 -78
- package/dist/harness/activation/dispatcher.d.ts +8 -2
- package/dist/harness/activation/dispatcher.js +33 -5
- package/dist/harness/activation/inbox.d.ts +87 -0
- package/dist/harness/activation/inbox.js +169 -0
- package/dist/harness/activation/runtime.d.ts +9 -8
- package/dist/harness/activation/runtime.js +100 -8
- package/dist/harness/activation/types.d.ts +19 -0
- package/dist/harness/activation/types.js +2 -0
- package/dist/harness/agent/builder.d.ts +18 -3
- package/dist/harness/agent/builder.js +42 -17
- package/dist/harness/agent/config-bridge.d.ts +5 -0
- package/dist/harness/agent/config-bridge.js +7 -1
- package/dist/harness/agent/config-integrity.d.ts +72 -0
- package/dist/harness/agent/config-integrity.js +146 -0
- package/dist/harness/agent/tool-purpose.d.ts +9 -1
- package/dist/harness/agent/tool-purpose.js +11 -2
- package/dist/harness/agent/wire-agent-builder.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +3 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
- package/dist/harness/collaboration/delegation/child-run.js +21 -5
- package/dist/harness/collaboration/delegation/notifier.js +4 -3
- package/dist/harness/collaboration/delegation/service.js +2 -3
- package/dist/harness/collaboration/delegation/wiring.js +6 -5
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +1 -1
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +1 -1
- package/dist/harness/context/capabilities/compact/engine.d.ts +30 -0
- package/dist/harness/context/capabilities/compact/engine.js +198 -46
- package/dist/harness/context/capabilities/compact/handover.d.ts +78 -0
- package/dist/harness/context/capabilities/compact/handover.js +107 -0
- package/dist/harness/context/capabilities/compact/index.d.ts +3 -1
- package/dist/harness/context/capabilities/compact/index.js +2 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +30 -1
- package/dist/harness/context/capabilities/summary/executor.js +2 -1
- package/dist/harness/context/capabilities/summary/policies.js +8 -5
- package/dist/harness/context/constitution/default-agents.md +11 -10
- package/dist/harness/context/default-context-engine.d.ts +34 -4
- package/dist/harness/context/default-context-engine.js +198 -53
- package/dist/harness/context/hybrid-compressor.js +6 -0
- package/dist/harness/context/layer-types.d.ts +36 -0
- package/dist/harness/context/layer-types.js +38 -0
- package/dist/harness/context/llm-summarizer.d.ts +2 -8
- package/dist/harness/context/llm-summarizer.js +69 -91
- package/dist/harness/context/message-selector.js +4 -3
- package/dist/harness/context/root-instructions.js +1 -1
- package/dist/harness/context/summarize.d.ts +2 -0
- package/dist/harness/context/summarize.js +7 -2
- package/dist/harness/context/system-prompt-assembler.js +10 -4
- package/dist/harness/context/tool-result-aging.js +2 -2
- package/dist/harness/context/truncate-compressor.js +7 -0
- package/dist/harness/context/turn-envelope.d.ts +4 -3
- package/dist/harness/context/turn-envelope.js +4 -3
- package/dist/harness/context/types.d.ts +33 -1
- package/dist/harness/extension/execution-environment/dangerous-commands.d.ts +28 -0
- package/dist/harness/extension/execution-environment/dangerous-commands.js +129 -0
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +133 -4
- package/dist/harness/extension/execution-environment/effect-policy.js +263 -14
- package/dist/harness/extension/execution-environment/index.d.ts +4 -2
- package/dist/harness/extension/execution-environment/index.js +2 -1
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/kill-switch.d.ts +34 -0
- package/dist/harness/extension/execution-environment/kill-switch.js +46 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +200 -0
- package/dist/harness/extension/execution-environment/ops-audit.js +338 -0
- package/dist/harness/extension/execution-environment/privileged-exec.d.ts +158 -0
- package/dist/harness/extension/execution-environment/privileged-exec.js +418 -0
- package/dist/harness/extension/execution-environment/process-info.d.ts +180 -0
- package/dist/harness/extension/execution-environment/process-info.js +466 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +7 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +9 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +109 -0
- package/dist/harness/extension/execution-environment/sandbox.js +264 -29
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +1 -1
- package/dist/harness/extension/execution-environment/tool-capabilities.js +6 -0
- package/dist/harness/extension/execution-environment/types.d.ts +19 -0
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +50 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +4 -5
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +5 -15
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +53 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +10 -17
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +8 -8
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +9 -100
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.js +350 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.d.ts +30 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.js +137 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +54 -4
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +42 -16
- package/dist/harness/governance/security/temp-path.d.ts +9 -0
- package/dist/harness/governance/security/temp-path.js +13 -2
- package/dist/harness/governance/session-acl/seed-roles.js +14 -0
- package/dist/harness/index.d.ts +4 -0
- package/dist/harness/index.js +3 -0
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/fts.js +1 -2
- package/dist/harness/knowledge/grounding.js +5 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +180 -48
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +150 -150
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
- package/dist/harness/memory/sqlite/keyword-search.js +4 -3
- package/dist/harness/observability/observer/hub.js +38 -1
- package/dist/harness/observability/observer/run-snapshot.js +1 -0
- package/dist/harness/observability/observer/types.d.ts +27 -0
- package/dist/harness/run/agent/agent.d.ts +7 -0
- package/dist/harness/run/agent/agent.js +23 -1
- package/dist/harness/run/reliability/fallback-provider.d.ts +117 -5
- package/dist/harness/run/reliability/fallback-provider.js +262 -22
- package/dist/harness/run/reliability/harness-events.d.ts +24 -1
- package/dist/harness/run/reliability/model-error-policy.d.ts +32 -0
- package/dist/harness/run/reliability/model-error-policy.js +42 -0
- package/dist/harness/run/reliability/provider-wrapper.js +29 -2
- package/dist/harness/run/reliability/refusal-guard.d.ts +20 -0
- package/dist/harness/run/reliability/refusal-guard.js +102 -0
- package/dist/harness/run/reliability/run-agent.js +231 -33
- package/dist/harness/run/run-guard/default-run-guard.js +1 -1
- package/dist/harness/run/run-scope.d.ts +31 -0
- package/dist/harness/run/runner.d.ts +132 -2
- package/dist/harness/run/runner.js +679 -60
- package/dist/harness/session/attachments/llm-intent.js +2 -1
- package/dist/harness/session/history/port.js +15 -5
- package/dist/harness/session/in-memory-store.d.ts +5 -0
- package/dist/harness/session/in-memory-store.js +33 -2
- package/dist/harness/session/tasks/render.d.ts +4 -1
- package/dist/harness/session/tasks/render.js +10 -7
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/shared/events/agent-event-map.d.ts +92 -0
- package/dist/harness/shared/events/agent-event-map.js +7 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -3
- package/dist/integration/agent-runtime/channel-message-source.js +19 -1
- package/dist/integration/index.d.ts +2 -0
- package/dist/integration/index.js +1 -0
- package/dist/integration/observability/loop-watchdog.d.ts +56 -0
- package/dist/integration/observability/loop-watchdog.js +177 -0
- package/dist/integration/observability/metrics.d.ts +3 -0
- package/dist/integration/observability/metrics.js +18 -7
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +23 -0
- package/dist/integration/providers/anthropic.js +97 -12
- package/dist/integration/providers/fetch-timeout.d.ts +42 -0
- package/dist/integration/providers/fetch-timeout.js +51 -0
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -11
- package/dist/integration/providers/provider-diagnostics.d.ts +80 -0
- package/dist/integration/providers/provider-diagnostics.js +89 -0
- package/dist/integration/providers/timeout-coherence.d.ts +52 -0
- package/dist/integration/providers/timeout-coherence.js +68 -0
- package/dist/integration/providers/wire-dump.d.ts +62 -0
- package/dist/integration/providers/wire-dump.js +111 -2
- package/dist/integration/storage/jsonl.d.ts +19 -1
- package/dist/integration/storage/jsonl.js +100 -4
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +1 -1
- package/dist/subsystems/memory-steward/backfill/handler.js +1 -1
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/formation/handler.js +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { runGit } from './git-runner.js';
|
|
2
|
+
const DEFAULT_MAX_ENTRIES = 500;
|
|
3
|
+
const EMPTY_COUNTS = () => ({
|
|
4
|
+
conflicted: 0,
|
|
5
|
+
staged: 0,
|
|
6
|
+
unstaged: 0,
|
|
7
|
+
untracked: 0,
|
|
8
|
+
});
|
|
9
|
+
/** Group render order: conflicts first, then staged, unstaged, untracked. */
|
|
10
|
+
const GROUP_RANK = {
|
|
11
|
+
conflicted: 0,
|
|
12
|
+
staged: 1,
|
|
13
|
+
unstaged: 2,
|
|
14
|
+
untracked: 3,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Parse `git status --porcelain=v2 -z [--branch]` output.
|
|
18
|
+
*
|
|
19
|
+
* Record grammar (NUL-separated): `# key value` headers; `1 XY sub mH mI mW hH
|
|
20
|
+
* hI path`; `2 XY sub mH mI mW hH hI Xscore path` + separate origPath field;
|
|
21
|
+
* `u XY sub m1 m2 m3 mW h1 h2 h3 path`; `? path`; `! path` (skipped — we never
|
|
22
|
+
* pass --ignored). Paths are raw bytes decoded as UTF-8; no quoting in -z mode.
|
|
23
|
+
*
|
|
24
|
+
* @param raw - NUL-separated porcelain v2 stream
|
|
25
|
+
* @param options - maxEntries / untracked granularity (untracked only affects readers)
|
|
26
|
+
* @returns branch block (null without headers), full counts, capped entries,
|
|
27
|
+
* skippedRecords for known-type records that failed to parse
|
|
28
|
+
*/
|
|
29
|
+
export function parsePorcelainV2(raw, options) {
|
|
30
|
+
const maxEntries = Math.max(1, options?.maxEntries ?? DEFAULT_MAX_ENTRIES);
|
|
31
|
+
const branch = {
|
|
32
|
+
oid: null,
|
|
33
|
+
head: null,
|
|
34
|
+
detached: false,
|
|
35
|
+
initial: false,
|
|
36
|
+
upstream: null,
|
|
37
|
+
ahead: null,
|
|
38
|
+
behind: null,
|
|
39
|
+
};
|
|
40
|
+
let sawBranchHeader = false;
|
|
41
|
+
let skippedRecords = 0;
|
|
42
|
+
const rows = [];
|
|
43
|
+
const counts = EMPTY_COUNTS();
|
|
44
|
+
const pushRow = (entry, idx) => {
|
|
45
|
+
counts[entry.group] += 1;
|
|
46
|
+
rows.push({ entry, idx });
|
|
47
|
+
};
|
|
48
|
+
const tokens = raw.split('\0');
|
|
49
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
50
|
+
const tok = tokens[i];
|
|
51
|
+
if (!tok)
|
|
52
|
+
continue;
|
|
53
|
+
if (tok.startsWith('# ')) {
|
|
54
|
+
sawBranchHeader = true;
|
|
55
|
+
const rest = tok.slice(2);
|
|
56
|
+
if (rest.startsWith('branch.oid ')) {
|
|
57
|
+
const v = rest.slice('branch.oid '.length);
|
|
58
|
+
branch.initial = v === '(initial)';
|
|
59
|
+
branch.oid = branch.initial ? null : v;
|
|
60
|
+
}
|
|
61
|
+
else if (rest.startsWith('branch.head ')) {
|
|
62
|
+
const v = rest.slice('branch.head '.length);
|
|
63
|
+
branch.detached = v === '(detached)';
|
|
64
|
+
branch.head = branch.detached ? null : v;
|
|
65
|
+
}
|
|
66
|
+
else if (rest.startsWith('branch.upstream ')) {
|
|
67
|
+
branch.upstream = rest.slice('branch.upstream '.length);
|
|
68
|
+
}
|
|
69
|
+
else if (rest.startsWith('branch.ab ')) {
|
|
70
|
+
const m = /^\+(-?\d+) -(-?\d+)$/.exec(rest.slice('branch.ab '.length));
|
|
71
|
+
if (m) {
|
|
72
|
+
branch.ahead = Number(m[1]);
|
|
73
|
+
branch.behind = Number(m[2]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const kindCh = tok[0];
|
|
79
|
+
if (kindCh === '1') {
|
|
80
|
+
const m = /^1 (\S)(\S) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) ([\s\S]*)$/.exec(tok);
|
|
81
|
+
if (!m) {
|
|
82
|
+
skippedRecords += 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const base = { kind: 'changed', x: m[1], y: m[2], path: m[9] };
|
|
86
|
+
if (base.x !== '.')
|
|
87
|
+
pushRow({ ...base, group: 'staged' }, i);
|
|
88
|
+
if (base.y !== '.' || base.x === '.')
|
|
89
|
+
pushRow({ ...base, group: 'unstaged' }, i);
|
|
90
|
+
}
|
|
91
|
+
else if (kindCh === '2') {
|
|
92
|
+
const m = /^2 (\S)(\S) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) ([A-Z][0-9]*) ([\s\S]*)$/.exec(tok);
|
|
93
|
+
if (!m) {
|
|
94
|
+
skippedRecords += 1;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const origPath = tokens[i + 1] ?? '';
|
|
98
|
+
if (origPath)
|
|
99
|
+
i += 1;
|
|
100
|
+
const base = {
|
|
101
|
+
kind: (m[9].startsWith('R') ? 'renamed' : 'copied'),
|
|
102
|
+
x: m[1],
|
|
103
|
+
y: m[2],
|
|
104
|
+
path: m[10],
|
|
105
|
+
...(origPath ? { origPath } : {}),
|
|
106
|
+
};
|
|
107
|
+
if (base.x !== '.')
|
|
108
|
+
pushRow({ ...base, group: 'staged' }, i);
|
|
109
|
+
if (base.y !== '.' || base.x === '.')
|
|
110
|
+
pushRow({ ...base, group: 'unstaged' }, i);
|
|
111
|
+
}
|
|
112
|
+
else if (kindCh === 'u') {
|
|
113
|
+
// u <XY> <sub> <m1> <m2> <m3> <mW> <h1> <h2> <h3> <path> — sub + 7 modes/hashes
|
|
114
|
+
const m = /^u (\S)(\S) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) ([\s\S]*)$/.exec(tok);
|
|
115
|
+
if (!m) {
|
|
116
|
+
skippedRecords += 1;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
pushRow({ kind: 'conflicted', group: 'conflicted', x: m[1], y: m[2], path: m[11] }, i);
|
|
120
|
+
}
|
|
121
|
+
else if (kindCh === '?') {
|
|
122
|
+
pushRow({ kind: 'untracked', group: 'untracked', x: '?', y: '?', path: tok.slice(2) }, i);
|
|
123
|
+
}
|
|
124
|
+
else if (kindCh !== '!') {
|
|
125
|
+
// Unknown record type: count it so format drift never looks like "clean".
|
|
126
|
+
skippedRecords += 1;
|
|
127
|
+
}
|
|
128
|
+
// '!' (ignored) records are skipped by design: readers never pass --ignored.
|
|
129
|
+
}
|
|
130
|
+
// Stable group order (conflicted → staged → unstaged → untracked); git's own
|
|
131
|
+
// path order is preserved inside a group.
|
|
132
|
+
const sorted = rows
|
|
133
|
+
.sort((a, b) => GROUP_RANK[a.entry.group] - GROUP_RANK[b.entry.group] || a.idx - b.idx)
|
|
134
|
+
.map((s) => s.entry);
|
|
135
|
+
return {
|
|
136
|
+
branch: sawBranchHeader ? branch : null,
|
|
137
|
+
counts,
|
|
138
|
+
entries: sorted.slice(0, maxEntries),
|
|
139
|
+
truncated: sorted.length > maxEntries,
|
|
140
|
+
skippedRecords,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Read a structured git status snapshot for `cwd`.
|
|
145
|
+
*
|
|
146
|
+
* @param cwd - repository (or subdirectory) path; caller has contained it
|
|
147
|
+
* @param options - maxEntries / untracked granularity
|
|
148
|
+
* @returns isRepo=false when cwd is not inside a git work tree (a state, not an
|
|
149
|
+
* error); throws `git_status_failed: …` on real git failures, on
|
|
150
|
+
* output-cap kills (never partial-as-success), and `git_not_found: …`
|
|
151
|
+
* when git is not on PATH
|
|
152
|
+
*/
|
|
153
|
+
export async function readGitStatusSnapshot(cwd, options) {
|
|
154
|
+
const untracked = options?.untracked ?? 'normal';
|
|
155
|
+
// 最小上下文:只带 jail 诉求与 jail 根(快照本就 context-free——journal=false、
|
|
156
|
+
// 网络默认 deny)。pathRoots 决定 jail 内可见根(allowRoots = [cwd, ...pathRoots])。
|
|
157
|
+
const context = options?.requireJail || options?.jailRoots?.length
|
|
158
|
+
? {
|
|
159
|
+
...(options?.requireJail ? { requireJail: true } : {}),
|
|
160
|
+
...(options?.jailRoots?.length ? { pathRoots: options.jailRoots } : {}),
|
|
161
|
+
}
|
|
162
|
+
: undefined;
|
|
163
|
+
const top = await runGit(context, cwd, ['rev-parse', '--show-toplevel'], {
|
|
164
|
+
journal: false,
|
|
165
|
+
applyOutputGate: false,
|
|
166
|
+
timeoutMs: 15_000,
|
|
167
|
+
});
|
|
168
|
+
if (top.exitCode !== 0) {
|
|
169
|
+
if (/not a git repository/i.test(top.stderr)) {
|
|
170
|
+
return {
|
|
171
|
+
isRepo: false,
|
|
172
|
+
repoRoot: null,
|
|
173
|
+
branch: null,
|
|
174
|
+
counts: EMPTY_COUNTS(),
|
|
175
|
+
entries: [],
|
|
176
|
+
truncated: false,
|
|
177
|
+
skippedRecords: 0,
|
|
178
|
+
generatedAt: new Date().toISOString(),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
throw new Error(`git_status_failed: ${top.stderr.trim().slice(0, 200) || `rev-parse exited ${top.exitCode}`}`);
|
|
182
|
+
}
|
|
183
|
+
const st = await runGit(context, cwd, ['status', '--porcelain=v2', '-z', '--branch', `--untracked-files=${untracked}`], { journal: false, applyOutputGate: false, timeoutMs: 30_000 });
|
|
184
|
+
// A killed/truncated stream would parse as a partial record set — surface it
|
|
185
|
+
// as a failure instead of a plausible-looking clean/partial status.
|
|
186
|
+
if (st.exitCode !== 0 || st.truncated || st.terminated) {
|
|
187
|
+
throw new Error(`git_status_failed: ${st.terminateReason ??
|
|
188
|
+
st.stderr.trim().slice(0, 200) ??
|
|
189
|
+
`status exited ${st.exitCode}`}`);
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
isRepo: true,
|
|
193
|
+
repoRoot: top.stdout.trim(),
|
|
194
|
+
...parsePorcelainV2(st.stdout, options),
|
|
195
|
+
generatedAt: new Date().toISOString(),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* git_* dedicated tools
|
|
2
|
+
* git_* dedicated tools — local VCS porcelain without a shell.
|
|
3
3
|
*
|
|
4
4
|
* Spawn `git` with a fixed argv allowlist (never a command string). Isolation:
|
|
5
5
|
* nonexistent `core.hooksPath`, `--no-verify`/`--no-gpg-sign` on commit,
|
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
* workspace/untrusted agents can still status/diff/commit without `shell`.
|
|
10
10
|
*/
|
|
11
11
|
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
12
|
-
/** git_status
|
|
12
|
+
/** git_status — porcelain working tree status */
|
|
13
13
|
export declare function createGitStatusTool(): RegisteredTool;
|
|
14
|
-
/** git_diff
|
|
14
|
+
/** git_diff — unstaged / staged / vs-ref diff */
|
|
15
15
|
export declare function createGitDiffTool(): RegisteredTool;
|
|
16
|
-
/** git_log
|
|
16
|
+
/** git_log — commit history */
|
|
17
17
|
export declare function createGitLogTool(): RegisteredTool;
|
|
18
|
-
/** git_show
|
|
18
|
+
/** git_show — show a commit / tree / blob */
|
|
19
19
|
export declare function createGitShowTool(): RegisteredTool;
|
|
20
|
-
/** git_commit
|
|
20
|
+
/** git_commit — add paths + commit (hooks disabled) */
|
|
21
21
|
export declare function createGitCommitTool(): RegisteredTool;
|
|
22
|
-
/** git_branch
|
|
22
|
+
/** git_branch — list / create / switch / delete */
|
|
23
23
|
export declare function createGitBranchTool(): RegisteredTool;
|
|
24
|
-
/** git_restore
|
|
24
|
+
/** git_restore — restore working tree / index paths */
|
|
25
25
|
export declare function createGitRestoreTool(): RegisteredTool;
|
|
26
26
|
/** All git_* tools (read + write). */
|
|
27
27
|
export declare function createGitTools(): RegisteredTool[];
|
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { gateEffect } from '../../execution-environment/effect-policy.js';
|
|
2
|
-
import { tmpdir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
2
|
import { resolveToolPath, isUnderAttachmentRoot, isUnderSessionUndoRoot } from './platform.js';
|
|
5
3
|
import { detectEol, toEol } from './eol.js';
|
|
6
|
-
import { assertSafeRef
|
|
7
|
-
|
|
8
|
-
* Nonexistent hooks dir (empty core.hooksPath is version-fragile: some gits
|
|
9
|
-
* treat it as `./` and still run cwd hooks).
|
|
10
|
-
*/
|
|
11
|
-
function noHooksDir() {
|
|
12
|
-
return join(tmpdir(), 'octopi-nohooks');
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Fixed git safety prefix. Command-line `-c` outranks local `.git/config`, so
|
|
16
|
-
* these neutralize repo-config RCE vectors (diff.external, gpg.program, …).
|
|
17
|
-
* `--no-optional-locks` avoids index lock fights. Never pass user `-c`.
|
|
18
|
-
*/
|
|
19
|
-
function gitSafePrefix() {
|
|
20
|
-
const hooks = noHooksDir();
|
|
21
|
-
return [
|
|
22
|
-
'--no-optional-locks',
|
|
23
|
-
'-c', `core.hooksPath=${hooks}`,
|
|
24
|
-
'-c', 'core.fsmonitor=',
|
|
25
|
-
'-c', 'core.pager=cat',
|
|
26
|
-
'-c', 'diff.external=',
|
|
27
|
-
'-c', 'diff.tool=',
|
|
28
|
-
'-c', 'merge.tool=',
|
|
29
|
-
'-c', 'merge.prompt=false',
|
|
30
|
-
'-c', 'gpg.program=true',
|
|
31
|
-
'-c', 'commit.gpgsign=false',
|
|
32
|
-
'-c', 'core.sshCommand=',
|
|
33
|
-
'-c', 'core.askpass=',
|
|
34
|
-
'-c', 'credential.helper=',
|
|
35
|
-
'-c', 'core.attributesFile=',
|
|
36
|
-
'-c', 'core.excludesFile=',
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Isolate global/system gitconfig. Local `.git/config` is still read; dangerous
|
|
41
|
-
* keys there are overridden by the `-c` prefix above (command line wins).
|
|
42
|
-
* On Windows use `NUL`, elsewhere `/dev/null` — a missing file is also fine.
|
|
43
|
-
*/
|
|
44
|
-
function gitIsolationEnv() {
|
|
45
|
-
const nullPath = process.platform === 'win32' ? 'NUL' : '/dev/null';
|
|
46
|
-
return {
|
|
47
|
-
GIT_CONFIG_NOSYSTEM: '1',
|
|
48
|
-
GIT_CONFIG_SYSTEM: nullPath,
|
|
49
|
-
GIT_CONFIG_GLOBAL: nullPath,
|
|
50
|
-
GIT_TERMINAL_PROMPT: '0',
|
|
51
|
-
GIT_OPTIONAL_LOCKS: '0',
|
|
52
|
-
GIT_ASKPASS: '',
|
|
53
|
-
SSH_ASKPASS: '',
|
|
54
|
-
};
|
|
55
|
-
}
|
|
4
|
+
import { assertSafeRef } from './allowlisted-run.js';
|
|
5
|
+
import { runGit } from './git-runner.js';
|
|
56
6
|
function resolveCwd(context, raw) {
|
|
57
7
|
const cwd = raw ?? context?.cwd ?? process.cwd();
|
|
58
8
|
const abs = resolveToolPath(cwd, context?.cwd, {
|
|
@@ -106,47 +56,6 @@ function toGitPathspec(raw, context, label) {
|
|
|
106
56
|
}
|
|
107
57
|
return raw;
|
|
108
58
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Discover filter.* drivers from repo/user config and pin them to `cat`.
|
|
111
|
-
* Command-line `-c` outranks local `.git/config`, so a malicious
|
|
112
|
-
* .gitattributes cannot run clean/smudge/process during `git add`.
|
|
113
|
-
*/
|
|
114
|
-
async function filterNeutralizers(context, cwd) {
|
|
115
|
-
const git = requireExecutable('git');
|
|
116
|
-
const res = await runAllowlistedArgv({
|
|
117
|
-
executable: git,
|
|
118
|
-
args: [...gitSafePrefix(), 'config', '--name-only', '--get-regexp', '^filter\\.'],
|
|
119
|
-
cwd,
|
|
120
|
-
context,
|
|
121
|
-
env: gitIsolationEnv(),
|
|
122
|
-
journal: false,
|
|
123
|
-
});
|
|
124
|
-
if (res.exitCode !== 0)
|
|
125
|
-
return [];
|
|
126
|
-
const names = new Set();
|
|
127
|
-
for (const line of res.stdout.split(/\r?\n/)) {
|
|
128
|
-
const m = /^filter\.(.+)\.(clean|smudge|process)$/.exec(line.trim());
|
|
129
|
-
if (m && /^[A-Za-z0-9._-]+$/.test(m[1]))
|
|
130
|
-
names.add(m[1]);
|
|
131
|
-
}
|
|
132
|
-
const out = [];
|
|
133
|
-
for (const n of names) {
|
|
134
|
-
out.push('-c', `filter.${n}.clean=cat`, '-c', `filter.${n}.smudge=cat`, '-c', `filter.${n}.process=cat`);
|
|
135
|
-
}
|
|
136
|
-
return out;
|
|
137
|
-
}
|
|
138
|
-
async function runGit(context, cwd, args, options) {
|
|
139
|
-
const git = requireExecutable('git');
|
|
140
|
-
return runAllowlistedArgv({
|
|
141
|
-
executable: git,
|
|
142
|
-
args: [...gitSafePrefix(), ...(await filterNeutralizers(context, cwd)), ...args],
|
|
143
|
-
cwd,
|
|
144
|
-
context,
|
|
145
|
-
env: gitIsolationEnv(),
|
|
146
|
-
timeoutMs: options?.timeoutMs ?? 60_000,
|
|
147
|
-
journal: options?.journal ?? false,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
59
|
function toText(result) {
|
|
151
60
|
return {
|
|
152
61
|
stdout: result.stdout,
|
|
@@ -159,7 +68,7 @@ function toText(result) {
|
|
|
159
68
|
isolation: result.isolation,
|
|
160
69
|
};
|
|
161
70
|
}
|
|
162
|
-
/** git_status
|
|
71
|
+
/** git_status — porcelain working tree status */
|
|
163
72
|
export function createGitStatusTool() {
|
|
164
73
|
return {
|
|
165
74
|
definition: {
|
|
@@ -190,7 +99,7 @@ export function createGitStatusTool() {
|
|
|
190
99
|
},
|
|
191
100
|
};
|
|
192
101
|
}
|
|
193
|
-
/** git_diff
|
|
102
|
+
/** git_diff — unstaged / staged / vs-ref diff */
|
|
194
103
|
export function createGitDiffTool() {
|
|
195
104
|
return {
|
|
196
105
|
definition: {
|
|
@@ -242,7 +151,7 @@ export function createGitDiffTool() {
|
|
|
242
151
|
},
|
|
243
152
|
};
|
|
244
153
|
}
|
|
245
|
-
/** git_log
|
|
154
|
+
/** git_log — commit history */
|
|
246
155
|
export function createGitLogTool() {
|
|
247
156
|
return {
|
|
248
157
|
definition: {
|
|
@@ -285,7 +194,7 @@ export function createGitLogTool() {
|
|
|
285
194
|
},
|
|
286
195
|
};
|
|
287
196
|
}
|
|
288
|
-
/** git_show
|
|
197
|
+
/** git_show — show a commit / tree / blob */
|
|
289
198
|
export function createGitShowTool() {
|
|
290
199
|
return {
|
|
291
200
|
definition: {
|
|
@@ -310,7 +219,7 @@ export function createGitShowTool() {
|
|
|
310
219
|
},
|
|
311
220
|
};
|
|
312
221
|
}
|
|
313
|
-
/** git_commit
|
|
222
|
+
/** git_commit — add paths + commit (hooks disabled) */
|
|
314
223
|
export function createGitCommitTool() {
|
|
315
224
|
return {
|
|
316
225
|
definition: {
|
|
@@ -415,7 +324,7 @@ export function createGitCommitTool() {
|
|
|
415
324
|
},
|
|
416
325
|
};
|
|
417
326
|
}
|
|
418
|
-
/** git_branch
|
|
327
|
+
/** git_branch — list / create / switch / delete */
|
|
419
328
|
export function createGitBranchTool() {
|
|
420
329
|
return {
|
|
421
330
|
definition: {
|
|
@@ -482,7 +391,7 @@ export function createGitBranchTool() {
|
|
|
482
391
|
},
|
|
483
392
|
};
|
|
484
393
|
}
|
|
485
|
-
/** git_restore
|
|
394
|
+
/** git_restore — restore working tree / index paths */
|
|
486
395
|
export function createGitRestoreTool() {
|
|
487
396
|
return {
|
|
488
397
|
definition: {
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export { getBuiltinTools } from './builtin.js';
|
|
2
2
|
export { createGitTools } from './git-tools.js';
|
|
3
|
+
export { runGit } from './git-runner.js';
|
|
4
|
+
export type { RunGitOptions } from './git-runner.js';
|
|
5
|
+
export { readGitStatusSnapshot, parsePorcelainV2 } from './git-status-snapshot.js';
|
|
6
|
+
export type { GitStatusSnapshot, GitStatusSnapshotBody, GitStatusSnapshotOptions, GitStatusEntry, GitStatusBranch, GitStatusCounts, GitStatusGroup, GitStatusKind, } from './git-status-snapshot.js';
|
|
3
7
|
export { createPackageTools } from './package-tools.js';
|
|
4
8
|
export { createDocumentReadTool, createDocumentProbeTool } from './document-tools.js';
|
|
5
9
|
export { createFileEditTool } from './file-edit.js';
|
|
6
10
|
export { createFileSearchTool } from './file-search.js';
|
|
7
11
|
export { createHttpRequestTool } from './http.js';
|
|
8
12
|
export { createEnvInfoTool } from './env-info.js';
|
|
13
|
+
export { createProcessListTool } from './process-tools.js';
|
|
14
|
+
export { createPrivExecTool } from './privileged-tool.js';
|
|
9
15
|
export { commandExists, defaultPathEnv, findExecutable, resetPlatformShellCache, resolvePlatformShell, resolveToolPath, type PlatformShell, type ShellKind, } from './platform.js';
|
|
10
16
|
export { createToolSet } from './tool-set.js';
|
|
11
17
|
export type { ToolSet, ToolSetConfig } from './tool-set.js';
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export { getBuiltinTools } from './builtin.js';
|
|
2
2
|
export { createGitTools } from './git-tools.js';
|
|
3
|
+
export { runGit } from './git-runner.js';
|
|
4
|
+
export { readGitStatusSnapshot, parsePorcelainV2 } from './git-status-snapshot.js';
|
|
3
5
|
export { createPackageTools } from './package-tools.js';
|
|
4
6
|
export { createDocumentReadTool, createDocumentProbeTool } from './document-tools.js';
|
|
5
7
|
export { createFileEditTool } from './file-edit.js';
|
|
6
8
|
export { createFileSearchTool } from './file-search.js';
|
|
7
9
|
export { createHttpRequestTool } from './http.js';
|
|
8
10
|
export { createEnvInfoTool } from './env-info.js';
|
|
11
|
+
export { createProcessListTool } from './process-tools.js';
|
|
12
|
+
export { createPrivExecTool } from './privileged-tool.js';
|
|
9
13
|
export { commandExists, defaultPathEnv, findExecutable, resetPlatformShellCache, resolvePlatformShell, resolveToolPath, } from './platform.js';
|
|
10
14
|
export { createToolSet } from './tool-set.js';
|
|
11
15
|
export { createAskUserTool } from './ask-user.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* priv_exec 工具 — 白名单提权执行(ops P3,§5 P3 / §8)
|
|
3
|
+
*
|
|
4
|
+
* 独立 privileged 通道:引擎侧 execFile 执行完整 argv,不经 shell、不包 jail、
|
|
5
|
+
* env 消毒、**cwd 钉住**(规则显式或 `/`,绝不取 agent 的 cwd)、超时真树杀。
|
|
6
|
+
* shell 工具保持原牢笼语义不动(原则 6:提权不与牢笼抢轴)。
|
|
7
|
+
*
|
|
8
|
+
* 安全闸门(全 fail-closed):
|
|
9
|
+
* 1. **匹配面**(effect-policy `matchEscalationRule`):`allowlist` 档 cmd 绝对路径 +
|
|
10
|
+
* args 逐项全等;`full` 档(P4,需 privilegedAck + jail=none + mode=host)无
|
|
11
|
+
* allowlist 面,但 `via: sudo` 仍必须显式 `sudo -n` 形态(裸跑 = 非特权通道假象)。
|
|
12
|
+
* 未命中/形态非法 → 拒绝 + `ops.escalation.denied` 留痕(不留痕的拒绝等于没拒)。
|
|
13
|
+
* 2. **确认闸门**:规则 `confirm: true`(allowlist)或 §6 危险分类命中(full 档)走
|
|
14
|
+
* HitlDecision 单模型(§8.2),缓存 key 含**完整 argv 全等**(§5 P3:防一次批准
|
|
15
|
+
* 放行整类);特权通道把 `approve_always` 降格为 `approve_session`。
|
|
16
|
+
* **确认超时一律 deny**(T1 硬约束,outcome 不可配)。
|
|
17
|
+
* 3. **请求者授权**(§8.6 拍板):由 SEC-2 `toolRights.deny('priv_exec')` 表达——
|
|
18
|
+
* 缺权参与者在 toolRights 层即拒,连确认闸都到不了。
|
|
19
|
+
* 4. **审计**(§7):`ops.escalation.requested` → `ops.privileged.exec` / `denied`。
|
|
20
|
+
*
|
|
21
|
+
* `full` 档的 §6 分类是**减速带不是安全边界**(只拦事故不拦攻击):未命中自动放行,
|
|
22
|
+
* 不做「未知即危险」;真正的边界是 privilegedAck + 常驻 PRIVILEGED 标记 + 审计。
|
|
23
|
+
*/
|
|
24
|
+
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
25
|
+
import { type HitlDecisionCache } from '../../../governance/human-in-the-loop/decision-cache.js';
|
|
26
|
+
/** 创建选项 */
|
|
27
|
+
export interface CreatePrivExecToolOptions {
|
|
28
|
+
/** HITL 决策缓存(缺省全局 defaultHitlCache;测试/宿主可注入独立实例) */
|
|
29
|
+
cache?: HitlDecisionCache;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 创建 priv_exec 工具
|
|
33
|
+
*
|
|
34
|
+
* 参数:
|
|
35
|
+
* - cmd (string, required):可执行文件**绝对路径**(与规则逐字相同)
|
|
36
|
+
* - args (string[], optional):argv 尾部(与规则逐项全等)
|
|
37
|
+
*
|
|
38
|
+
* 返回:ruleId / exitCode / stdout / stderr / durationMs / confirmDecision。
|
|
39
|
+
*
|
|
40
|
+
* @param options - 可注入 HITL 缓存
|
|
41
|
+
* @returns 注册好的提权工具
|
|
42
|
+
*/
|
|
43
|
+
export declare function createPrivExecTool(options?: CreatePrivExecToolOptions): RegisteredTool;
|