mindvest-atlas 0.4.3 → 0.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindvest-atlas",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "description": "Atlas CLI \u2014 OAuth login, tool calls, and live alert/flow streaming for the Atlas trading API",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,8 +15,8 @@ import { requestJson } from '../api/client.js';
15
15
  import { runStream } from '../util/stream-loop.js';
16
16
  import { color, eprintln } from '../util/ui.js';
17
17
  import {
18
- DEFAULT_TIMEOUT_MS, computerName, jobEnv, machineId, osLabel,
19
- staleness, summarize, tail, workspace, workspaceRoot,
18
+ DEFAULT_TIMEOUT_MS, computerName, jobEnv, listJobFiles, machineId, osLabel,
19
+ readJobFile, staleness, summarize, tail, workspace, workspaceRoot,
20
20
  } from '../remote-control.js';
21
21
  import fs from 'node:fs';
22
22
  import path from 'node:path';
@@ -95,6 +95,27 @@ function runOnce(argv, dir, env, timeoutMs) {
95
95
  });
96
96
  }
97
97
 
98
+ /** Send one answer back up. Pass-through: the server relays it to whoever asked
99
+ * and stores none of it, which is what keeps a file's contents on this computer
100
+ * even while someone is looking at them. */
101
+ async function answer(requestId, payload) {
102
+ try {
103
+ await requestJson(API.remoteAnswer, { method: 'POST', body: { request_id: requestId, ...payload } });
104
+ } catch (err) {
105
+ eprintln(color.dim(` ↳ could not answer: ${err.message}`));
106
+ }
107
+ }
108
+
109
+ /** A question from the web about THIS computer's workspace. Read-only and
110
+ * confined to the jobs folder: it can list what is there and show one file; it
111
+ * cannot write, delete, or reach outside. */
112
+ async function handleAsk(ask, root) {
113
+ if (!ask?.request_id) return;
114
+ if (ask.op === 'list') return answer(ask.request_id, { ok: true, jobs: listJobFiles(root) });
115
+ if (ask.op === 'read') return answer(ask.request_id, readJobFile(ask.job || '', ask.path || '', root));
116
+ return answer(ask.request_id, { ok: false, error: 'Unknown request.' });
117
+ }
118
+
98
119
  async function runJob(job, root, timeoutMs) {
99
120
  const name = job.name || job.automation_id || 'job';
100
121
  const started = Date.now();
@@ -177,6 +198,8 @@ export async function remoteControlCommand(args) {
177
198
  onEvent: async ({ event, payload }) => {
178
199
  if (event === 'job' || event === 'message' || event === 'run') {
179
200
  await runJob(payload, root, timeoutMs);
201
+ } else if (event === 'ask') {
202
+ await handleAsk(payload, root);
180
203
  }
181
204
  },
182
205
  });
package/src/config.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import path from 'node:path';
3
3
  import os from 'node:os';
4
4
 
5
- export const VERSION = '0.4.3';
5
+ export const VERSION = '0.5.0';
6
6
  export const DEFAULT_BASE_URL = 'https://atlasmcp.finmanagerai.com';
7
7
  export const DEFAULT_SCOPE = 'atlas broker';
8
8
  export const CLIENT_NAME = 'Atlas CLI';
@@ -41,6 +41,7 @@ export const API = {
41
41
  remoteJobs: '/api/v1/remote-computer/jobs',
42
42
  remotePending: '/api/v1/remote-computer/pending',
43
43
  remoteStatus: '/api/v1/remote-computer/status',
44
+ remoteAnswer: '/api/v1/remote-computer/answer',
44
45
  localRuns: '/api/local/runs',
45
46
  };
46
47
 
@@ -218,3 +218,68 @@ export function summarize(output, ok) {
218
218
  if (!lines.length) return ok ? 'Ran and finished.' : null;
219
219
  return lines[lines.length - 1].slice(0, 2000);
220
220
  }
221
+
222
+ /** Files bigger than this are not read into a browser: a job's script or log is
223
+ * a few KB, and anything past it is a data file the viewer would choke on. */
224
+ export const MAX_VIEW_BYTES = 256 * 1024;
225
+ const SKIP_DIRS = new Set(['.venv', 'node_modules', '__pycache__']);
226
+
227
+ /**
228
+ * Every job folder and what is in it, as plain metadata.
229
+ *
230
+ * Names, sizes and times only — never contents. Confined to the workspace: this
231
+ * answers a request that arrived over the network, so it must not be able to
232
+ * describe anything outside the folder Atlas was given.
233
+ */
234
+ export function listJobFiles(root) {
235
+ const base = path.join(workspaceRoot(root), SCRIPTS_DIR);
236
+ let jobs = [];
237
+ try {
238
+ jobs = fs.readdirSync(base, { withFileTypes: true })
239
+ .filter((d) => d.isDirectory()).map((d) => d.name).sort();
240
+ } catch { return []; }
241
+ return jobs.map((job) => {
242
+ const files = [];
243
+ const walk = (dir, rel) => {
244
+ if (files.length >= 200) return;
245
+ let entries = [];
246
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
247
+ for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
248
+ if (SKIP_DIRS.has(e.name)) continue;
249
+ const abs = path.join(dir, e.name);
250
+ const r = rel ? `${rel}/${e.name}` : e.name;
251
+ if (e.isDirectory()) { walk(abs, r); continue; }
252
+ try {
253
+ const st = fs.statSync(abs);
254
+ files.push({ path: r, size: st.size, modified: st.mtimeMs / 1000 });
255
+ } catch { /* vanished mid-walk */ }
256
+ if (files.length >= 200) return;
257
+ }
258
+ };
259
+ walk(path.join(base, job), '');
260
+ return { job, files };
261
+ });
262
+ }
263
+
264
+ /**
265
+ * One file's text, or a reason it cannot be shown.
266
+ *
267
+ * The path is resolved and then checked to still be INSIDE the job's folder,
268
+ * which is what stops `../../.ssh/id_rsa` — a request arriving over the network
269
+ * must not reach a file the user never put in the workspace.
270
+ */
271
+ export function readJobFile(job, rel, root) {
272
+ const base = path.resolve(path.join(workspaceRoot(root), SCRIPTS_DIR, safeSlug(job)));
273
+ const target = path.resolve(path.join(base, rel));
274
+ if (target !== base && !target.startsWith(base + path.sep)) {
275
+ return { ok: false, error: "That file is outside this job's folder." };
276
+ }
277
+ try {
278
+ if (fs.statSync(target).size > MAX_VIEW_BYTES) {
279
+ return { ok: false, error: 'That file is too large to show here.' };
280
+ }
281
+ return { ok: true, text: fs.readFileSync(target, 'utf8') };
282
+ } catch {
283
+ return { ok: false, error: 'That file could not be read.' };
284
+ }
285
+ }