my-durable 0.0.75 → 0.0.76

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.
@@ -171,9 +171,21 @@ export interface GitStatus {
171
171
 
172
172
  /** One status for MANY paths — what a session list needs. The per-path cache
173
173
  * keeps repeat polls cheap on big repos. */
174
- export async function gitStatusBatch(paths: string[]): Promise<Record<string, GitStatus>> {
174
+ export async function gitStatusBatch(paths: string[]): Promise<Record<string, GitStatus | { error: string }>> {
175
175
  const unique = [...new Set(paths.filter(Boolean))];
176
- const entries = await Promise.all(unique.map(async (p) => [p, await gitStatus(p)] as const));
176
+ // R21 (index 400s): one failing path (permissions, a git binary error, a
177
+ // timeout on a huge checkout) used to reject the WHOLE batch — every
178
+ // project's chip died with it. Settle each path separately: failures become
179
+ // bounded `{error}` entries the FE caches instead of retry-hammering.
180
+ const entries = await Promise.all(
181
+ unique.map(async (p): Promise<[string, GitStatus | { error: string }]> => {
182
+ try {
183
+ return [p, await gitStatus(p)];
184
+ } catch (e) {
185
+ return [p, { error: String((e as Error)?.message ?? e).slice(0, 120) }];
186
+ }
187
+ }),
188
+ );
177
189
  return Object.fromEntries(entries);
178
190
  }
179
191
 
@@ -14,7 +14,7 @@ import type { DevicePairing } from "./pairing.js";
14
14
 
15
15
  type Async = (req: Request, res: Response) => Promise<unknown>;
16
16
  const route = (fn: Async) => (req: Request, res: Response, next: NextFunction) => fn(req, res).catch(next);
17
- import { gitOp, gitStatus, gitStatusBatch, isNotARepoError, type GitOp } from "./git.js";
17
+ import { gitOp, gitStatus, gitStatusBatch, isNotARepoError, type GitOp, type GitStatus } from "./git.js";
18
18
  const GIT_OPS: GitOp[] = ["diff", "log", "log-list", "fetch", "pull", "push", "switch", "branch", "commit", "stage", "unstage", "discard", "diff-file", "stash-push", "stash-pop", "compare", "merge-abort", "show-files", "ignore", "checkpoint", "checkpoints", "rewind", "resolve", "submodule-update", "pr-create", "pr-list", "pr-merge", "pr-checks", "pr-comment", "worktree-list", "worktree-add", "worktree-remove"];
19
19
 
20
20
  interface Locals {
@@ -180,12 +180,28 @@ export function v1(
180
180
  }));
181
181
  r.post("/git/status-batch", route(async (req, res) => {
182
182
  const raw: string[] = Array.isArray(req.body?.paths) ? req.body.paths.map(String).filter(Boolean).slice(0, 50) : [];
183
- const paths = await Promise.all(raw.map((p) => store.containedPath(p)));
184
- try {
185
- res.json(await gitStatusBatch(paths));
186
- } catch (e) {
187
- throw gitFault(e, paths[0] ?? "");
183
+ // R21 (index 400s): a project left over from OTHER start dirs (device
184
+ // restarted with a narrower sandbox) used to reject the WHOLE batch from
185
+ // Promise.all — every project's chip died with it and the FE retried the
186
+ // doomed request every stale window. Settle containment per path: foreign
187
+ // paths answer a bounded `{error}` entry keyed by the path AS SENT (the
188
+ // FE's cache key), the rest keep their real status.
189
+ const settled = await Promise.all(
190
+ raw.map(async (p): Promise<[string, string | undefined]> => {
191
+ try {
192
+ return [p, await store.containedPath(p)];
193
+ } catch {
194
+ return [p, undefined];
195
+ }
196
+ }),
197
+ );
198
+ const contained = settled.filter((e): e is [string, string] => e[1] !== undefined).map(([, c]) => c);
199
+ const statuses = await gitStatusBatch(contained);
200
+ const out: Record<string, GitStatus | { error: string }> = {};
201
+ for (const [p, c] of settled) {
202
+ out[p] = c === undefined ? { error: "path must live under a start dir" } : (statuses[c] ?? { error: "git status unavailable" });
188
203
  }
204
+ res.json(out);
189
205
  }));
190
206
  r.post("/git", route(async (req, res) => {
191
207
  const body = req.body ?? {};
@@ -18,19 +18,50 @@ export interface GitEntry {
18
18
  const entries = new Map<string, GitEntry>();
19
19
  const inflight = new Map<string, Promise<void>>();
20
20
 
21
+ /** A device's git surface is bounded by its start dirs (R21, index 400s): a
22
+ * project left over from OTHER start dirs answers 400 on the device, and
23
+ * asking anyway just spams the console with network errors every stale
24
+ * window. The network frame carries each device's startDirs + platform —
25
+ * pre-check client-side (the device stays the enforcer) and settle such
26
+ * paths locally. Unknown device facts → allow: the device decides. */
27
+ function gitPathAllowed(deviceId: string, path: string): boolean {
28
+ const dev = network.devices.value.find((d) => d.id === deviceId) as
29
+ | { info?: { startDirs?: unknown; platform?: unknown } }
30
+ | undefined;
31
+ const dirs = dev?.info?.startDirs;
32
+ if (!Array.isArray(dirs) || dirs.length === 0) return true;
33
+ const win = String(dev?.info?.platform ?? "").startsWith("win32");
34
+ const norm = (p: string) =>
35
+ win ? p.trim().replace(/\//g, "\\").replace(/\\+$/, "").toLowerCase() : p.trim().replace(/\/+$/, "");
36
+ const a = norm(path);
37
+ return dirs.some((raw) => {
38
+ const b = norm(String(raw));
39
+ return !!b && (a === b || a.startsWith(win ? b + "\\" : b + "/"));
40
+ });
41
+ }
42
+
43
+ /** Settle an entry from either a real status or the batch's `{error}` shape. */
44
+ function settleEntry(e: GitEntry, s: GitStatus | { error: string } | undefined) {
45
+ if (s && typeof (s as { error?: unknown }).error === "string") {
46
+ e.status = null;
47
+ e.error = (s as { error: string }).error;
48
+ } else {
49
+ e.status = (s as GitStatus) ?? null;
50
+ e.error = "";
51
+ }
52
+ e.at = Date.now();
53
+ }
54
+
21
55
  /** Fill MANY folders in one round-trip (session lists want branch-per-cwd).
22
56
  * Decorative by design: a failed batch stays silent — the Git tab is where
23
57
  * errors belong. */
24
58
  export async function ensureGitBatch(deviceId: string, paths: string[]) {
25
- const stale = paths.filter((p) => !fresh(gitEntry(deviceId, p), staleMsForBatch));
59
+ const stale = paths.filter((p) => !fresh(gitEntry(deviceId, p), staleMsForBatch) && gitPathAllowed(deviceId, p));
26
60
  if (!stale.length) return;
27
61
  try {
28
62
  const map = await deviceClient(deviceId).gitStatusBatch(stale, { timeoutMs: 60_000 });
29
63
  for (const [p, s] of Object.entries(map)) {
30
- const e = gitEntry(deviceId, p);
31
- e.status = s;
32
- e.at = Date.now();
33
- e.error = "";
64
+ settleEntry(gitEntry(deviceId, p), s as GitStatus | { error: string });
34
65
  }
35
66
  } catch {
36
67
  /* decorative: never surface batch failures */
@@ -100,6 +131,11 @@ export async function ensureGit(
100
131
  const k = key(deviceId, cwd);
101
132
  const e = gitEntry(deviceId, cwd);
102
133
  if (!force && fresh(e, staleMs)) return;
134
+ // Outside the device's sandbox: settle locally, never send the doomed 400.
135
+ if (!gitPathAllowed(deviceId, cwd)) {
136
+ settleEntry(e, { error: "outside the device's start dirs" });
137
+ return;
138
+ }
103
139
  const running = inflight.get(k);
104
140
  if (running) return running;
105
141
  const first = e.status === null && !e.error;
@@ -576,7 +576,10 @@ if (args.includes("--dev")) {
576
576
  // styles (plus the stylesheet host of the brand fonts), talks only to this hub and cannot be framed.
577
577
  const shellPolicy = [
578
578
  "default-src 'none'",
579
- "script-src 'self'",
579
+ // static.cloudflareinsights.com: Cloudflare Web Analytics auto-injects its
580
+ // beacon into every zone page — blocking it just spams the operator's
581
+ // console with CSP violations on every load.
582
+ "script-src 'self' https://static.cloudflareinsights.com",
580
583
  "style-src 'self' https://fonts.googleapis.com",
581
584
  "font-src https://fonts.gstatic.com",
582
585
  "img-src 'self' data:",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-durable",
3
- "version": "0.0.75",
3
+ "version": "0.0.76",
4
4
  "description": "Durable Pi — the durable agent network: hub web UI, device backend daemon, TUI admin and the shared SDK, packaged as one runnable monorepo install",
5
5
  "license": "MIT",
6
6
  "repository": {