repoburg 1.3.300 → 1.3.301

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.
@@ -10,6 +10,7 @@ const express_1 = __importDefault(require("express"));
10
10
  const fs_extra_1 = __importDefault(require("fs-extra"));
11
11
  const os_1 = __importDefault(require("os"));
12
12
  const path_1 = __importDefault(require("path"));
13
+ const static_files_1 = require("../utils/static-files");
13
14
  const collector_1 = require("./collector");
14
15
  const retention_1 = require("./retention");
15
16
  /**
@@ -59,7 +60,7 @@ function createRecorderRouter(opts = {}) {
59
60
  // resolution (two levels from daemon/[src|dist]) explicitly.
60
61
  const distPath = opts.distPath ?? path_1.default.resolve(__dirname, '../../../recorder/dist');
61
62
  if (fs_extra_1.default.existsSync(distPath)) {
62
- router.use(express_1.default.static(distPath));
63
+ router.use((0, static_files_1.serveStatic)(distPath));
63
64
  }
64
65
  else {
65
66
  console.warn(`[recorder] bundle not found at ${distPath} — script not served`);
@@ -19,6 +19,7 @@ exports.createPaneFrontendRouter = createPaneFrontendRouter;
19
19
  const express_1 = __importDefault(require("express"));
20
20
  const path_1 = __importDefault(require("path"));
21
21
  const fs_extra_1 = __importDefault(require("fs-extra"));
22
+ const static_files_1 = require("./utils/static-files");
22
23
  /** Resolve the pane frontend dist from the daemon's module directory. */
23
24
  function resolvePaneFrontendDist(fromDir) {
24
25
  return path_1.default.resolve(fromDir, '../../agent-pane/frontend/dist');
@@ -35,10 +36,10 @@ function createPaneFrontendRouter(distPath) {
35
36
  }
36
37
  const router = express_1.default.Router();
37
38
  // Static assets with fallthrough so the SPA fallback handles routes.
38
- router.use(express_1.default.static(distPath, { fallthrough: true }));
39
+ router.use((0, static_files_1.serveStatic)(distPath, { fallthrough: true }));
39
40
  // SPA fallback: any GET that no earlier route handled becomes the app.
40
41
  router.get('*', (_req, res) => {
41
- res.sendFile(indexHtml);
42
+ (0, static_files_1.sendFile)(res, indexHtml);
42
43
  });
43
44
  return router;
44
45
  }
