@yahyahammad/venastine 0.1.0
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/.env.example +14 -0
- package/LICENSE +201 -0
- package/NOTICE +14 -0
- package/PRIVACY.md +66 -0
- package/README.md +878 -0
- package/SECURITY.md +88 -0
- package/THIRD_PARTY_NOTICES.md +100 -0
- package/agents/builtin/compactor.md +75 -0
- package/agents/builtin/explore.md +77 -0
- package/agents/builtin/grill-me.md +27 -0
- package/agents/builtin/initializer.md +94 -0
- package/agents/builtin/pipeline-reviewer.md +100 -0
- package/agents/builtin/plan.md +88 -0
- package/agents/builtin/review.md +74 -0
- package/agents/manager.py +195 -0
- package/agents/subagent_tool.py +215 -0
- package/agents/tui_commands.py +136 -0
- package/bin/venastine.mjs +382 -0
- package/config.py +1198 -0
- package/core/__init__.py +0 -0
- package/core/approval.py +115 -0
- package/core/client.py +1548 -0
- package/core/compaction.py +959 -0
- package/core/config_loader.py +1563 -0
- package/core/events.py +61 -0
- package/core/interaction.py +328 -0
- package/core/loop.py +1353 -0
- package/core/memory.py +370 -0
- package/core/model_windows.py +175 -0
- package/core/pipeline_models.py +176 -0
- package/core/reasoning/__init__.py +0 -0
- package/core/reasoning/authorization.py +130 -0
- package/core/reasoning/base.py +219 -0
- package/core/reasoning/confidence_scoring.py +468 -0
- package/core/reasoning/events.py +149 -0
- package/core/reasoning/json_retry.py +219 -0
- package/core/reasoning/orchestrator.py +1382 -0
- package/core/reasoning/output_writer.py +286 -0
- package/core/reasoning/payload_validation.py +398 -0
- package/core/reasoning/pipeline_storage.py +361 -0
- package/core/reasoning/review.py +615 -0
- package/core/reasoning/scholar.py +434 -0
- package/core/reasoning/source_corpus.py +327 -0
- package/core/reasoning/source_scoring.py +855 -0
- package/core/replay.py +167 -0
- package/core/session.py +153 -0
- package/core/workspace_trust.py +207 -0
- package/credentials.py +180 -0
- package/database.py +252 -0
- package/env_secrets.py +77 -0
- package/json_store.py +123 -0
- package/logging_setup.py +185 -0
- package/main.py +1959 -0
- package/mcp_client/__init__.py +15 -0
- package/mcp_client/client.py +499 -0
- package/mcp_client/config.py +379 -0
- package/mcp_client/registration.py +182 -0
- package/memories/manager.py +132 -0
- package/memories/tui_commands.py +232 -0
- package/package.json +73 -0
- package/project_init/config_files.py +278 -0
- package/project_init/doc_sets.py +330 -0
- package/project_init/generator.py +564 -0
- package/project_init/manifest.py +406 -0
- package/project_init/tui_commands.py +144 -0
- package/prompts/__init__.py +0 -0
- package/prompts/annotate.md +14 -0
- package/prompts/assumption_audit.md +27 -0
- package/prompts/claim_extraction.md +34 -0
- package/prompts/completeness.md +18 -0
- package/prompts/confidence_tiers.md +23 -0
- package/prompts/critic_pass.md +24 -0
- package/prompts/final_synthesis.md +13 -0
- package/prompts/initial_generation.md +14 -0
- package/prompts/preliminary_plan.md +23 -0
- package/prompts/revalidate.md +25 -0
- package/prompts/revise.md +15 -0
- package/prompts/source_grounding.md +66 -0
- package/prompts/system_prompts.py +262 -0
- package/prompts/universal_system_prompt +7 -0
- package/prompts/untrusted_content +1 -0
- package/providers.json.example +92 -0
- package/pyproject.toml +100 -0
- package/requirements.txt +72 -0
- package/safety/__init__.py +0 -0
- package/safety/policy_enforcement.py +682 -0
- package/security/__init__.py +0 -0
- package/security/capability.py +177 -0
- package/security/permissions.py +190 -0
- package/security/posture.py +302 -0
- package/security/protected_paths.py +309 -0
- package/security/sandbox.py +985 -0
- package/skills/builtin/crypto/cryptography-verification.md +66 -0
- package/skills/builtin/math/formal-specification.md +67 -0
- package/skills/builtin/math/numerical-methods.md +66 -0
- package/skills/builtin/math/proof-writing.md +61 -0
- package/skills/builtin/research/experiment-design.md +62 -0
- package/skills/builtin/research/literature-review.md +65 -0
- package/skills/builtin/research/reproducibility.md +55 -0
- package/skills/builtin/research/source-evaluation.md +70 -0
- package/skills/builtin/research/statistical-inference.md +63 -0
- package/skills/builtin/research/technical-writing.md +59 -0
- package/skills/builtin/security/cybersecurity-research.md +63 -0
- package/skills/builtin/software/code-review.md +61 -0
- package/skills/builtin/software/debugging.md +61 -0
- package/skills/builtin/software/test-design.md +67 -0
- package/skills/manager.py +138 -0
- package/skills/tui_commands.py +111 -0
- package/storage.py +1005 -0
- package/tools/base.py +305 -0
- package/tools/builtin/__init__.py +0 -0
- package/tools/builtin/_math_common.py +377 -0
- package/tools/builtin/_net_common.py +61 -0
- package/tools/builtin/arxiv.py +223 -0
- package/tools/builtin/ask_user.py +213 -0
- package/tools/builtin/discrete_math.py +134 -0
- package/tools/builtin/fetch_url.py +153 -0
- package/tools/builtin/file_ops.py +412 -0
- package/tools/builtin/geometry.py +148 -0
- package/tools/builtin/get_time.py +20 -0
- package/tools/builtin/linear_algebra.py +155 -0
- package/tools/builtin/load_skill.py +66 -0
- package/tools/builtin/logic.py +96 -0
- package/tools/builtin/pin.py +193 -0
- package/tools/builtin/probability_stats.py +228 -0
- package/tools/builtin/project_docs.py +405 -0
- package/tools/builtin/remember.py +158 -0
- package/tools/builtin/shell.py +461 -0
- package/tools/builtin/symbolic_math.py +119 -0
- package/tools/builtin/todo.py +147 -0
- package/tools/builtin/web_search.py +151 -0
- package/tools/context.py +136 -0
- package/tools/isolation.py +314 -0
- package/tools/registry.py +897 -0
- package/tui/app.py +3423 -0
- package/tui/app.tcss +458 -0
- package/tui/commands.py +61 -0
- package/tui/diffs.py +265 -0
- package/tui/preferences.py +182 -0
- package/tui/ravens.py +146 -0
- package/tui/screens.py +943 -0
- package/tui/themes.py +366 -0
- package/tui/widgets.py +1239 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* bin/venastine.mjs -- the npm entry point (batch 35).
|
|
4
|
+
*
|
|
5
|
+
* npm delivers this project as a FOLDER OF SOURCE, not a binary. This file
|
|
6
|
+
* is the only thing npm can execute, so its whole job is to hand control to
|
|
7
|
+
* the Python that actually implements the harness:
|
|
8
|
+
*
|
|
9
|
+
* find a Python >= 3.11 -> make sure its dependencies exist
|
|
10
|
+
* -> spawn `python <root>/main.py` with the user's argv, cwd and stdio
|
|
11
|
+
*
|
|
12
|
+
* ZERO npm DEPENDENCIES, deliberately. Node stdlib only. The tarball is
|
|
13
|
+
* first-party source and nothing else, which is what lets
|
|
14
|
+
* THIRD_PARTY_NOTICES.md say the npm channel adds no licence surface. Do not
|
|
15
|
+
* add a dependency here without changing that file too.
|
|
16
|
+
*
|
|
17
|
+
* WHAT THIS FILE MUST NEVER DO, and why each one is a real bug and not a
|
|
18
|
+
* style preference:
|
|
19
|
+
*
|
|
20
|
+
* * Never set PYTHONPATH. tools/isolation.py builds its child's PYTHONPATH
|
|
21
|
+
* from the PARENT's resolved sys.path -- "handing the child the paths the
|
|
22
|
+
* parent actually resolved is deterministic". A value injected here would
|
|
23
|
+
* be inherited into that computation and poison it.
|
|
24
|
+
* * Never set AGENT_WORKSPACE. WORKSPACE_DIR is a PERMISSION BOUNDARY, not
|
|
25
|
+
* a storage location: file_ops auto-approves writes inside it and demands
|
|
26
|
+
* approval outside. Redirecting it to a shared home directory would
|
|
27
|
+
* silently auto-approve writes there from every project.
|
|
28
|
+
* * Never install without consent. See ensureRuntime().
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { spawnSync } from 'node:child_process';
|
|
32
|
+
import crypto from 'node:crypto';
|
|
33
|
+
import fs from 'node:fs';
|
|
34
|
+
import os from 'node:os';
|
|
35
|
+
import path from 'node:path';
|
|
36
|
+
import readline from 'node:readline';
|
|
37
|
+
import { fileURLToPath } from 'node:url';
|
|
38
|
+
|
|
39
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
40
|
+
const ROOT = path.dirname(HERE);
|
|
41
|
+
const REQUIREMENTS = path.join(ROOT, 'requirements.txt');
|
|
42
|
+
const MAIN = path.join(ROOT, 'main.py');
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ~/.config/venastine ON EVERY PLATFORM, Windows included.
|
|
46
|
+
*
|
|
47
|
+
* Not %APPDATA%, however Node-idiomatic that would be. The Python half of
|
|
48
|
+
* this directory is already fixed: core/config_loader.py, mcp_client/config.py
|
|
49
|
+
* and core/workspace_trust.py all resolve their user tier with
|
|
50
|
+
* os.path.expanduser("~/.config/venastine"). Splitting one config directory
|
|
51
|
+
* across two locations by platform is the bug this constant exists to avoid.
|
|
52
|
+
*/
|
|
53
|
+
const CONFIG_HOME = path.join(os.homedir(), '.config', 'venastine');
|
|
54
|
+
|
|
55
|
+
const MIN_PYTHON = [3, 11];
|
|
56
|
+
|
|
57
|
+
/** Python floor, in the terms the project already states it in (#144). */
|
|
58
|
+
const PYTHON_FLOOR_MESSAGE =
|
|
59
|
+
`Venastine needs Python ${MIN_PYTHON.join('.')} or newer.\n` +
|
|
60
|
+
'\n' +
|
|
61
|
+
'mcp_client/client.py uses asyncio.timeout (3.11+) and 27 sites use runtime\n' +
|
|
62
|
+
'`X | Y` annotations (3.10+). On an older interpreter the harness installs\n' +
|
|
63
|
+
'and then fails from inside the MCP connect path, which is why this refuses\n' +
|
|
64
|
+
'here instead.\n' +
|
|
65
|
+
'\n' +
|
|
66
|
+
'Install Python 3.11+, or point VENASTINE_PYTHON at one:\n' +
|
|
67
|
+
' VENASTINE_PYTHON=/path/to/python3.12 venastine';
|
|
68
|
+
|
|
69
|
+
function readPackageVersion() {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version;
|
|
72
|
+
} catch {
|
|
73
|
+
return '0.0.0';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Candidate interpreters, best first. The loop takes the first that satisfies
|
|
79
|
+
* the floor, so an old `python3` earlier in the list simply falls through to a
|
|
80
|
+
* newer explicit one rather than failing the launch.
|
|
81
|
+
*/
|
|
82
|
+
function pythonCandidates() {
|
|
83
|
+
if (process.env.VENASTINE_PYTHON) {
|
|
84
|
+
return [{ cmd: process.env.VENASTINE_PYTHON, args: [], explicit: true }];
|
|
85
|
+
}
|
|
86
|
+
if (process.platform === 'win32') {
|
|
87
|
+
// `py -3` is the launcher's newest install; the explicit ones are the
|
|
88
|
+
// fallback for machines without the py launcher on PATH.
|
|
89
|
+
return [
|
|
90
|
+
{ cmd: 'py', args: ['-3'] },
|
|
91
|
+
{ cmd: 'python', args: [] },
|
|
92
|
+
{ cmd: 'python3', args: [] },
|
|
93
|
+
{ cmd: 'py', args: ['-3.13'] },
|
|
94
|
+
{ cmd: 'py', args: ['-3.12'] },
|
|
95
|
+
{ cmd: 'py', args: ['-3.11'] },
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
return [
|
|
99
|
+
{ cmd: 'python3', args: [] },
|
|
100
|
+
{ cmd: 'python3.13', args: [] },
|
|
101
|
+
{ cmd: 'python3.12', args: [] },
|
|
102
|
+
{ cmd: 'python3.11', args: [] },
|
|
103
|
+
{ cmd: 'python', args: [] },
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const PROBE = 'import sys; print("%d.%d" % sys.version_info[:2]); print(sys.executable)';
|
|
108
|
+
|
|
109
|
+
function probe(candidate) {
|
|
110
|
+
const r = spawnSync(candidate.cmd, [...candidate.args, '-c', PROBE], {
|
|
111
|
+
encoding: 'utf8',
|
|
112
|
+
// Windows resolves `py`/`python` through PATHEXT, which needs the shell
|
|
113
|
+
// off but the extension search on -- spawnSync does that for us. What it
|
|
114
|
+
// does NOT do is survive a missing binary, hence the status check below.
|
|
115
|
+
windowsHide: true,
|
|
116
|
+
});
|
|
117
|
+
if (r.status !== 0 || !r.stdout) return null;
|
|
118
|
+
const [version, executable] = r.stdout.trim().split(/\r?\n/);
|
|
119
|
+
if (!version || !executable) return null;
|
|
120
|
+
const [major, minor] = version.split('.').map(Number);
|
|
121
|
+
return { ...candidate, version, executable, major, minor };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function findPython() {
|
|
125
|
+
const rejected = [];
|
|
126
|
+
for (const candidate of pythonCandidates()) {
|
|
127
|
+
const found = probe(candidate);
|
|
128
|
+
if (!found) continue;
|
|
129
|
+
if (found.major > MIN_PYTHON[0] ||
|
|
130
|
+
(found.major === MIN_PYTHON[0] && found.minor >= MIN_PYTHON[1])) {
|
|
131
|
+
return found;
|
|
132
|
+
}
|
|
133
|
+
rejected.push(`${found.executable} (${found.version})`);
|
|
134
|
+
}
|
|
135
|
+
const detail = rejected.length
|
|
136
|
+
? `\n\nFound, but too old: ${rejected.join(', ')}`
|
|
137
|
+
: '\n\nNo Python interpreter was found on PATH.';
|
|
138
|
+
fail(PYTHON_FLOOR_MESSAGE + detail);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function requirementsHash() {
|
|
142
|
+
return crypto.createHash('sha256')
|
|
143
|
+
.update(fs.readFileSync(REQUIREMENTS))
|
|
144
|
+
.digest('hex')
|
|
145
|
+
.slice(0, 12);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The runtime directory is keyed by VERSION AND requirements hash together.
|
|
150
|
+
*
|
|
151
|
+
* Either alone is not enough: a version bump with unchanged pins should reuse
|
|
152
|
+
* the environment, and an edited pin within one version must NOT. Keying on
|
|
153
|
+
* both means every distinct dependency set gets a clean venv instead of a
|
|
154
|
+
* half-migrated one, and switching back to an older install finds its own
|
|
155
|
+
* environment still intact.
|
|
156
|
+
*/
|
|
157
|
+
function runtimePaths() {
|
|
158
|
+
const dir = path.join(CONFIG_HOME, 'runtime', `${readPackageVersion()}-${requirementsHash()}`);
|
|
159
|
+
return {
|
|
160
|
+
dir,
|
|
161
|
+
python: process.platform === 'win32'
|
|
162
|
+
? path.join(dir, 'Scripts', 'python.exe')
|
|
163
|
+
: path.join(dir, 'bin', 'python'),
|
|
164
|
+
// Written LAST, and it -- not the directory -- is what "ready" means. A
|
|
165
|
+
// venv whose pip install died half way exists on disk and would otherwise
|
|
166
|
+
// read as installed, then fail on a missing import at the first model call.
|
|
167
|
+
stamp: path.join(dir, 'venastine-runtime.json'),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function isReady(rt) {
|
|
172
|
+
return fs.existsSync(rt.stamp) && fs.existsSync(rt.python);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function countPins() {
|
|
176
|
+
return fs.readFileSync(REQUIREMENTS, 'utf8')
|
|
177
|
+
.split(/\r?\n/)
|
|
178
|
+
.filter((line) => line.trim() && !line.trim().startsWith('#'))
|
|
179
|
+
.length;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function ask(question) {
|
|
183
|
+
return new Promise((resolve) => {
|
|
184
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
185
|
+
rl.question(question, (answer) => {
|
|
186
|
+
rl.close();
|
|
187
|
+
resolve(/^y(es)?$/i.test(answer.trim()));
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Build the Python environment, only ever with the user's say-so.
|
|
194
|
+
*
|
|
195
|
+
* The consent prompt is not ceremony. This is the one action the launcher
|
|
196
|
+
* takes on its own initiative -- it runs a network install of 17 pinned
|
|
197
|
+
* distributions -- and the project's own rule for that case is D17/D31:
|
|
198
|
+
* show what will run and confirm it. That is also why the bootstrap is here
|
|
199
|
+
* and not in an npm `postinstall` hook, where it would run unannounced and be
|
|
200
|
+
* skipped entirely under `--ignore-scripts`.
|
|
201
|
+
*
|
|
202
|
+
* NOT A TTY AND NO --venastine-yes => REFUSE AND PRINT THE COMMAND. A CI job
|
|
203
|
+
* or a piped invocation must not be able to trigger an unattended install
|
|
204
|
+
* just by being unable to answer.
|
|
205
|
+
*/
|
|
206
|
+
async function ensureRuntime(python, rt, { assumeYes }) {
|
|
207
|
+
if (isReady(rt)) return;
|
|
208
|
+
|
|
209
|
+
const summary =
|
|
210
|
+
'Venastine needs a Python environment (first run).\n' +
|
|
211
|
+
` python : ${python.version} (${python.executable})\n` +
|
|
212
|
+
` venv : ${rt.dir}\n` +
|
|
213
|
+
` install : ${countPins()} pinned packages from requirements.txt\n`;
|
|
214
|
+
|
|
215
|
+
if (!assumeYes) {
|
|
216
|
+
if (!process.stdin.isTTY) {
|
|
217
|
+
fail(
|
|
218
|
+
summary +
|
|
219
|
+
'\nRefusing to install unattended (no terminal to ask in).\n' +
|
|
220
|
+
'Re-run interactively, pass --venastine-yes, or build it yourself:\n' +
|
|
221
|
+
` ${python.executable} -m venv "${rt.dir}"\n` +
|
|
222
|
+
` "${rt.python}" -m pip install -r "${REQUIREMENTS}"`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
process.stdout.write(summary);
|
|
226
|
+
const ok = await ask('Proceed? [y/N] ');
|
|
227
|
+
if (!ok) fail('Cancelled. Nothing was installed.');
|
|
228
|
+
} else {
|
|
229
|
+
process.stdout.write(summary);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
run(python.executable, ['-m', 'venv', rt.dir]);
|
|
234
|
+
run(rt.python, ['-m', 'pip', 'install', '--disable-pip-version-check',
|
|
235
|
+
'-r', REQUIREMENTS]);
|
|
236
|
+
} catch (e) {
|
|
237
|
+
// Leave nothing half-built behind: the next run must start clean rather
|
|
238
|
+
// than inherit a venv that is missing an unknown subset of its packages.
|
|
239
|
+
fs.rmSync(rt.dir, { recursive: true, force: true });
|
|
240
|
+
fail(`Environment setup failed: ${e.message}`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
fs.writeFileSync(rt.stamp, JSON.stringify({
|
|
244
|
+
version: readPackageVersion(),
|
|
245
|
+
requirementsHash: requirementsHash(),
|
|
246
|
+
python: python.executable,
|
|
247
|
+
pythonVersion: python.version,
|
|
248
|
+
createdAt: new Date().toISOString(),
|
|
249
|
+
}, null, 2));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function run(cmd, args) {
|
|
253
|
+
const r = spawnSync(cmd, args, { stdio: 'inherit', windowsHide: true });
|
|
254
|
+
if (r.error) throw r.error;
|
|
255
|
+
if (r.status !== 0) throw new Error(`${path.basename(cmd)} ${args[0]} exited ${r.status}`);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Walks up from cwd the way dotenv's find_dotenv(usecwd=True) now does. */
|
|
259
|
+
function findEnvFile() {
|
|
260
|
+
let dir = process.cwd();
|
|
261
|
+
for (;;) {
|
|
262
|
+
const candidate = path.join(dir, '.env');
|
|
263
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
264
|
+
const parent = path.dirname(dir);
|
|
265
|
+
if (parent === dir) return null;
|
|
266
|
+
dir = parent;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The child's environment: inherit everything, then fill in ONLY what is
|
|
272
|
+
* missing. Every branch here defers to a value the user already set.
|
|
273
|
+
*/
|
|
274
|
+
function childEnv() {
|
|
275
|
+
const env = { ...process.env };
|
|
276
|
+
const cwd = process.cwd();
|
|
277
|
+
|
|
278
|
+
// Credentials. cwd wins, because per-project keys are a real workflow; the
|
|
279
|
+
// user-level file is the fallback that makes a globally-installed CLI
|
|
280
|
+
// usable from directories that have no providers.json of their own.
|
|
281
|
+
if (!env.AGENT_PROVIDERS_FILE && !fs.existsSync(path.join(cwd, 'providers.json'))) {
|
|
282
|
+
const shared = path.join(CONFIG_HOME, 'providers.json');
|
|
283
|
+
if (fs.existsSync(shared)) env.AGENT_PROVIDERS_FILE = shared;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// State. ONE decision drives BOTH variables -- a global database writing to
|
|
287
|
+
// a local log is worse than either arrangement on its own.
|
|
288
|
+
//
|
|
289
|
+
// Why global at all: main.py sets project_path = os.getcwd(), and UserMemory
|
|
290
|
+
// carries `scope` AND `project_path` (M12/D25) precisely so ONE database can
|
|
291
|
+
// tell projects apart. Per-directory databases would put an accidental
|
|
292
|
+
// scoping axis on top of that deliberate one -- `--thread <uuid>` would stop
|
|
293
|
+
// resolving outside the directory it was created in, and a memory saved
|
|
294
|
+
// scope="global" would be global only inside one folder.
|
|
295
|
+
//
|
|
296
|
+
// An existing ./app.db always wins, so running this launcher inside a
|
|
297
|
+
// checkout keeps using the data already there instead of orphaning it.
|
|
298
|
+
if (!env.APP_DB_PATH && !fs.existsSync(path.join(cwd, 'app.db'))) {
|
|
299
|
+
env.APP_DB_PATH = path.join(CONFIG_HOME, 'app.db');
|
|
300
|
+
if (!env.AGENT_LOG_FILE) env.AGENT_LOG_FILE = path.join(CONFIG_HOME, 'logs', 'app.log');
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// AGENT_OUTPUT_DIR is deliberately untouched: research artifacts belong
|
|
304
|
+
// beside the work that prompted them, and nothing reads them back -- the
|
|
305
|
+
// report and claims live in the PipelineRunRecord row, not in output/.
|
|
306
|
+
return env;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function doctor(python, rt) {
|
|
310
|
+
const cwd = process.cwd();
|
|
311
|
+
const env = childEnv();
|
|
312
|
+
const localProviders = path.join(cwd, 'providers.json');
|
|
313
|
+
const lines = [
|
|
314
|
+
`venastine ${readPackageVersion()}`,
|
|
315
|
+
` package root : ${ROOT}`,
|
|
316
|
+
` node : ${process.version}`,
|
|
317
|
+
` python : ${python.version} (${python.executable})`,
|
|
318
|
+
` venv : ${rt.dir}`,
|
|
319
|
+
` venv ready : ${isReady(rt) ? 'yes' : 'no (first run will build it)'}`,
|
|
320
|
+
` cwd : ${cwd}`,
|
|
321
|
+
` providers.json: ${env.AGENT_PROVIDERS_FILE
|
|
322
|
+
|| (fs.existsSync(localProviders) ? localProviders : '(none found)')}`,
|
|
323
|
+
` .env : ${env.AGENT_ENV_FILE || findEnvFile() || '(none found)'}`,
|
|
324
|
+
` app.db : ${env.APP_DB_PATH || path.join(cwd, 'app.db')}`,
|
|
325
|
+
` log file : ${env.AGENT_LOG_FILE || path.join(cwd, 'logs', 'app.log')}`,
|
|
326
|
+
` output dir : ${env.AGENT_OUTPUT_DIR || path.join(cwd, 'output')}`,
|
|
327
|
+
` workspace : ${env.AGENT_WORKSPACE || path.join(cwd, 'workspace')}`,
|
|
328
|
+
];
|
|
329
|
+
process.stdout.write(lines.join('\n') + '\n');
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function fail(message) {
|
|
333
|
+
process.stderr.write(message.replace(/\n?$/, '\n'));
|
|
334
|
+
process.exit(1);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async function main() {
|
|
338
|
+
const argv = process.argv.slice(2);
|
|
339
|
+
|
|
340
|
+
// Launcher-owned flags are PREFIXED because main.py takes a positional
|
|
341
|
+
// `query`: a bare `venastine doctor` would be sent to the model as a
|
|
342
|
+
// research question rather than reaching this file.
|
|
343
|
+
const assumeYes = argv.includes('--venastine-yes');
|
|
344
|
+
const wantDoctor = argv.includes('--venastine-doctor');
|
|
345
|
+
const wantReinstall = argv.includes('--venastine-reinstall');
|
|
346
|
+
const passthrough = argv.filter((a) => !a.startsWith('--venastine-'));
|
|
347
|
+
|
|
348
|
+
const python = findPython();
|
|
349
|
+
const rt = runtimePaths();
|
|
350
|
+
|
|
351
|
+
if (wantReinstall) {
|
|
352
|
+
fs.rmSync(rt.dir, { recursive: true, force: true });
|
|
353
|
+
process.stdout.write(`Removed ${rt.dir}\n`);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (wantDoctor) {
|
|
357
|
+
doctor(python, rt);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
await ensureRuntime(python, rt, { assumeYes });
|
|
362
|
+
|
|
363
|
+
// Let the child own the terminal's interrupt. Without this, Ctrl+C kills
|
|
364
|
+
// the launcher first and the harness loses its chance to shut down.
|
|
365
|
+
process.on('SIGINT', () => {});
|
|
366
|
+
|
|
367
|
+
// main.py BY PATH, so its directory becomes sys.path[0]: the harness relies
|
|
368
|
+
// on the project root being importable (AGENTS.md, "the project root is on
|
|
369
|
+
// sys.path"). stdio:'inherit' is what gives the Textual TUI a real terminal.
|
|
370
|
+
const child = spawnSync(rt.python, [MAIN, ...passthrough], {
|
|
371
|
+
stdio: 'inherit',
|
|
372
|
+
cwd: process.cwd(),
|
|
373
|
+
env: childEnv(),
|
|
374
|
+
windowsHide: false,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
if (child.error) fail(`Could not start the harness: ${child.error.message}`);
|
|
378
|
+
if (child.signal) process.exit(128 + (os.constants.signals[child.signal] || 0));
|
|
379
|
+
process.exit(child.status ?? 1);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
main().catch((e) => fail(e.stack || String(e)));
|