@jstn-sdk/ma 0.1.13 → 0.14.1
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/.agents/plugins/marketplace.json +0 -0
- package/.codex/agents/Architect.toml +1 -0
- package/.codex/agents/Auditor.toml +1 -0
- package/.codex/agents/Builder.toml +1 -0
- package/.codex/agents/Flow.toml +1 -0
- package/.codex/agents/Sage.toml +1 -0
- package/.codex/agents/Vibe.toml +1 -0
- package/.codex/hooks.json +12 -2
- package/.codex/prompts/enforcement.md +0 -0
- package/.codex/prompts/onboarding.md +6 -1
- package/.codex/prompts/release-rules.md +0 -0
- package/.codex/prompts/skill-contract.md +0 -0
- package/COVERAGE.md +9 -9
- package/DEMO.md +15 -6
- package/LICENSE +0 -0
- package/README.md +127 -784
- package/bin/ma.js +591 -105
- package/data/clone-data.ledger.json +0 -0
- package/data/clone-data.proof.json +0 -0
- package/data/clone-data.rvf +0 -0
- package/docs/README.md +8 -2
- package/docs/assets/banner.png +0 -0
- package/docs/autonomous-tasks.md +46 -0
- package/docs/codex-integration.md +16 -0
- package/docs/getting-started.md +32 -8
- package/docs/installed-sdk.md +0 -0
- package/docs/mcp-setup.md +30 -1
- package/docs/qa/{release-issue-gates-0.1.13.json → release-issue-gates-0.14.1.json} +77 -77
- package/docs/qa/release-readiness-0.1.5.md +0 -0
- package/docs/qa/{release-readiness-0.1.13.md → release-readiness-0.14.1.md} +12 -12
- package/docs/quality.md +24 -0
- package/docs/reference/native-engineering-patterns.md +0 -0
- package/docs/reference/native-security-playbooks.md +0 -0
- package/docs/reference/native-source-selection.md +0 -0
- package/docs/reference/native-style-and-deslop.md +0 -0
- package/docs/release-spec.md +27 -14
- package/docs/skills.md +1 -1
- package/docs/vendor-plugin-publishing.md +49 -0
- package/index.js +73 -0
- package/mcp/collections.json +0 -0
- package/mcp/fallback.json +0 -0
- package/mcp/local/code-intel.js +185 -41
- package/mcp/local/context.js +180 -0
- package/mcp/local/memory.js +17 -6
- package/mcp/local/playbooks.js +0 -0
- package/mcp/local/quality.js +39 -0
- package/mcp/local/state.js +7 -3
- package/mcp/local/team-run.js +8 -3
- package/mcp/local/trace.js +0 -0
- package/mcp/local-capabilities.json +9 -0
- package/mcp/native-playbooks.json +0 -0
- package/mcp/servers.json +0 -0
- package/package.json +37 -6
- package/plugins/meta-architect/.app.json +1 -1
- package/plugins/meta-architect/.claude-plugin/plugin.json +12 -0
- package/plugins/meta-architect/.codex-plugin/plugin.json +1 -1
- package/plugins/meta-architect/.mcp.json +1 -1
- package/plugins/meta-architect/README.md +14 -2
- package/plugins/meta-architect/obsidian/main.js +137 -4
- package/plugins/meta-architect/obsidian/manifest.json +1 -1
- package/plugins/meta-architect/obsidian/styles.css +0 -0
- package/plugins/meta-architect/skills/align/SKILL.md +0 -0
- package/plugins/meta-architect/skills/align/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/align/references/shared-language.md +0 -0
- package/plugins/meta-architect/skills/arch/SKILL.md +0 -0
- package/plugins/meta-architect/skills/arch/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/build/SKILL.md +0 -0
- package/plugins/meta-architect/skills/build/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/cleanup/SKILL.md +0 -0
- package/plugins/meta-architect/skills/cleanup/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/cleanup/references/style-and-deslop.md +0 -0
- package/plugins/meta-architect/skills/diagnose/SKILL.md +0 -0
- package/plugins/meta-architect/skills/diagnose/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/flow/SKILL.md +0 -0
- package/plugins/meta-architect/skills/flow/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/maestro/SKILL.md +17 -1
- package/plugins/meta-architect/skills/maestro/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/maestro/references/core-release-rules.md +2 -2
- package/plugins/meta-architect/skills/maestro/references/native-ingest-map.md +0 -0
- package/plugins/meta-architect/skills/sage/SKILL.md +0 -0
- package/plugins/meta-architect/skills/sage/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/sage/references/source-selection.md +0 -0
- package/plugins/meta-architect/skills/tdd/SKILL.md +0 -0
- package/plugins/meta-architect/skills/tdd/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/vet/SKILL.md +0 -0
- package/plugins/meta-architect/skills/vet/agents/openai.yaml +0 -0
- package/plugins/meta-architect/skills/vet/references/security-playbooks.md +0 -0
- package/plugins/meta-architect/skills/vibe/SKILL.md +0 -0
- package/plugins/meta-architect/skills/vibe/agents/openai.yaml +0 -0
- package/schemas/autonomous-task-queue.schema.json +58 -0
- package/schemas/handoff-packet.schema.json +36 -0
- package/schemas/setup-receipt.schema.json +28 -0
- package/schemas/skill-frontmatter.schema.json +20 -0
- package/schemas/support-bundle.schema.json +37 -0
- package/schemas/task-contract.schema.json +31 -0
- package/scripts/active-autonomy-hook.mjs +141 -11
- package/scripts/biome-staged.js +0 -0
- package/scripts/build-linux-packages.mjs +7 -3
- package/scripts/cleanup-test-fixtures.sh +55 -0
- package/scripts/context-hydration-hook.mjs +89 -0
- package/scripts/demo-smoke.js +285 -0
- package/scripts/doctor.js +10 -8
- package/scripts/install.sh +33 -4
- package/scripts/install.sh.sha256 +1 -0
- package/scripts/linux-package-lib.mjs +0 -0
- package/scripts/linux-package-smoke.mjs +2 -2
- package/scripts/package-size-check.mjs +26 -0
- package/scripts/plugin-build.js +314 -0
- package/scripts/plugin-publish.js +77 -0
- package/scripts/plugin-sync.js +83 -17
- package/scripts/prepack.js +9 -0
- package/scripts/ralph/prompt.md +0 -0
- package/scripts/release-metadata.js +0 -0
- package/scripts/release-sync.js +83 -7
- package/scripts/release-verify.js +131 -7
- package/scripts/setup-npmrc.js +48 -23
- package/scripts/skills-install.js +9 -2
- package/scripts/skills-manifest.js +2 -21
- package/scripts/skills-pack.js +2 -2
- package/scripts/skills-validate.js +5 -55
- package/skills/align/SKILL.md +0 -0
- package/skills/align/agents/openai.yaml +0 -0
- package/skills/align/references/shared-language.md +0 -0
- package/skills/arch/SKILL.md +0 -0
- package/skills/arch/agents/openai.yaml +0 -0
- package/skills/build/SKILL.md +0 -0
- package/skills/build/agents/openai.yaml +0 -0
- package/skills/cleanup/SKILL.md +0 -0
- package/skills/cleanup/agents/openai.yaml +0 -0
- package/skills/cleanup/references/style-and-deslop.md +0 -0
- package/skills/diagnose/SKILL.md +0 -0
- package/skills/diagnose/agents/openai.yaml +0 -0
- package/skills/flow/SKILL.md +0 -0
- package/skills/flow/agents/openai.yaml +0 -0
- package/skills/index.json +0 -0
- package/skills/maestro/SKILL.md +17 -1
- package/skills/maestro/agents/openai.yaml +0 -0
- package/skills/maestro/references/core-release-rules.md +2 -2
- package/skills/maestro/references/native-ingest-map.md +0 -0
- package/skills/sage/SKILL.md +0 -0
- package/skills/sage/agents/openai.yaml +0 -0
- package/skills/sage/references/source-selection.md +0 -0
- package/skills/tdd/SKILL.md +0 -0
- package/skills/tdd/agents/openai.yaml +0 -0
- package/skills/vet/SKILL.md +0 -0
- package/skills/vet/agents/openai.yaml +0 -0
- package/skills/vet/references/security-playbooks.md +0 -0
- package/skills/vibe/SKILL.md +0 -0
- package/skills/vibe/agents/openai.yaml +0 -0
- package/sprint/00-idea.md +0 -0
- package/sprint/01-architecture.md +0 -0
- package/sprint/02-oss-evidence.md +0 -0
- package/sprint/03-logic.md +0 -0
- package/sprint/04-security.md +0 -0
- package/sprint/05-dx-ux.md +0 -0
- package/sprint/06-build-plan.md +0 -0
- package/sprint/07-release.md +2 -2
- package/src/agents.js +281 -0
- package/src/bootstrap.js +272 -65
- package/src/build-gate.js +0 -0
- package/src/codex-app-server.js +291 -0
- package/src/decision-log.js +0 -0
- package/src/fs-utils.js +175 -4
- package/src/launcher.js +26 -23
- package/src/mcp-config.js +9 -1
- package/src/mcp-live-client.js +141 -8
- package/src/paths.js +6 -1
- package/src/policy.js +2 -2
- package/src/prelaunch.js +223 -0
- package/src/process-utils.js +62 -0
- package/src/quality/ai-quality-orchestrator.js +328 -0
- package/src/release-issue-gates.js +62 -0
- package/src/release-operations.js +72 -0
- package/src/release-state.js +0 -0
- package/src/runtime/active-autonomy-core.js +0 -0
- package/src/runtime/agent-compat.js +31 -0
- package/src/runtime/alignment-sentinel.js +0 -0
- package/src/runtime/architect-review.js +249 -11
- package/src/runtime/autonomous-tasks.js +585 -0
- package/src/runtime/build-readiness.js +0 -0
- package/src/runtime/code-graph-rehearse.js +0 -0
- package/src/runtime/codeburn-core.js +118 -0
- package/src/runtime/context-authority.js +40 -0
- package/src/runtime/context-economy-core.js +40 -0
- package/src/runtime/continuity-graph.js +201 -0
- package/src/runtime/continuity-notes.js +71 -26
- package/src/runtime/core-source-ingest.js +2 -2
- package/src/runtime/detached-provider.js +90 -13
- package/src/runtime/doctor-report.js +18 -0
- package/src/runtime/environment-awareness-core.js +0 -0
- package/src/runtime/exposure-catalog.js +0 -0
- package/src/runtime/graphify-core.js +167 -0
- package/src/runtime/guidance-stack.js +9 -2
- package/src/runtime/handoff-packets.js +92 -0
- package/src/runtime/headroom-core.js +104 -0
- package/src/runtime/helper-orchestration-core.js +0 -0
- package/src/runtime/hook-profiles.js +20 -0
- package/src/runtime/learning-loop-core.js +110 -4
- package/src/runtime/live-agent-verification.js +122 -0
- package/src/runtime/maestro-events.js +0 -0
- package/src/runtime/maestro-manager.js +0 -0
- package/src/runtime/maestro-output.js +58 -0
- package/src/runtime/maestro-state.js +0 -0
- package/src/runtime/managed-markdown.js +29 -0
- package/src/runtime/mcp-authority.js +147 -0
- package/src/runtime/mcp-policy.js +0 -0
- package/src/runtime/obsidian-integration-core.js +255 -17
- package/src/runtime/obsidian-plugin-bridge.js +344 -38
- package/src/runtime/orchestrator.js +0 -0
- package/src/runtime/pi-maestro-core.js +89 -0
- package/src/runtime/preferences.js +79 -0
- package/src/runtime/project-context.js +636 -0
- package/src/runtime/prompt-strategy-core.js +0 -0
- package/src/runtime/quorum-review.js +0 -0
- package/src/runtime/ralph-execution-core.js +0 -0
- package/src/runtime/redaction-gateway.js +218 -19
- package/src/runtime/runtime-state.js +94 -2
- package/src/runtime/schema-migrations.js +162 -0
- package/src/runtime/semantic-recording-core.js +0 -0
- package/src/runtime/signal-hooks.js +13 -0
- package/src/runtime/skills-registry-export.js +96 -8
- package/src/runtime/startup-path.js +0 -0
- package/src/runtime/task-contracts.js +83 -0
- package/src/runtime/universal-plugin-broker-core.js +373 -50
- package/src/runtime/workspace-intelligence-runtime.js +0 -0
- package/src/runtime/workspace-virtualizer.js +0 -0
- package/src/runtime/workspaces.js +0 -0
- package/src/runtime-artifacts.js +0 -0
- package/src/setup-lifecycle.js +359 -0
- package/src/skill-frontmatter.js +78 -0
- package/src/skill-installer.js +226 -71
- package/src/skills.js +309 -31
- package/src/state-sync.js +0 -0
- package/src/test-fixtures.js +543 -0
- package/src/tui/grid.js +67 -0
- package/src/tui/status-grid.js +23 -0
- package/support-bundle.json +114 -0
- package/templates/AGENTS.md +6 -2
- package/templates/catalog-manifest.json +0 -0
- package/templates/model-instructions/core.md +0 -0
- package/templates/model-instructions/release.md +0 -0
- package/templates/model-instructions/security.md +0 -0
- package/templates/quality/ai-quality-rules.yml +37 -0
- package/docs/assets/image/Screenshot(1).png +0 -0
- package/docs/assets/image/Screenshot(2).png +0 -0
- package/docs/assets/image/Screenshot(3).png +0 -0
- package/docs/assets/image/Screenshot(4).png +0 -0
- package/docs/assets/image/Screenshot(5).png +0 -0
- package/docs/assets/image/Screenshot(6).png +0 -0
- package/docs/assets/image/Screenshot(7).png +0 -0
- package/docs/assets/image/Screenshot(8).png +0 -0
- package/docs/assets/image/Screenshot(9).png +0 -0
- package/docs/assets/meta-architect-logo.png +0 -0
- package/docs/assets/meta-architect-logo.svg +0 -8
- package/docs/onboarding.md +0 -81
- package/docs/prompt-guidance-contract.md +0 -17
- package/docs/prompt-guidance-fragments/active-autonomy-core.md +0 -7
- package/docs/skills-publishing.md +0 -255
- package/scripts/postinstall.js +0 -23
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
3
4
|
import { readJson, writeFileIfMissing, writeJson } from "../fs-utils.js";
|
|
4
5
|
import { getRuntimeStatePath } from "../paths.js";
|
|
5
|
-
import {
|
|
6
|
+
import { safeSpawnSync } from "../process-utils.js";
|
|
7
|
+
import {
|
|
8
|
+
maskSensitiveText,
|
|
9
|
+
redactProviderBoundPayload,
|
|
10
|
+
redactProviderBoundText,
|
|
11
|
+
seedRedactionVault,
|
|
12
|
+
} from "./redaction-gateway.js";
|
|
13
|
+
|
|
14
|
+
const REVIEW_POLICY_PATH = path.join(".ma", "architect-review-policy.json");
|
|
15
|
+
const DEFAULT_REVIEW_TIMEOUT_MS = 120000;
|
|
16
|
+
const MAX_REVIEW_OUTPUT_BYTES = 1024 * 1024;
|
|
6
17
|
|
|
7
18
|
export function getArchitectReviewPath() {
|
|
8
19
|
return getRuntimeStatePath("architect-review.json");
|
|
@@ -57,32 +68,259 @@ export async function runExternalArchitectReview({ prompt = "" } = {}) {
|
|
|
57
68
|
const outputPath = getRuntimeStatePath("architect-review.output.json");
|
|
58
69
|
await fs.writeFile(promptPath, `${redactedPrompt.sanitizedText.trimEnd()}\n`, "utf8");
|
|
59
70
|
|
|
60
|
-
const
|
|
71
|
+
const { command: binary, args } = parseTrustedCommand(
|
|
72
|
+
command,
|
|
73
|
+
redactedPrompt.sanitizedText,
|
|
74
|
+
getArchitectReviewConfiguration(),
|
|
75
|
+
);
|
|
76
|
+
const timeout = readReviewTimeoutMs();
|
|
77
|
+
const result = safeSpawnSync(binary, args, {
|
|
61
78
|
cwd: process.cwd(),
|
|
62
|
-
env: {
|
|
63
|
-
...process.env,
|
|
79
|
+
env: buildArchitectReviewEnv({
|
|
64
80
|
MA_ARCHITECT_REVIEW_PROMPT: redactedPrompt.sanitizedText,
|
|
65
81
|
MA_ARCHITECT_REVIEW_PROMPT_FILE: promptPath,
|
|
66
82
|
MA_ARCHITECT_REVIEW_OUTPUT: outputPath,
|
|
67
|
-
},
|
|
83
|
+
}),
|
|
68
84
|
encoding: "utf8",
|
|
85
|
+
shell: false,
|
|
86
|
+
timeout,
|
|
87
|
+
maxBuffer: MAX_REVIEW_OUTPUT_BYTES,
|
|
88
|
+
killSignal: "SIGKILL",
|
|
69
89
|
});
|
|
70
90
|
|
|
91
|
+
if (result.error) {
|
|
92
|
+
await writeReviewReceipt({
|
|
93
|
+
status: "failed",
|
|
94
|
+
command: binary,
|
|
95
|
+
timeout,
|
|
96
|
+
error: result.error.message,
|
|
97
|
+
});
|
|
98
|
+
throw new Error(`External architect review failed: ${result.error.message}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
71
101
|
if (result.status !== 0) {
|
|
102
|
+
await writeReviewReceipt({
|
|
103
|
+
status: "failed",
|
|
104
|
+
command: binary,
|
|
105
|
+
timeout,
|
|
106
|
+
code: result.status,
|
|
107
|
+
stderr: result.stderr,
|
|
108
|
+
});
|
|
72
109
|
throw new Error(
|
|
73
|
-
|
|
110
|
+
maskSensitiveText(
|
|
111
|
+
result.stderr?.trim() || result.stdout?.trim() || "External architect review failed",
|
|
112
|
+
).sanitizedText,
|
|
74
113
|
);
|
|
75
114
|
}
|
|
76
115
|
|
|
116
|
+
let outputStat;
|
|
117
|
+
try {
|
|
118
|
+
outputStat = await fs.stat(outputPath);
|
|
119
|
+
} catch {
|
|
120
|
+
await writeReviewReceipt({
|
|
121
|
+
status: "failed",
|
|
122
|
+
command: binary,
|
|
123
|
+
timeout,
|
|
124
|
+
error: "reviewer did not produce the configured JSON output",
|
|
125
|
+
});
|
|
126
|
+
throw new Error("External architect review did not produce JSON output");
|
|
127
|
+
}
|
|
128
|
+
if (outputStat.size > MAX_REVIEW_OUTPUT_BYTES) {
|
|
129
|
+
await writeReviewReceipt({
|
|
130
|
+
status: "failed",
|
|
131
|
+
command: binary,
|
|
132
|
+
timeout,
|
|
133
|
+
error: `review output exceeds ${MAX_REVIEW_OUTPUT_BYTES} bytes`,
|
|
134
|
+
});
|
|
135
|
+
throw new Error(`External architect review output exceeds ${MAX_REVIEW_OUTPUT_BYTES} bytes`);
|
|
136
|
+
}
|
|
77
137
|
const parsed = JSON.parse(await fs.readFile(outputPath, "utf8"));
|
|
138
|
+
const safeOutput = await redactProviderBoundPayload(parsed, {
|
|
139
|
+
kind: "architect-review-output",
|
|
140
|
+
});
|
|
141
|
+
const sanitized = safeOutput.sanitizedPayload;
|
|
78
142
|
const review = {
|
|
79
143
|
schemaVersion: "0.1.0",
|
|
80
|
-
verdict:
|
|
81
|
-
reviewer:
|
|
82
|
-
summary:
|
|
83
|
-
findings: Array.isArray(
|
|
144
|
+
verdict: sanitized.verdict ?? "UNKNOWN",
|
|
145
|
+
reviewer: sanitized.reviewer ?? "external",
|
|
146
|
+
summary: sanitized.summary ?? null,
|
|
147
|
+
findings: Array.isArray(sanitized.findings) ? sanitized.findings : [],
|
|
84
148
|
reviewedAt: new Date().toISOString(),
|
|
85
149
|
};
|
|
86
150
|
await saveArchitectReview(review);
|
|
151
|
+
await writeReviewReceipt({
|
|
152
|
+
status: "completed",
|
|
153
|
+
command: binary,
|
|
154
|
+
timeout,
|
|
155
|
+
verdict: review.verdict,
|
|
156
|
+
});
|
|
87
157
|
return review;
|
|
88
158
|
}
|
|
159
|
+
|
|
160
|
+
export function getArchitectReviewConfiguration(root = process.env.MA_ROOT ?? process.cwd()) {
|
|
161
|
+
const allowedCommands = new Set(
|
|
162
|
+
(process.env.MA_ARCHITECT_REVIEW_ALLOWLIST ?? "")
|
|
163
|
+
.split(",")
|
|
164
|
+
.map((value) => value.trim())
|
|
165
|
+
.filter(Boolean),
|
|
166
|
+
);
|
|
167
|
+
const policyPath = path.join(root, REVIEW_POLICY_PATH);
|
|
168
|
+
try {
|
|
169
|
+
const policy = JSON.parse(readFileSync(policyPath, "utf8"));
|
|
170
|
+
for (const value of policy.allowedCommands ?? []) {
|
|
171
|
+
if (typeof value === "string" && value.trim()) allowedCommands.add(value.trim());
|
|
172
|
+
}
|
|
173
|
+
return { allowedCommands: [...allowedCommands], policyPath, source: "environment+project" };
|
|
174
|
+
} catch {
|
|
175
|
+
return {
|
|
176
|
+
allowedCommands: [...allowedCommands],
|
|
177
|
+
policyPath,
|
|
178
|
+
source: allowedCommands.size > 0 ? "environment" : "none",
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function parseTrustedCommand(command, promptText, configuration = {}) {
|
|
184
|
+
if (/[;&|`<>]/.test(command)) {
|
|
185
|
+
throw new Error("MA_ARCHITECT_REVIEW_CMD must not contain shell metacharacters");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const parts = splitCommand(command);
|
|
189
|
+
if (parts.length === 0) {
|
|
190
|
+
throw new Error("MA_ARCHITECT_REVIEW_CMD is empty");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (parts[0].includes("=") && !parts[0].includes("/")) {
|
|
194
|
+
throw new Error("MA_ARCHITECT_REVIEW_CMD must start with an executable");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const substituted = parts.map((part) => part.replaceAll("{prompt}", promptText));
|
|
198
|
+
const configured = new Set(configuration.allowedCommands ?? []);
|
|
199
|
+
const commandName = path.basename(substituted[0]);
|
|
200
|
+
if (!configured.has(substituted[0]) && !configured.has(commandName)) {
|
|
201
|
+
throw new Error(
|
|
202
|
+
`MA_ARCHITECT_REVIEW_CMD is not allowlisted: ${substituted[0]}. ` +
|
|
203
|
+
"Add its exact command or basename to MA_ARCHITECT_REVIEW_ALLOWLIST or .ma/architect-review-policy.json.",
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
command: substituted[0],
|
|
208
|
+
args: substituted.slice(1),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function readReviewTimeoutMs() {
|
|
213
|
+
const parsed = Number(process.env.MA_ARCHITECT_REVIEW_TIMEOUT_MS);
|
|
214
|
+
if (!Number.isFinite(parsed) || parsed <= 0) return DEFAULT_REVIEW_TIMEOUT_MS;
|
|
215
|
+
return Math.min(120000, Math.max(1000, Math.floor(parsed)));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function writeReviewReceipt(details) {
|
|
219
|
+
const receiptDir = path.join(
|
|
220
|
+
process.env.MA_ROOT ?? process.cwd(),
|
|
221
|
+
".ma",
|
|
222
|
+
"evidence",
|
|
223
|
+
"architect-review-receipts",
|
|
224
|
+
);
|
|
225
|
+
const safeDetails = { ...details };
|
|
226
|
+
for (const key of ["error", "stderr"]) {
|
|
227
|
+
if (safeDetails[key])
|
|
228
|
+
safeDetails[key] = maskSensitiveText(String(safeDetails[key])).sanitizedText;
|
|
229
|
+
}
|
|
230
|
+
await fs.mkdir(receiptDir, { recursive: true }).catch(() => {});
|
|
231
|
+
await fs
|
|
232
|
+
.writeFile(
|
|
233
|
+
path.join(receiptDir, `review-${Date.now()}-${process.pid}.json`),
|
|
234
|
+
`${JSON.stringify(
|
|
235
|
+
{
|
|
236
|
+
schemaVersion: "0.1.0",
|
|
237
|
+
record_type: "architect_review_receipt",
|
|
238
|
+
generatedAt: new Date().toISOString(),
|
|
239
|
+
...safeDetails,
|
|
240
|
+
},
|
|
241
|
+
null,
|
|
242
|
+
2,
|
|
243
|
+
)}\n`,
|
|
244
|
+
{ mode: 0o600 },
|
|
245
|
+
)
|
|
246
|
+
.catch(() => {});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function buildArchitectReviewEnv(extraEnv = {}) {
|
|
250
|
+
const passthroughKeys = new Set([
|
|
251
|
+
"PATH",
|
|
252
|
+
"HOME",
|
|
253
|
+
"USERPROFILE",
|
|
254
|
+
"TMPDIR",
|
|
255
|
+
"TMP",
|
|
256
|
+
"TEMP",
|
|
257
|
+
"LANG",
|
|
258
|
+
"LC_ALL",
|
|
259
|
+
"SYSTEMROOT",
|
|
260
|
+
"COMSPEC",
|
|
261
|
+
"MA_ROOT",
|
|
262
|
+
]);
|
|
263
|
+
const env = {};
|
|
264
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
265
|
+
if (passthroughKeys.has(key)) {
|
|
266
|
+
env[key] = value;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return { ...env, ...extraEnv };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function splitCommand(command) {
|
|
273
|
+
const parts = [];
|
|
274
|
+
let current = "";
|
|
275
|
+
let quote = null;
|
|
276
|
+
let escaping = false;
|
|
277
|
+
|
|
278
|
+
for (const char of command) {
|
|
279
|
+
if (escaping) {
|
|
280
|
+
current += char;
|
|
281
|
+
escaping = false;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (char === "\\") {
|
|
286
|
+
escaping = true;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (quote) {
|
|
291
|
+
if (char === quote) {
|
|
292
|
+
quote = null;
|
|
293
|
+
} else {
|
|
294
|
+
current += char;
|
|
295
|
+
}
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (char === "'" || char === '"') {
|
|
300
|
+
quote = char;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (/\s/.test(char)) {
|
|
305
|
+
if (current) {
|
|
306
|
+
parts.push(current);
|
|
307
|
+
current = "";
|
|
308
|
+
}
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
current += char;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (escaping) {
|
|
316
|
+
current += "\\";
|
|
317
|
+
}
|
|
318
|
+
if (quote) {
|
|
319
|
+
throw new Error("MA_ARCHITECT_REVIEW_CMD has an unterminated quote");
|
|
320
|
+
}
|
|
321
|
+
if (current) {
|
|
322
|
+
parts.push(current);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return parts;
|
|
326
|
+
}
|