agent-steward 0.0.3 → 0.0.5
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 +154 -2
- package/CROSS_PLATFORM.md +19 -0
- package/README.md +54 -9
- package/ROADMAP-STRATEGY.md +23 -20
- package/ROADMAP.md +140 -143
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +351 -0
- package/dist/core/dlq-api.d.ts +44 -0
- package/dist/core/dlq-api.d.ts.map +1 -0
- package/dist/core/dlq-api.js +68 -0
- package/dist/core/dry-run.d.ts.map +1 -1
- package/dist/core/dry-run.js +18 -1
- package/dist/core/execution.d.ts +203 -0
- package/dist/core/execution.d.ts.map +1 -0
- package/dist/core/execution.js +309 -0
- package/dist/core/gate-integrity.d.ts +35 -0
- package/dist/core/gate-integrity.d.ts.map +1 -0
- package/dist/core/gate-integrity.js +132 -0
- package/dist/core/git-trigger.d.ts.map +1 -1
- package/dist/core/git-trigger.js +14 -2
- package/dist/core/guard-run.d.ts +4 -0
- package/dist/core/guard-run.d.ts.map +1 -0
- package/dist/core/guard-run.js +101 -0
- package/dist/core/guard.d.ts +52 -0
- package/dist/core/guard.d.ts.map +1 -0
- package/dist/core/guard.js +362 -0
- package/dist/core/lock.d.ts +61 -4
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +213 -26
- package/dist/core/matrix.d.ts.map +1 -1
- package/dist/core/matrix.js +75 -15
- package/dist/core/mission.d.ts +83 -0
- package/dist/core/mission.d.ts.map +1 -0
- package/dist/core/mission.js +334 -0
- package/dist/core/one-shot.d.ts +5 -1
- package/dist/core/one-shot.d.ts.map +1 -1
- package/dist/core/one-shot.js +33 -8
- package/dist/core/opencode-cli.d.ts +28 -0
- package/dist/core/opencode-cli.d.ts.map +1 -0
- package/dist/core/opencode-cli.js +74 -0
- package/dist/core/opencode-models.d.ts +62 -0
- package/dist/core/opencode-models.d.ts.map +1 -0
- package/dist/core/opencode-models.js +277 -0
- package/dist/core/pipeline-apply.d.ts +38 -0
- package/dist/core/pipeline-apply.d.ts.map +1 -0
- package/dist/core/pipeline-apply.js +117 -0
- package/dist/core/pipeline-io.d.ts +13 -0
- package/dist/core/pipeline-io.d.ts.map +1 -0
- package/dist/core/pipeline-io.js +64 -0
- package/dist/core/pipeline-map.d.ts +46 -0
- package/dist/core/pipeline-map.d.ts.map +1 -0
- package/dist/core/pipeline-map.js +196 -0
- package/dist/core/pipeline-spec.d.ts +109 -0
- package/dist/core/pipeline-spec.d.ts.map +1 -0
- package/dist/core/pipeline-spec.js +554 -0
- package/dist/core/ps-wrapper.d.ts +19 -2
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +261 -63
- package/dist/core/record-history.d.ts +15 -0
- package/dist/core/record-history.d.ts.map +1 -1
- package/dist/core/record-history.js +183 -58
- package/dist/core/router/dispatch.d.ts +36 -0
- package/dist/core/router/dispatch.d.ts.map +1 -0
- package/dist/core/router/dispatch.js +59 -0
- package/dist/core/router/escalation.d.ts +47 -0
- package/dist/core/router/escalation.d.ts.map +1 -0
- package/dist/core/router/escalation.js +87 -0
- package/dist/core/router/planner.d.ts +53 -0
- package/dist/core/router/planner.d.ts.map +1 -0
- package/dist/core/router/planner.js +113 -0
- package/dist/core/router/rules.d.ts +46 -0
- package/dist/core/router/rules.d.ts.map +1 -0
- package/dist/core/router/rules.js +91 -0
- package/dist/core/run-panel-api.d.ts +94 -0
- package/dist/core/run-panel-api.d.ts.map +1 -0
- package/dist/core/run-panel-api.js +169 -0
- package/dist/core/schedule-gate.js +5 -1
- package/dist/core/schedule-v2.d.ts +34 -0
- package/dist/core/schedule-v2.d.ts.map +1 -1
- package/dist/core/schedule-v2.js +91 -5
- package/dist/core/scheduler/at-fallback.d.ts +55 -2
- package/dist/core/scheduler/at-fallback.d.ts.map +1 -1
- package/dist/core/scheduler/at-fallback.js +135 -5
- package/dist/core/scheduler/linux.d.ts +18 -2
- package/dist/core/scheduler/linux.d.ts.map +1 -1
- package/dist/core/scheduler/linux.js +63 -20
- package/dist/core/scheduler/mac.d.ts +44 -2
- package/dist/core/scheduler/mac.d.ts.map +1 -1
- package/dist/core/scheduler/mac.js +126 -15
- package/dist/core/scheduler/posix.d.ts.map +1 -1
- package/dist/core/scheduler/posix.js +25 -1
- package/dist/core/scheduler/registry.d.ts +11 -0
- package/dist/core/scheduler/registry.d.ts.map +1 -1
- package/dist/core/scheduler/registry.js +83 -21
- package/dist/core/scheduler/run-now.d.ts +16 -0
- package/dist/core/scheduler/run-now.d.ts.map +1 -0
- package/dist/core/scheduler/run-now.js +28 -0
- package/dist/core/scheduler/windows.d.ts.map +1 -1
- package/dist/core/scheduler/windows.js +15 -12
- package/dist/core/secrets.d.ts.map +1 -1
- package/dist/core/secrets.js +125 -28
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +18 -11
- package/dist/core/structured-log.d.ts +7 -1
- package/dist/core/structured-log.d.ts.map +1 -1
- package/dist/core/task-name.d.ts +24 -0
- package/dist/core/task-name.d.ts.map +1 -0
- package/dist/core/task-name.js +40 -0
- package/dist/core/worktree-run.d.ts +4 -0
- package/dist/core/worktree-run.d.ts.map +1 -0
- package/dist/core/worktree-run.js +164 -0
- package/dist/core/worktree.d.ts +115 -0
- package/dist/core/worktree.d.ts.map +1 -0
- package/dist/core/worktree.js +462 -0
- package/dist/core/wrappers/bash.d.ts +17 -0
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +224 -28
- package/dist/db/capability-repo.d.ts +124 -0
- package/dist/db/capability-repo.d.ts.map +1 -0
- package/dist/db/capability-repo.js +267 -0
- package/dist/db/history-repo.d.ts +46 -5
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +107 -25
- package/dist/db/index.d.ts +4 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +39 -1
- package/dist/db/metrics-repo.js +2 -2
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +3 -1
- package/dist/db/recovery.d.ts.map +1 -1
- package/dist/db/recovery.js +5 -4
- package/dist/db/run-context.d.ts +103 -0
- package/dist/db/run-context.d.ts.map +1 -0
- package/dist/db/run-context.js +224 -0
- package/dist/db/run-dlq.d.ts +100 -0
- package/dist/db/run-dlq.d.ts.map +1 -0
- package/dist/db/run-dlq.js +191 -0
- package/dist/db/run-journal.d.ts +33 -5
- package/dist/db/run-journal.d.ts.map +1 -1
- package/dist/db/run-journal.js +78 -14
- package/dist/db/run-resume.d.ts +10 -2
- package/dist/db/run-resume.d.ts.map +1 -1
- package/dist/db/run-resume.js +39 -13
- package/dist/db/runs-repo.d.ts +32 -7
- package/dist/db/runs-repo.d.ts.map +1 -1
- package/dist/db/runs-repo.js +50 -11
- package/dist/db/schema.d.ts +2 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +216 -3
- package/dist/db/settings-repo.d.ts +11 -0
- package/dist/db/settings-repo.d.ts.map +1 -1
- package/dist/db/settings-repo.js +25 -0
- package/dist/db/step-idempotency.d.ts +51 -0
- package/dist/db/step-idempotency.d.ts.map +1 -0
- package/dist/db/step-idempotency.js +136 -0
- package/dist/history.d.ts +1 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/i18n.d.ts +5 -0
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +11 -4
- package/dist/index.d.ts +140 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +480 -18
- package/dist/notifications.d.ts +22 -0
- package/dist/notifications.d.ts.map +1 -1
- package/dist/notifications.js +36 -8
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +25 -4
- package/dist/rpc.d.ts +924 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +352 -0
- package/dist/server.d.ts +46 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +172 -53
- package/dist/settings.d.ts +2 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +3 -3
- package/dist/shared/jobs-view.d.ts +1 -1
- package/dist/shared/jobs-view.d.ts.map +1 -1
- package/dist/shared/jobs-view.js +2 -0
- package/dist/task-transfer.d.ts +16 -0
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +16 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +7 -0
- package/dist/workspaces.d.ts +25 -3
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +43 -8
- package/docs/ARCHITECTURE.md +498 -58
- package/docs/COMPATIBILITY.md +2 -2
- package/docs/CONCEPT.md +185 -91
- package/docs/CROSS_PLATFORM.ru.md +20 -0
- package/docs/CROSS_PLATFORM.zh.md +18 -0
- package/docs/EXECUTION-LOOP.md +211 -0
- package/docs/FEATURES.md +65 -4
- package/docs/FEATURES.zh.md +52 -4
- package/docs/MIGRATION.md +2 -2
- package/docs/PIPELINE.md +293 -0
- package/docs/README.ru.md +44 -5
- package/docs/README.zh.md +46 -6
- package/docs/SAFETY.md +142 -0
- package/docs/SAVINGS.md +29 -0
- package/docs/SAVINGS.ru.md +29 -0
- package/docs/SAVINGS.zh.md +18 -0
- package/gui-experimental.cjs +9 -8
- package/locales/en.json +84 -1
- package/locales/ru.json +84 -1
- package/locales/zh.json +84 -1
- package/opencode.pipeline.yaml +35 -0
- package/package.json +46 -2
- package/scripts/audit-bundle.mjs +215 -0
- package/scripts/test-home.mjs +83 -0
- package/src/cli.ts +412 -0
- package/src/core/dlq-api.ts +98 -0
- package/src/core/dry-run.ts +27 -3
- package/src/core/execution.ts +538 -0
- package/src/core/file-watcher.ts +2 -2
- package/src/core/gate-integrity.ts +160 -0
- package/src/core/git-trigger.ts +18 -5
- package/src/core/guard-run.ts +119 -0
- package/src/core/guard.ts +431 -0
- package/src/core/lock.ts +244 -30
- package/src/core/matrix.ts +95 -50
- package/src/core/mission.ts +485 -0
- package/src/core/native-notify.ts +1 -1
- package/src/core/one-shot.ts +36 -8
- package/src/core/opencode-cli.ts +103 -0
- package/src/core/opencode-models.ts +315 -0
- package/src/core/pipeline-apply.ts +158 -0
- package/src/core/pipeline-io.ts +79 -0
- package/src/core/pipeline-map.ts +264 -0
- package/src/core/pipeline-spec.ts +775 -0
- package/src/core/ps-wrapper.ts +274 -64
- package/src/core/record-history.ts +229 -104
- package/src/core/router/dispatch.ts +94 -0
- package/src/core/router/escalation.ts +129 -0
- package/src/core/router/planner.ts +166 -0
- package/src/core/router/rules.ts +115 -0
- package/src/core/run-panel-api.ts +262 -0
- package/src/core/schedule-gate.ts +7 -3
- package/src/core/schedule-v2.ts +114 -5
- package/src/core/scheduler/at-fallback.ts +190 -5
- package/src/core/scheduler/linux.ts +72 -21
- package/src/core/scheduler/logs.ts +2 -2
- package/src/core/scheduler/mac.ts +174 -14
- package/src/core/scheduler/posix.ts +20 -1
- package/src/core/scheduler/registry.ts +107 -26
- package/src/core/scheduler/run-now.ts +32 -0
- package/src/core/scheduler/windows.ts +19 -15
- package/src/core/secrets.ts +131 -31
- package/src/core/session.ts +23 -10
- package/src/core/structured-log.ts +22 -5
- package/src/core/task-name.ts +67 -0
- package/src/core/telegram.ts +2 -2
- package/src/core/triage-worker.ts +7 -7
- package/src/core/triage.ts +2 -2
- package/src/core/worktree-run.ts +199 -0
- package/src/core/worktree.ts +600 -0
- package/src/core/wrappers/bash.ts +239 -27
- package/src/db/capability-repo.ts +402 -0
- package/src/db/history-repo.ts +151 -22
- package/src/db/index.ts +37 -1
- package/src/db/metrics-repo.ts +2 -2
- package/src/db/migrate.ts +3 -1
- package/src/db/recovery.ts +5 -4
- package/src/db/run-context.ts +370 -0
- package/src/db/run-dlq.ts +310 -0
- package/src/db/run-journal.ts +100 -13
- package/src/db/run-resume.ts +65 -13
- package/src/db/runs-repo.ts +66 -13
- package/src/db/schema.ts +218 -3
- package/src/db/settings-repo.ts +31 -0
- package/src/db/step-idempotency.ts +185 -0
- package/src/gui.tsx +692 -13
- package/src/history.ts +1 -1
- package/src/i18n.ts +12 -4
- package/src/index.ts +648 -8
- package/src/notifications.ts +38 -8
- package/src/profiles.ts +26 -4
- package/src/rpc.ts +379 -0
- package/src/server.ts +206 -54
- package/src/settings.ts +5 -5
- package/src/shared/jobs-view.ts +3 -1
- package/src/task-transfer.ts +31 -0
- package/src/types.ts +9 -0
- package/src/workspaces.ts +58 -9
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* G-1.2: проверяемый snapshot входов Quality Gate.
|
|
3
|
+
*
|
|
4
|
+
* Обёртка фиксирует хэш команды/хука гейта, промпта и таймаута в момент
|
|
5
|
+
* создания задачи (файл лежит в PLUGIN_DIR, вне write-scope агента) и
|
|
6
|
+
* сверяет его непосредственно перед запуском гейта. Подмена гейта или
|
|
7
|
+
* промпта после создания задачи приводит к fail-closed: гейт не выполняется,
|
|
8
|
+
* запуск помечается ошибкой. Snapshot защищает от подмены *definition*
|
|
9
|
+
* гейта; исходники, которые гейт проверяет, в хэш не входят (агент
|
|
10
|
+
* legitimately меняет их в ходе задачи).
|
|
11
|
+
*/
|
|
12
|
+
import crypto from "node:crypto";
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { PLUGIN_DIR, sanitizeName } from "../types.js";
|
|
17
|
+
export const GATE_SNAPSHOT_VERSION = 1;
|
|
18
|
+
export const GATE_SNAPSHOT_DIR = path.join(PLUGIN_DIR, "gate-snapshots");
|
|
19
|
+
/** Канонический хэш входов гейта. Порядок полей фиксирован контрактом. */
|
|
20
|
+
export function gateInputsHash(inputs) {
|
|
21
|
+
const canonical = JSON.stringify({
|
|
22
|
+
version: GATE_SNAPSHOT_VERSION,
|
|
23
|
+
gate: inputs.gate,
|
|
24
|
+
prompt: inputs.prompt,
|
|
25
|
+
gateTimeoutSeconds: inputs.gateTimeoutSeconds,
|
|
26
|
+
});
|
|
27
|
+
return crypto.createHash("sha256").update(canonical, "utf8").digest("hex");
|
|
28
|
+
}
|
|
29
|
+
/** Путь snapshot'а задачи — вне рабочей директории задачи. */
|
|
30
|
+
export function gateSnapshotPath(taskName) {
|
|
31
|
+
const segment = sanitizeName(taskName).slice(0, 80) || "task";
|
|
32
|
+
return path.join(GATE_SNAPSHOT_DIR, `${segment}.json`);
|
|
33
|
+
}
|
|
34
|
+
function readText(file) {
|
|
35
|
+
if (!file)
|
|
36
|
+
return "";
|
|
37
|
+
try {
|
|
38
|
+
return fs.readFileSync(file, "utf8");
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Пишет snapshot задачам на этапе создания обёртки (fail-closed при ошибке). */
|
|
45
|
+
export function createGateSnapshot(taskName, inputs, snapshotFile = gateSnapshotPath(taskName)) {
|
|
46
|
+
const snapshot = {
|
|
47
|
+
version: GATE_SNAPSHOT_VERSION,
|
|
48
|
+
taskName,
|
|
49
|
+
createdAt: new Date().toISOString(),
|
|
50
|
+
hash: gateInputsHash(inputs),
|
|
51
|
+
};
|
|
52
|
+
fs.mkdirSync(path.dirname(snapshotFile), { recursive: true });
|
|
53
|
+
fs.writeFileSync(snapshotFile, `${JSON.stringify(snapshot, null, 2)}\n`, {
|
|
54
|
+
encoding: "utf8",
|
|
55
|
+
mode: 0o600,
|
|
56
|
+
});
|
|
57
|
+
return snapshotFile;
|
|
58
|
+
}
|
|
59
|
+
export function readGateSnapshot(file) {
|
|
60
|
+
try {
|
|
61
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
62
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
63
|
+
return null;
|
|
64
|
+
const value = parsed;
|
|
65
|
+
if (value.version !== GATE_SNAPSHOT_VERSION)
|
|
66
|
+
return null;
|
|
67
|
+
if (typeof value.hash !== "string" || !/^[0-9a-f]{64}$/.test(value.hash))
|
|
68
|
+
return null;
|
|
69
|
+
return {
|
|
70
|
+
version: value.version,
|
|
71
|
+
taskName: typeof value.taskName === "string" ? value.taskName : "",
|
|
72
|
+
createdAt: typeof value.createdAt === "string" ? value.createdAt : "",
|
|
73
|
+
hash: value.hash,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Сверяет текущие входы гейта с зафиксированными. При расхождении — fail-closed. */
|
|
81
|
+
export function verifyGateSnapshot(snapshotFile, inputs) {
|
|
82
|
+
const snapshot = readGateSnapshot(snapshotFile);
|
|
83
|
+
if (!snapshot) {
|
|
84
|
+
return { ok: false, reason: "snapshot гейта отсутствует или повреждён" };
|
|
85
|
+
}
|
|
86
|
+
const actual = gateInputsHash(inputs);
|
|
87
|
+
const expected = snapshot.hash;
|
|
88
|
+
const same = Buffer.byteLength(actual) === Buffer.byteLength(expected) &&
|
|
89
|
+
crypto.timingSafeEqual(Buffer.from(actual, "utf8"), Buffer.from(expected, "utf8"));
|
|
90
|
+
if (!same) {
|
|
91
|
+
return { ok: false, reason: "входы Quality Gate изменены с момента создания задачи" };
|
|
92
|
+
}
|
|
93
|
+
return { ok: true };
|
|
94
|
+
}
|
|
95
|
+
function optionValue(argv, name) {
|
|
96
|
+
const index = argv.indexOf(name);
|
|
97
|
+
return index >= 0 ? argv[index + 1] : undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* CLI для обёрток: `node gate-integrity.js verify --snapshot <file>
|
|
101
|
+
* --gate-file <file> | --gate-command <text> --prompt-file <file> --timeout <n>`.
|
|
102
|
+
* exit 0 — входы совпадают, exit 1 — расхождение/отсутствие snapshot'а.
|
|
103
|
+
*/
|
|
104
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
105
|
+
if (argv[0] !== "verify") {
|
|
106
|
+
console.error("gate-integrity: только команда verify поддерживается");
|
|
107
|
+
return 2;
|
|
108
|
+
}
|
|
109
|
+
const snapshotFile = optionValue(argv, "--snapshot");
|
|
110
|
+
if (!snapshotFile) {
|
|
111
|
+
console.error("gate-integrity: не задан --snapshot");
|
|
112
|
+
return 2;
|
|
113
|
+
}
|
|
114
|
+
const gateFile = optionValue(argv, "--gate-file");
|
|
115
|
+
const gateCommand = optionValue(argv, "--gate-command");
|
|
116
|
+
const gate = gateFile ? readText(gateFile) : gateCommand ?? "";
|
|
117
|
+
const timeoutRaw = Number(optionValue(argv, "--timeout") ?? 300);
|
|
118
|
+
const inputs = {
|
|
119
|
+
gate,
|
|
120
|
+
prompt: readText(optionValue(argv, "--prompt-file")),
|
|
121
|
+
gateTimeoutSeconds: Number.isFinite(timeoutRaw) ? timeoutRaw : 300,
|
|
122
|
+
};
|
|
123
|
+
const result = verifyGateSnapshot(snapshotFile, inputs);
|
|
124
|
+
if (!result.ok) {
|
|
125
|
+
console.error(`gate-integrity: ${result.reason ?? "проверка целостности не пройдена"}`);
|
|
126
|
+
return 1;
|
|
127
|
+
}
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url))) {
|
|
131
|
+
process.exitCode = await main();
|
|
132
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-trigger.d.ts","sourceRoot":"","sources":["../../src/core/git-trigger.ts"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AAEH,eAAO,MAAM,gCAAgC,KAAK,CAAC;AACnD,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAE7C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,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10000;
|
|
22
|
+
/**
|
|
23
|
+
* W-1 (0.0.6): опрос репозитория — служебная операция, а не пользовательская.
|
|
24
|
+
* Игнорируем пользовательские хуки и запрещаем интерактивный ввод пароля,
|
|
25
|
+
* чтобы длинная цепочка хуков или запрос credentials не блокировали опрос.
|
|
26
|
+
*/
|
|
27
|
+
const GIT_SAFE_ARGS = ["-c", `core.hooksPath=${process.platform === "win32" ? "NUL" : "/dev/null"}`];
|
|
28
|
+
const GIT_SAFE_ENV = { ...process.env, GIT_TERMINAL_PROMPT: "0" };
|
|
22
29
|
const defaultRunner = (cwd, args) => new Promise((resolve, reject) => {
|
|
23
|
-
execFile("git", ["-C", cwd, ...args], {
|
|
30
|
+
execFile("git", ["-C", cwd, ...GIT_SAFE_ARGS, ...args], {
|
|
31
|
+
timeout: GIT_COMMAND_TIMEOUT_MS,
|
|
32
|
+
windowsHide: true,
|
|
33
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
34
|
+
env: GIT_SAFE_ENV,
|
|
35
|
+
}, (err, stdout) => {
|
|
24
36
|
if (err) {
|
|
25
37
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
26
38
|
return;
|
|
@@ -162,7 +174,7 @@ export async function checkGitTrigger(task, options = {}) {
|
|
|
162
174
|
files: [],
|
|
163
175
|
matched: [],
|
|
164
176
|
message: t("gitTrigger.diffFailed", {
|
|
165
|
-
error: err
|
|
177
|
+
error: err instanceof Error ? err.message : String(err),
|
|
166
178
|
}),
|
|
167
179
|
};
|
|
168
180
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard-run.d.ts","sourceRoot":"","sources":["../../src/core/guard-run.ts"],"names":[],"mappings":";AA8DA,yEAAyE;AACzE,wBAAsB,IAAI,CAAC,IAAI,GAAE,MAAM,EAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,CA0ClF"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* W-3 (0.0.6): CLI-помощник guard-условий.
|
|
4
|
+
*
|
|
5
|
+
* Вызывается из сгенерированных обёрток до запуска opencode:
|
|
6
|
+
* node guard-run.js --cwd "<workdir>" --guards-b64 "<base64 json>" [--json]
|
|
7
|
+
*
|
|
8
|
+
* Коды выхода:
|
|
9
|
+
* 0 — все guard-проверки пройдены, можно запускать;
|
|
10
|
+
* 4 — проверки не пройдены, прогон нужно пропустить (skip);
|
|
11
|
+
* 1 — некорректные аргументы или конфигурация (fail-closed).
|
|
12
|
+
*
|
|
13
|
+
* В stdout печатается человекочитаемая причина (или JSON с --json),
|
|
14
|
+
* диагностика — в stderr. Модуль ничего не завершает при импорте.
|
|
15
|
+
*/
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { pathToFileURL } from "node:url";
|
|
18
|
+
import { evaluateGuards, GUARD_SKIP_EXIT_CODE, normalizeTaskGuards, } from "./guard.js";
|
|
19
|
+
function parseArgs(argv) {
|
|
20
|
+
const args = { json: false };
|
|
21
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
22
|
+
const flag = argv[index];
|
|
23
|
+
const value = argv[index + 1];
|
|
24
|
+
switch (flag) {
|
|
25
|
+
case "--json":
|
|
26
|
+
args.json = true;
|
|
27
|
+
break;
|
|
28
|
+
case "--cwd":
|
|
29
|
+
case "--guards-b64": {
|
|
30
|
+
if (!value || value.startsWith("--")) {
|
|
31
|
+
return { args, error: `Флаг ${flag} требует значение.` };
|
|
32
|
+
}
|
|
33
|
+
if (flag === "--cwd")
|
|
34
|
+
args.cwd = value;
|
|
35
|
+
if (flag === "--guards-b64")
|
|
36
|
+
args.guardsB64 = value;
|
|
37
|
+
index += 1;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
default:
|
|
41
|
+
return { args, error: `Неизвестный аргумент: ${flag}` };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { args };
|
|
45
|
+
}
|
|
46
|
+
function usage() {
|
|
47
|
+
return [
|
|
48
|
+
"Использование:",
|
|
49
|
+
' guard-run.js --cwd <dir> --guards-b64 "<base64 json>" [--json]',
|
|
50
|
+
].join("\n");
|
|
51
|
+
}
|
|
52
|
+
/** Точка входа для тестов: возвращает exit code, ничего не завершает. */
|
|
53
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
54
|
+
const parsed = parseArgs(argv);
|
|
55
|
+
if (parsed.error) {
|
|
56
|
+
process.stderr.write(`[guard] ${parsed.error}\n`);
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
const { cwd, guardsB64 } = parsed.args;
|
|
60
|
+
if (!cwd || !guardsB64) {
|
|
61
|
+
process.stderr.write(`[guard] ${usage()}\n`);
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
let raw;
|
|
65
|
+
try {
|
|
66
|
+
raw = JSON.parse(Buffer.from(guardsB64, "base64").toString("utf8"));
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
process.stderr.write(`[guard] не удалось разобрать guards: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
const normalized = normalizeTaskGuards(raw);
|
|
73
|
+
if (!normalized.ok) {
|
|
74
|
+
process.stderr.write(`[guard] ${normalized.error}\n`);
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
if (!normalized.guards) {
|
|
78
|
+
process.stderr.write("[guard] пустая конфигурация guard.\n");
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
const result = await evaluateGuards(normalized.guards, { cwd });
|
|
82
|
+
if (parsed.args.json) {
|
|
83
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
84
|
+
}
|
|
85
|
+
else if (result.passed) {
|
|
86
|
+
process.stdout.write(`[guard] OK: ${result.checks.length} проверок пройдено\n`);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
process.stdout.write(`[guard] skipped: ${result.reasons.join("; ")}\n`);
|
|
90
|
+
}
|
|
91
|
+
return result.passed ? 0 : GUARD_SKIP_EXIT_CODE;
|
|
92
|
+
}
|
|
93
|
+
const invokedPath = process.argv[1] ? pathToFileURL(path.resolve(process.argv[1])).href : "";
|
|
94
|
+
if (import.meta.url === invokedPath) {
|
|
95
|
+
main().then((code) => {
|
|
96
|
+
process.exitCode = code;
|
|
97
|
+
}, (error) => {
|
|
98
|
+
process.stderr.write(`[guard] ${error instanceof Error ? error.message : String(error)}\n`);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Код выхода CLI-помощника: guard не пройден, прогон нужно пропустить. */
|
|
2
|
+
export declare const GUARD_SKIP_EXIT_CODE = 4;
|
|
3
|
+
/** Таймаут shell-guard по умолчанию. */
|
|
4
|
+
export declare const DEFAULT_GUARD_TIMEOUT_SECONDS = 60;
|
|
5
|
+
export interface SemanticGuardConfig {
|
|
6
|
+
/** Все пути должны существовать (относительно рабочей директории). */
|
|
7
|
+
filesExist?: string[];
|
|
8
|
+
/** Ни один из путей не должен существовать. */
|
|
9
|
+
filesMissing?: string[];
|
|
10
|
+
/** Glob-шаблон текущей git-ветки, например `feature/*`. */
|
|
11
|
+
branch?: string;
|
|
12
|
+
/** Glob-шаблоны изменённых путей; достаточно совпадения хотя бы с одним. */
|
|
13
|
+
changedPaths?: string[];
|
|
14
|
+
/** Git-ref для сравнения изменений. По умолчанию `HEAD~1`. */
|
|
15
|
+
changedSince?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TaskGuards {
|
|
18
|
+
/** Shell-команда: exit 0 — запускать, любой другой код — пропустить. */
|
|
19
|
+
command?: string;
|
|
20
|
+
/** Таймаут shell-guard в секундах (1..3600, по умолчанию 60). */
|
|
21
|
+
timeoutSeconds?: number;
|
|
22
|
+
/** Семантические проверки рабочей директории. */
|
|
23
|
+
semantic?: SemanticGuardConfig;
|
|
24
|
+
}
|
|
25
|
+
export interface GuardEvaluation {
|
|
26
|
+
/** true — все проверки пройдены, задачу можно запускать. */
|
|
27
|
+
passed: boolean;
|
|
28
|
+
/** Причины пропуска (человекочитаемые). */
|
|
29
|
+
reasons: string[];
|
|
30
|
+
/** Выполненные проверки (для лога). */
|
|
31
|
+
checks: string[];
|
|
32
|
+
}
|
|
33
|
+
export type NormalizeGuardsResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
guards?: TaskGuards;
|
|
36
|
+
} | {
|
|
37
|
+
ok: false;
|
|
38
|
+
error: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Валидирует guard-конфигурацию из JSON/инструмента/импорта.
|
|
42
|
+
* Возвращает нормализованный объект либо ошибку; никогда не бросает.
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizeTaskGuards(input: unknown): NormalizeGuardsResult;
|
|
45
|
+
/**
|
|
46
|
+
* Выполняет guard-проверки в указанной рабочей директории.
|
|
47
|
+
* Никогда не бросает: любая ошибка означает «пропустить».
|
|
48
|
+
*/
|
|
49
|
+
export declare function evaluateGuards(guards: TaskGuards, options: {
|
|
50
|
+
cwd: string;
|
|
51
|
+
}): Promise<GuardEvaluation>;
|
|
52
|
+
//# sourceMappingURL=guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/core/guard.ts"],"names":[],"mappings":"AAmBA,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,wCAAwC;AACxC,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAMhD,MAAM,WAAW,mBAAmB;IAClC,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;I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