@@ -32,7 +32,7 @@ function request(server, method, url) {
32
32
  const req = http_1.default.request({ host: '127.0.0.1', port, method, path: url }, (res) => {
33
33
  let data = '';
34
34
  res.on('data', (chunk) => (data += chunk));
35
- res.on('end', () => resolve({ status: res.statusCode ?? 0, body: data, type: res.headers['content-type'] }));
35
+ res.on('end', () => resolve({ status: res.statusCode ?? 0, body: data, type: res.headers['content-type'], headers: res.headers }));
36
36
  });
37
37
  req.on('error', reject);
38
38
  req.end();
@@ -66,6 +66,13 @@ describe('staticServing', () => {
66
66
  expect(res.status).toBe(200);
67
67
  expect(res.body).toContain('pane-spa');
68
68
  });
69
+ it('validates the SPA index by its bytes, not by the mtime npm pins', async () => {
70
+ for (const url of ['/', '/sessions/abc-123']) {
71
+ const res = await request(server, 'GET', url);
72
+ expect(res.headers.etag).toMatch(/^"/);
73
+ expect(res.headers['last-modified']).toBeUndefined();
74
+ }
75
+ });
69
76
  it('never shadows /api paths (handled by the pane delegate first)', async () => {
70
77
  const res = await request(server, 'GET', '/api/sessions');
71
78
  expect(res.status).toBe(503);
@@ -205,6 +205,9 @@ describe('replay UI', () => {
205
205
  let r = await get(s, '/');
206
206
  expect(r.status).toBe(200);
207
207
  expect(r.body).toContain('replay ui');
208
+ // An ETag of the bytes: npm pins every mtime, so express's own stays the same across releases.
209
+ expect(r.headers.etag).toMatch(/^"/);
210
+ expect(r.headers['last-modified']).toBeUndefined();
208
211
  expect((await get(s, '/assets/app.js')).body).toBe('console.log(1)');
209
212
  r = await request(s, 'GET', MOUNT);
210
213
  expect(r.status).toBe(301);
@@ -14,6 +14,7 @@ exports.viewerLoader = viewerLoader;
14
14
  const express_1 = __importDefault(require("express"));
15
15
  const fs_1 = __importDefault(require("fs"));
16
16
  const path_1 = __importDefault(require("path"));
17
+ const static_files_1 = require("../../utils/static-files");
17
18
  const PLACEHOLDER = `<!doctype html>
18
19
  <meta charset="utf-8" />
19
20
  <title>tabtape</title>
@@ -28,7 +29,7 @@ function uiRouter(dist) {
28
29
  // Checked per request: building the UI does not need a daemon restart.
29
30
  const built = () => !!appDir && fs_1.default.existsSync(path_1.default.join(appDir, 'index.html'));
30
31
  if (appDir) {
31
- const serve = express_1.default.static(appDir, { fallthrough: true, index: 'index.html' });
32
+ const serve = (0, static_files_1.serveStatic)(appDir, { fallthrough: true, index: 'index.html' });
32
33
  router.use((req, res, next) => (built() ? serve(req, res, next) : next()));
33
34
  }
34
35
  router.get(['/', '/index.html'], (_req, res) => {
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.contentEtag = contentEtag;
7
+ exports.serveStatic = serveStatic;
8
+ exports.sendFile = sendFile;
9
+ /**
10
+ * Static files from the daemon's npm package (the pane SPA, the tabtape
11
+ * replay UI, the recorder bundle) with cache validators that follow their
12
+ * content.
13
+ *
14
+ * npm packs every file with the mtime 1985-10-26, so express's own
15
+ * validators (a weak ETag of size and mtime, Last-Modified = mtime) only
16
+ * change when a file's size does. A Vite index.html keeps its size from one
17
+ * release to the next (only the hashes in the asset names change): a browser
18
+ * that cached it under the previous release got 304, kept the old page and
19
+ * asked for assets the new release does not have, so the page stayed blank.
20
+ *
21
+ * Here the ETag is a hash of the file's bytes and there is no Last-Modified:
22
+ * a 304 means the file really is the same.
23
+ */
24
+ const crypto_1 = __importDefault(require("crypto"));
25
+ const express_1 = __importDefault(require("express"));
26
+ const fs_1 = __importDefault(require("fs"));
27
+ const etags = new Map();
28
+ /** Strong ETag of the file's bytes; read again only when the file changes on disk. */
29
+ function contentEtag(file, stat = fs_1.default.statSync(file)) {
30
+ // Rewriting a file moves its ctime even when the mtime is set back to 1985.
31
+ const stamp = `${stat.ino}:${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}`;
32
+ const known = etags.get(file);
33
+ if (known?.stamp === stamp)
34
+ return known.etag;
35
+ const etag = `"${crypto_1.default.createHash('sha256').update(fs_1.default.readFileSync(file)).digest('base64url')}"`;
36
+ etags.set(file, { stamp, etag });
37
+ return etag;
38
+ }
39
+ /** express.static with content ETags instead of express's own validators. */
40
+ function serveStatic(root, options = {}) {
41
+ return express_1.default.static(root, {
42
+ ...options,
43
+ etag: false,
44
+ lastModified: false,
45
+ setHeaders: (res, file, stat) => {
46
+ res.setHeader('ETag', contentEtag(file, stat));
47
+ options.setHeaders?.(res, file, stat);
48
+ },
49
+ });
50
+ }
51
+ /** res.sendFile with the same validators. */
52
+ function sendFile(res, file) {
53
+ let etag = null;
54
+ try {
55
+ etag = contentEtag(file);
56
+ }
57
+ catch {
58
+ // missing or unreadable: sendFile reports it
59
+ }
60
+ res.sendFile(file, { etag: false, lastModified: false, headers: etag ? { ETag: etag } : {} });
61
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const express_1 = __importDefault(require("express"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const http_1 = __importDefault(require("http"));
9
+ const os_1 = __importDefault(require("os"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const static_files_1 = require("./static-files");
12
+ // npm packs every file with this mtime, whatever the release.
13
+ const NPM_MTIME = new Date('1985-10-26T08:15:00Z');
14
+ const dirs = [];
15
+ const servers = [];
16
+ /** A release's dist: index.html of the same size each time, only the asset hash differs. */
17
+ function release(hash) {
18
+ const dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'static-files-'));
19
+ dirs.push(dir);
20
+ const file = path_1.default.join(dir, 'index.html');
21
+ fs_1.default.writeFileSync(file, `<script type="module" src="/assets/index-${hash}.js"></script>`);
22
+ fs_1.default.utimesSync(file, NPM_MTIME, NPM_MTIME);
23
+ return dir;
24
+ }
25
+ async function serve(dir) {
26
+ const app = (0, express_1.default)();
27
+ app.use((0, static_files_1.serveStatic)(dir));
28
+ app.get('/route', (_req, res) => (0, static_files_1.sendFile)(res, path_1.default.join(dir, 'index.html')));
29
+ const server = app.listen(0, '127.0.0.1');
30
+ servers.push(server);
31
+ await new Promise((resolve) => server.once('listening', resolve));
32
+ return server.address().port;
33
+ }
34
+ function get(port, p, headers = {}) {
35
+ return new Promise((resolve, reject) => {
36
+ http_1.default
37
+ .get({ host: '127.0.0.1', port, path: p, headers }, (res) => {
38
+ let body = '';
39
+ res.on('data', (c) => (body += c));
40
+ res.on('end', () => resolve({ status: res.statusCode ?? 0, headers: res.headers, body }));
41
+ })
42
+ .on('error', reject);
43
+ });
44
+ }
45
+ afterAll(async () => {
46
+ await Promise.all(servers.map((s) => new Promise((resolve) => s.close(resolve))));
47
+ for (const d of dirs)
48
+ fs_1.default.rmSync(d, { recursive: true, force: true });
49
+ });
50
+ describe('static files', () => {
51
+ it('answers 304 only while the bytes are the same', async () => {
52
+ const port = await serve(release('AAAAAAAA'));
53
+ for (const p of ['/', '/route']) {
54
+ const first = await get(port, p);
55
+ expect(first.status).toBe(200);
56
+ expect(first.headers.etag).toMatch(/^"[\w-]+"$/);
57
+ expect(first.headers['last-modified']).toBeUndefined();
58
+ expect((await get(port, p, { 'If-None-Match': first.headers.etag })).status).toBe(304);
59
+ }
60
+ });
61
+ it('gives a browser that cached the previous release the new index.html', async () => {
62
+ const before = await serve(release('AAAAAAAA'));
63
+ const cached = await get(before, '/');
64
+ const after = await serve(release('BBBBBBBB'));
65
+ // What express used to send for both releases: size and the npm mtime.
66
+ const oldEtag = `W/"${cached.body.length.toString(16)}-${NPM_MTIME.getTime().toString(16)}"`;
67
+ for (const p of ['/', '/route']) {
68
+ for (const etag of [cached.headers.etag, oldEtag]) {
69
+ const r = await get(after, p, { 'If-None-Match': etag, 'If-Modified-Since': NPM_MTIME.toUTCString() });
70
+ expect(r.status).toBe(200);
71
+ expect(r.body).toContain('index-BBBBBBBB.js');
72
+ }
73
+ expect((await get(after, p, { 'If-Modified-Since': NPM_MTIME.toUTCString() })).status).toBe(200);
74
+ }
75
+ });
76
+ it('hashes a file again when it is replaced in place', () => {
77
+ const dir = release('AAAAAAAA');
78
+ const file = path_1.default.join(dir, 'index.html');
79
+ const a = (0, static_files_1.contentEtag)(file);
80
+ expect((0, static_files_1.contentEtag)(file)).toBe(a);
81
+ const next = path_1.default.join(dir, 'next.html');
82
+ fs_1.default.writeFileSync(next, fs_1.default.readFileSync(file, 'utf8').replace('AAAAAAAA', 'BBBBBBBB'));
83
+ fs_1.default.utimesSync(next, NPM_MTIME, NPM_MTIME);
84
+ fs_1.default.renameSync(next, file);
85
+ expect((0, static_files_1.contentEtag)(file)).not.toBe(a);
86
+ });
87
+ it('leaves a missing file to sendFile', async () => {
88
+ const dir = release('AAAAAAAA');
89
+ const port = await serve(dir);
90
+ fs_1.default.rmSync(path_1.default.join(dir, 'index.html'));
91
+ expect((await get(port, '/route')).status).toBe(404);
92
+ });
93
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repoburg",
3
- "version": "1.3.300",
3
+ "version": "1.3.301",
4
4
  "description": "A local AI-powered software developer assistant that runs on your own machine.",
5
5
  "author": "Celal Ertug",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "tree": "65394d713550af26f228f3b5da2af01f7c696ebe",
3
- "commit": "e53fbc170227cfd3b8d76067a30db5e40d7f8807",
3
+ "commit": "1d66a1c06d5a26bf30ee62f4cb3007c5c5a4a282",
4
4
  "dirty": false,
5
- "repoburgVersion": "1.3.300",
6
- "builtAt": "2026-11-04T05:32:54.760Z"
5
+ "repoburgVersion": "1.3.301",
6
+ "builtAt": "2026-11-05T04:34:49.093Z"
7
7
  }
@@ -58,5 +58,5 @@
58
58
  ]
59
59
  }
60
60
  ],
61
- "version_name": "0.6.0 (repoburg 1.3.300, e53fbc1)"
61
+ "version_name": "0.6.0 (repoburg 1.3.301, 1d66a1c)"
62
62
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "tree": "65394d713550af26f228f3b5da2af01f7c696ebe",
3
- "commit": "e53fbc170227cfd3b8d76067a30db5e40d7f8807",
3
+ "commit": "1d66a1c06d5a26bf30ee62f4cb3007c5c5a4a282",
4
4
  "dirty": false,
5
- "repoburgVersion": "1.3.300",
6
- "builtAt": "2026-11-04T05:32:54.760Z"
5
+ "repoburgVersion": "1.3.301",
6
+ "builtAt": "2026-11-05T04:34:49.093Z"
7
7
  }