@conarium-ai/core 0.2.6 → 0.2.8

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +34 -0
  3. package/SECURITY.md +79 -41
  4. package/bin/conarium-console.mjs +86 -4
  5. package/bin/conarium-init.mjs +1 -1
  6. package/dist/console-handoff.d.ts +24 -0
  7. package/dist/console-handoff.d.ts.map +1 -0
  8. package/dist/console-handoff.js +49 -0
  9. package/dist/console-handoff.js.map +1 -0
  10. package/dist/console-notify.d.ts +6 -0
  11. package/dist/console-notify.d.ts.map +1 -0
  12. package/dist/console-notify.js +41 -0
  13. package/dist/console-notify.js.map +1 -0
  14. package/dist/console-ready.d.ts +5 -0
  15. package/dist/console-ready.d.ts.map +1 -0
  16. package/dist/console-ready.js +27 -0
  17. package/dist/console-ready.js.map +1 -0
  18. package/dist/console-receipts.d.ts +30 -0
  19. package/dist/console-receipts.d.ts.map +1 -0
  20. package/dist/console-receipts.js +137 -0
  21. package/dist/console-receipts.js.map +1 -0
  22. package/dist/console-shortcut.d.ts +49 -0
  23. package/dist/console-shortcut.d.ts.map +1 -0
  24. package/dist/console-shortcut.js +176 -0
  25. package/dist/console-shortcut.js.map +1 -0
  26. package/dist/console.d.ts +6 -0
  27. package/dist/console.d.ts.map +1 -1
  28. package/dist/console.js +150 -19
  29. package/dist/console.js.map +1 -1
  30. package/dist/http.d.ts.map +1 -1
  31. package/dist/http.js +9 -0
  32. package/dist/http.js.map +1 -1
  33. package/dist/keys.js +1 -1
  34. package/dist/keys.js.map +1 -1
  35. package/dist/receipt-view.d.ts +89 -0
  36. package/dist/receipt-view.d.ts.map +1 -0
  37. package/dist/receipt-view.js +317 -0
  38. package/dist/receipt-view.js.map +1 -0
  39. package/dist/receipt.d.ts +14 -0
  40. package/dist/receipt.d.ts.map +1 -1
  41. package/dist/receipt.js +39 -0
  42. package/dist/receipt.js.map +1 -1
  43. package/examples/per-user-identity/mint-token.mjs +3 -2
  44. package/package.json +2 -2
  45. package/public/app.js +119 -7
  46. package/public/index.html +28 -0
  47. package/public/style.css +16 -0
package/CHANGELOG.md CHANGED
@@ -2,7 +2,37 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- Nothing yet — 0.2.6 is the current cut.
5
+ - **Console Makbuzlar tab.** Lists `audit.receiptSink` newest-first, opens the
6
+ same receipt HTML as `/proof`, and writes **zincir sağlam** / **kırık (satır N)**.
7
+ Renderer is `src/receipt-view.ts` — demo must not keep a second copy.
8
+ - **`conarium-console --install-shortcut` / `--uninstall-shortcut`.**
9
+ Desktop / Applications / XDG launcher for the existing loopback console.
10
+ Double-click waits until the port listens, then opens the browser with a
11
+ one-time `/handoff` nonce (≤30s). The long-lived token is not put in the
12
+ URL. Auth and CSRF are unchanged for Bearer clients.
13
+ - **HTTP gateway returns 404 (plain text) for `/.well-known/*`.** Public
14
+ demo has no OAuth. A 302+HTML catch-all made MCP clients treat the
15
+ redirect body as authorization-server metadata. Caddy must still 404
16
+ these paths before its catch-all; this is defense in depth.
17
+
18
+ ## 0.2.7 — 2026-08-14
19
+
20
+ CodeQL #16 was real. `mint-token.mjs` wrote the per-user token file at
21
+ the process umask (usually 0644) and only then `chmod 0600`. The window
22
+ is the product's identity store. The file is now born with `mode: 0o600`;
23
+ `chmod` remains a backstop for an already-wide file. The same birth
24
+ permission is applied to `writeKeyPairFiles` (private PEM) and
25
+ `conarium-init`'s signing key.
26
+
27
+ Console config saves go through a same-directory temp file + `rename`
28
+ so a crash cannot leave a half-written policy.
29
+
30
+ ### Fixed
31
+
32
+ - **Token / signing-key files no longer exist world-readable, even briefly.**
33
+ - **Console `POST /api/config` is an atomic replace.**
34
+
35
+ **Not published. Not deployed to Hetzner.**
6
36
 
7
37
  ## 0.2.6 — 2026-08-14
8
38
 
package/README.md CHANGED
@@ -380,6 +380,40 @@ npm start
380
380
  `conarium-init` refuses to overwrite existing files unless you pass `--force`.
381
381
  It never prints the private key — only its path.
382
382
 
383
+ ### Desktop shortcut for the console
384
+
385
+ The policy editor is `npx conarium-console`. It still binds `127.0.0.1` and
386
+ still requires a token. These two commands only add a door on the desktop:
387
+
388
+ ```bash
389
+ npx conarium-console --install-shortcut
390
+ npx conarium-console --uninstall-shortcut
391
+ ```
392
+
393
+ | | |
394
+ |--|--|
395
+ | Windows | `.lnk` on the desktop (console window minimized) |
396
+ | macOS | `~/Applications/Conarium Console.app` |
397
+ | Linux | `~/.local/share/applications/conarium-console.desktop` |
398
+
399
+ Double-click starts the same console, waits until the port is listening, then
400
+ opens your browser. The token is not put in the URL; a one-time nonce (≤30s)
401
+ is exchanged for a session cookie. If a shortcut with that name already exists,
402
+ a `-2` suffix is used instead of overwriting.
403
+
404
+ Export `CONARIUM_CONSOLE_TOKEN` before `--install-shortcut` so the launcher
405
+ can read it from `~/.conarium/console.token` (created `0600`). The shortcut
406
+ file itself does not contain the token.
407
+
408
+ No `.ico` / `.icns` / 512px PNG ships in this package yet, so the shortcut
409
+ has no custom icon.
410
+
411
+ The console **Makbuzlar** tab lists signed receipts from `audit.receiptSink`
412
+ (newest first) and shows the same receipt HTML as `demo.conarium.dev/proof`.
413
+ It verifies the hash chain and writes **zincir sağlam** or **kırık (satır N)**.
414
+ If the sink is empty or unset, it says so — it does not invent a sample
415
+ receipt. Audit Logs remain the unsigned playground trail; they are not receipts.
416
+
383
417
  When the package is on npm, the same binaries will ship in the tarball
384
418
  (`conarium-init`, `conarium-doctor`, `conarium-verify`, `conarium-suggest-policy`).
385
419
  Until then, run them from this repository as above.
package/SECURITY.md CHANGED
@@ -168,47 +168,85 @@ this reason — the scope was narrowed to be correct, not to make the number sma
168
168
 
169
169
  ## CodeQL findings, triaged
170
170
 
171
- CodeQL ran for the first time on 2026-08-12 and raised twelve alerts. Each was
172
- checked against the code rather than accepted or dismissed on sight. One was real
173
- and is fixed; the rest are false positives and are dismissed in the Security tab
174
- with the reasoning recorded there, not silently closed.
175
-
176
- **Fixed — `js/missing-rate-limiting` in `src/console.ts` (4 alerts).** The console
177
- had no rate limit. It binds to `127.0.0.1` and requires a token plus a CSRF header,
178
- so the exposure was narrow — but `CONARIUM_CONSOLE_HOST` can publish it, and in that
179
- configuration nothing slowed a token brute force. A limiter now runs **before**
180
- authentication, deliberately: in `src/http.ts` the limit runs *after* auth so an
181
- unauthorized flood cannot burn a real client's budget, whereas here the thing being
182
- protected is the token itself, and a limit placed after auth would never count the
183
- failed attempts. Same library, opposite order, different reason. Test: case `4b` in
184
- `test/security_hardening_14.mjs`, which sends deliberately wrong tokens.
185
-
186
- One honest wrinkle: **CodeQL still flags these four after the fix.** The analysis
187
- re-ran on the fixed commit and the alerts moved to the new line numbers but stayed
188
- open, because the query looks for a recognised middleware and ours is hand-written —
189
- exactly the situation as the `anchor-service` alerts below. They are dismissed with
190
- that stated on each one. If you are auditing this, do not read "12 dismissed" as
191
- "12 non-issues": one of them was real, and the fix is in `270ac54` with a test that
192
- fails without it.
193
-
194
- **False positive — `js/xss-through-dom` (2 alerts, dismissed 2026-08-12).** Those
195
- alerts pointed at a marketing `index.html` that no longer lives in this
196
- repository. The site is `conarium.dev` (private `nexus` repo). The demo SQL box
197
- there still goes through `hlsql()` → `esc()` before `innerHTML`.
198
-
199
- **False positive — `js/missing-rate-limiting` in `src/anchor-service.ts` (2 alerts).**
200
- The service does rate limit, per owner, returning 429 (`src/anchor-service.ts:135-188`).
201
- The limiter is hand-written rather than a recognised middleware, so the query does
202
- not match it.
203
-
204
- **False positive — `js/http-to-file-access` in `src/anchor-service.ts` (1 alert).**
205
- The write target is the fixed configured `storePath`; the record id is server-generated
206
- (`randomBytes(9)`), and `req.params.id` is only ever used to *search* stored records,
207
- never to build a path. There is no traversal.
208
-
209
- **False positive — `js/file-system-race` in `scripts/` and `bin/` (3 alerts).** These
210
- are developer and CLI tools. Exploiting the check-then-use window requires local write
211
- access to the same filesystem, at which point the tool is not the weakest link.
171
+ Measured **2026-08-14** against `main` (`4be8e82`, after the 0.2.7 fixes and a
172
+ fresh CodeQL run): **0 open**, **17 dismissed**, every dismissal carrying its
173
+ reasoning in the Security tab. The numbers are that query, not a remembered
174
+ total. A stale count is the same class of lie this product exists to refuse.
175
+
176
+ ⚠️ **Alert numbers are not stable.** A fix moves a line, CodeQL closes the old
177
+ alert and opens a new one at the new position — during 0.2.7 the `mint-token`
178
+ finding closed as `#16` and reopened as `#18`, and the new regression test
179
+ raised `#19` of its own. Read the classes below, not the numbers.
180
+
181
+ ### What was actually found
182
+
183
+ **`js/file-system-race` in `examples/per-user-identity/mint-token.mjs` — real, fixed in 0.2.7.**
184
+ The file was created at the process umask (usually 0644) and only then
185
+ `chmod 0600`. Between those two calls, per-user identity tokens were readable
186
+ by another local account. That file is the store behind "a shared credential
187
+ does not name a person". It now births with `writeFileSync(..., { mode: 0o600 })`;
188
+ `chmod` is a backstop, not the only defence. The same birth permission is on
189
+ `src/keys.ts` (`writeKeyPairFiles` private PEM) and `bin/conarium-init.mjs`
190
+ (signing key). Measured on ext4 with `umask 0022`: with `mode` present the file
191
+ is born `600` even when `chmod` is disabled; with `mode` removed it is born
192
+ `644`. Do not read "everything dismissed" as "nothing was real".
193
+
194
+ **`js/missing-rate-limiting` in `src/console.ts`.**
195
+ False positive. A limiter runs **before** authentication, deliberately: in
196
+ `src/http.ts` the limit runs *after* auth so an unauthorized flood cannot burn
197
+ a real client's budget; here the thing being protected is the token itself
198
+ (`test/security_hardening_14.mjs` case `4b`). The query looks for a recognised
199
+ middleware; ours is hand-written. Dismiss is a GitHub Security-tab action, not
200
+ a code change.
201
+
202
+ **`js/file-system-race` in `src/console.ts` (config save).** Weak, local tool —
203
+ but 0.2.7 closed the practical hole anyway: the save is now temp-file + `rename`
204
+ in the same directory, so a crash cannot leave a half-written policy. This alert
205
+ **closed on its own** after the fix; it is the one finding here that CodeQL
206
+ agreed was resolved rather than dismissed.
207
+
208
+ **`js/file-system-race` in `bin/conarium-suggest-policy.mjs`.** New file, new
209
+ alert — that is normal. The tool is read-only (`--sql`), wrapped in try/catch,
210
+ and refuses to write config. There is no privileged sink after the check, so the
211
+ window has no consequence. Noise.
212
+
213
+ **`js/file-system-race` in `test/mint_token_mode.mjs`.** The regression test for
214
+ the finding above: it creates a file in a temp directory and stats it to assert
215
+ the `0600` birth permission. Dismissed as *used in tests*.
216
+
217
+ ### Earlier rounds
218
+
219
+ First CodeQL run was 2026-08-12 (twelve alerts). One of those (`js/missing-rate-limiting`
220
+ on the console with **no** limiter) was real and was fixed in `270ac54`. The
221
+ others were false positives and are dismissed in the Security tab with the
222
+ reasoning recorded there:
223
+
224
+ **`js/missing-rate-limiting` in `src/console.ts` (the original four, plus
225
+ follow-ups).** Limiter exists; query does not see a hand-written one.
226
+
227
+ **`js/xss-through-dom` (2, dismissed 2026-08-12).** Marketing `index.html` that
228
+ no longer lives in this repository. The site is `conarium.dev` (private `nexus`
229
+ repo). The demo SQL box there still goes through `hlsql()` → `esc()` before
230
+ `innerHTML`.
231
+
232
+ **`js/missing-rate-limiting` in `src/anchor-service.ts` (2).** The service does
233
+ rate limit, per owner, returning 429. Hand-written limiter.
234
+
235
+ **`js/http-to-file-access` in `src/anchor-service.ts` (1).** The write target is
236
+ the fixed configured `storePath`; the record id is server-generated
237
+ (`randomBytes(9)`), and `req.params.id` is only ever used to *search* stored
238
+ records, never to build a path.
239
+
240
+ **`js/file-system-race` in `scripts/` and `bin/` (3).** Developer and CLI tools.
241
+ Exploiting the check-then-use window requires local write access to the same
242
+ filesystem, at which point the tool is not the weakest link.
243
+
244
+ If you are auditing this, do not read "17 dismissed" as "17 non-issues". Two of
245
+ them were real and were fixed, not argued away: the console with no rate limiter
246
+ (`270ac54`), and the token file that was born world-readable and narrowed
247
+ afterwards (0.2.7). Everything else is dismissed with its reasoning attached,
248
+ and a dismissal in this repository means *"we looked and wrote down why"*, not
249
+ *"we closed it"*.
212
250
 
213
251
  ## Secrets in git history
214
252
 
@@ -44,9 +44,13 @@ if (has('--help') || has('-h')) {
44
44
  the same file the gateway reads)
45
45
  --port <n> default 3000 (or CONARIUM_CONSOLE_PORT)
46
46
  --host <ip> default 127.0.0.1 (or CONARIUM_CONSOLE_HOST)
47
+ --install-shortcut put a desktop / Applications / .desktop launcher
48
+ --uninstall-shortcut remove the launcher this command created
49
+ --launch start, wait until the port listens, open the browser
50
+ (used by the shortcut; do not put a token in the URL)
47
51
  --help this text
48
52
 
49
- Required:
53
+ Required to start (not to install a shortcut):
50
54
  CONARIUM_CONSOLE_TOKEN bearer token for every request
51
55
  Optional:
52
56
  CONARIUM_CONSOLE_CSRF_TOKEN defaults to the console token
@@ -65,6 +69,8 @@ const die = (code, msg, fix) => {
65
69
 
66
70
  const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)))
67
71
  const consoleJs = join(pkgRoot, 'dist', 'console.js')
72
+ const shortcutJs = join(pkgRoot, 'dist', 'console-shortcut.js')
73
+ const thisBin = fileURLToPath(import.meta.url)
68
74
  if (!existsSync(consoleJs)) {
69
75
  die(
70
76
  2,
@@ -73,6 +79,39 @@ if (!existsSync(consoleJs)) {
73
79
  )
74
80
  }
75
81
 
82
+ if (has('--install-shortcut') || has('--uninstall-shortcut')) {
83
+ const { installShortcut, uninstallShortcut } = await import(pathToFileURL(shortcutJs).href)
84
+ try {
85
+ if (has('--uninstall-shortcut')) {
86
+ const { removed } = uninstallShortcut()
87
+ console.error(removed ? `conarium-console: removed ${removed}` : 'conarium-console: no shortcut recorded')
88
+ process.exit(0)
89
+ }
90
+ const workdir = process.cwd()
91
+ const token = process.env.CONARIUM_CONSOLE_TOKEN?.trim() || ''
92
+ const out = installShortcut({
93
+ scriptPath: thisBin,
94
+ workdir,
95
+ token: token || undefined,
96
+ })
97
+ console.error(`conarium-console: shortcut at ${out.dest}${out.collided ? ' (name was taken, used -2)' : ''}`)
98
+ if (!token) {
99
+ console.error('conarium-console: CONARIUM_CONSOLE_TOKEN was not set; the shortcut will need it in the environment, or re-run install with the token exported')
100
+ }
101
+ process.exit(0)
102
+ } catch (e) {
103
+ die(2, `shortcut: ${e.message}`)
104
+ }
105
+ }
106
+
107
+ if (has('--launch')) {
108
+ const { loadLaunchToken, loadShortcutState } = await import(pathToFileURL(shortcutJs).href)
109
+ const persisted = loadLaunchToken()
110
+ if (persisted && !process.env.CONARIUM_CONSOLE_TOKEN?.trim()) {
111
+ process.env.CONARIUM_CONSOLE_TOKEN = persisted
112
+ }
113
+ }
114
+
76
115
  if (!process.env.CONARIUM_CONSOLE_TOKEN?.trim()) {
77
116
  die(
78
117
  2,
@@ -121,7 +160,15 @@ if (!loopback && process.env.CONARIUM_CONSOLE_PUBLIC !== '1') {
121
160
  // inside the package, which for an installed user is the wrong file twice over:
122
161
  // it is not the one the gateway reads, and npm overwrites it on every install.
123
162
  // Default to the same path the gateway uses — conarium.config.json in cwd.
124
- const configFile = resolve(process.cwd(), valueOf('--config', 'conarium.config.json'))
163
+ let workdir = process.cwd()
164
+ if (has('--launch') && !has('--config')) {
165
+ const { loadShortcutState } = await import(pathToFileURL(shortcutJs).href)
166
+ const st = loadShortcutState()
167
+ if (st?.workdir && existsSync(join(st.workdir, 'conarium.config.json'))) {
168
+ workdir = st.workdir
169
+ }
170
+ }
171
+ const configFile = resolve(workdir, valueOf('--config', 'conarium.config.json'))
125
172
  if (!existsSync(configFile)) {
126
173
  die(
127
174
  2,
@@ -132,14 +179,49 @@ if (!existsSync(configFile)) {
132
179
 
133
180
  try {
134
181
  const { createConsoleApp } = await import(pathToFileURL(consoleJs).href)
135
- const app = createConsoleApp({ configFile })
136
- app.listen(port, host, () => {
182
+ const launch = has('--launch')
183
+ let handoff
184
+ let lastPresence = 0
185
+ if (launch) {
186
+ const { createHandoffStore } = await import(pathToFileURL(join(pkgRoot, 'dist', 'console-handoff.js')).href)
187
+ handoff = createHandoffStore()
188
+ }
189
+ const app = createConsoleApp({
190
+ configFile,
191
+ handoff,
192
+ onPresence: launch ? () => { lastPresence = Date.now() } : undefined,
193
+ })
194
+ const server = app.listen(port, host, async () => {
137
195
  console.error(`[conarium-console] http://${host}:${port} — editing ${configFile}`)
138
196
  console.error(
139
197
  loopback
140
198
  ? '[conarium-console] loopback only — tunnel in over SSH if you are not on this machine'
141
199
  : '[conarium-console] WARNING: bound to a non-loopback address on purpose (CONARIUM_CONSOLE_PUBLIC=1)',
142
200
  )
201
+ if (!launch) return
202
+ const { waitForListen } = await import(pathToFileURL(join(pkgRoot, 'dist', 'console-ready.js')).href)
203
+ const { openBrowser, notifyLaunchError } = await import(pathToFileURL(join(pkgRoot, 'dist', 'console-notify.js')).href)
204
+ try {
205
+ await waitForListen(host, port, { timeoutMs: 15_000 })
206
+ const nonce = handoff.issue()
207
+ openBrowser(`http://${host}:${port}/handoff?n=${encodeURIComponent(nonce)}`)
208
+ const started = Date.now()
209
+ const watch = setInterval(() => {
210
+ if (lastPresence && Date.now() - lastPresence > 8_000) {
211
+ clearInterval(watch)
212
+ server.close(() => process.exit(0))
213
+ }
214
+ if (!lastPresence && Date.now() - started > 30_000) {
215
+ clearInterval(watch)
216
+ notifyLaunchError('The console started but the browser never opened a session.')
217
+ server.close(() => process.exit(2))
218
+ }
219
+ }, 1000)
220
+ watch.unref()
221
+ } catch (err) {
222
+ notifyLaunchError(err.message)
223
+ server.close(() => process.exit(2))
224
+ }
143
225
  })
144
226
  } catch (e) {
145
227
  // Anything that goes wrong before we are listening is a start failure, not a
@@ -127,7 +127,7 @@ if (!NO_KEYS) {
127
127
  const publicPem = pair.publicKey.export({ type: 'spki', format: 'pem' }).toString()
128
128
  keyId = keyIdFromPublicPem(publicPem)
129
129
  try {
130
- writeFileSync(signingKeyPath, signingPem, writeOpts)
130
+ writeFileSync(signingKeyPath, signingPem, { ...writeOpts, mode: 0o600 })
131
131
  writeFileSync(publicPath, publicPem, writeOpts)
132
132
  writeFileSync(signingKeyIdPath, keyId + '\n', writeOpts)
133
133
  writeFileSync(publicKeyIdPath, keyId + '\n', writeOpts)
@@ -0,0 +1,24 @@
1
+ export declare const HANDOFF_TTL_MS = 30000;
2
+ export interface HandoffEntry {
3
+ exp: number;
4
+ used: boolean;
5
+ }
6
+ export declare function createHandoffStore(opts?: {
7
+ ttlMs?: number;
8
+ now?: () => number;
9
+ }): {
10
+ issue: () => string;
11
+ consume: (n: string) => boolean;
12
+ size: () => number;
13
+ };
14
+ export interface ConsoleSession {
15
+ csrf: string;
16
+ }
17
+ export declare function createSessionStore(): {
18
+ create: () => {
19
+ id: string;
20
+ csrf: string;
21
+ };
22
+ get: (id: string) => ConsoleSession | null;
23
+ };
24
+ //# sourceMappingURL=console-handoff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-handoff.d.ts","sourceRoot":"","sources":["../src/console-handoff.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,QAAS,CAAA;AAEpC,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,OAAO,CAAA;CACd;AAED,wBAAgB,kBAAkB,CAAC,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAAO;iBAKhE,MAAM;iBAMJ,MAAM,KAAG,OAAO;;EAerC;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;CACb;AAED,wBAAgB,kBAAkB;kBAGb;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;cAO9B,MAAM,KAAG,cAAc,GAAG,IAAI;EAMhD"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * One-time handoff nonce for the desktop launcher.
3
+ * The long-lived console token never goes in a URL.
4
+ */
5
+ import { randomBytes } from 'node:crypto';
6
+ export const HANDOFF_TTL_MS = 30_000;
7
+ export function createHandoffStore(opts = {}) {
8
+ const ttl = opts.ttlMs ?? HANDOFF_TTL_MS;
9
+ const now = opts.now ?? Date.now;
10
+ const map = new Map();
11
+ function issue() {
12
+ const n = randomBytes(24).toString('base64url');
13
+ map.set(n, { exp: now() + ttl, used: false });
14
+ return n;
15
+ }
16
+ function consume(n) {
17
+ if (!n)
18
+ return false;
19
+ const e = map.get(n);
20
+ if (!e)
21
+ return false;
22
+ if (e.used)
23
+ return false;
24
+ if (now() > e.exp) {
25
+ map.delete(n);
26
+ return false;
27
+ }
28
+ e.used = true;
29
+ map.delete(n);
30
+ return true;
31
+ }
32
+ return { issue, consume, size: () => map.size };
33
+ }
34
+ export function createSessionStore() {
35
+ const map = new Map();
36
+ function create() {
37
+ const id = randomBytes(24).toString('base64url');
38
+ const csrf = randomBytes(24).toString('base64url');
39
+ map.set(id, { csrf });
40
+ return { id, csrf };
41
+ }
42
+ function get(id) {
43
+ if (!id)
44
+ return null;
45
+ return map.get(id) ?? null;
46
+ }
47
+ return { create, get };
48
+ }
49
+ //# sourceMappingURL=console-handoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-handoff.js","sourceRoot":"","sources":["../src/console-handoff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAA;AAOpC,MAAM,UAAU,kBAAkB,CAAC,OAA+C,EAAE;IAClF,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,IAAI,cAAc,CAAA;IACxC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAA;IAChC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAwB,CAAA;IAE3C,SAAS,KAAK;QACZ,MAAM,CAAC,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;QAC/C,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QAC7C,OAAO,CAAC,CAAA;IACV,CAAC;IAED,SAAS,OA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 +1,6 @@
1
+ export declare function notifyLaunchError(message: string, opts?: {
2
+ platform?: NodeJS.Platform;
3
+ home?: string;
4
+ }): void;
5
+ export declare function openBrowser(url: string, platform?: NodeJS.Platform): void;
6
+ //# sourceMappingURL=console-notify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-notify.d.ts","sourceRoot":"","sources":["../src/console-notify.ts"],"names":[],"mappings":"AAQA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,IAAI,CAoBjH;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,IAAI,CAU3F"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Show a launch failure to a human. No silent exit.
3
+ */
4
+ import { spawnSync } from 'node:child_process';
5
+ import { writeBorn0600 } from './console-shortcut.js';
6
+ import { homedir } from 'node:os';
7
+ import { join } from 'node:path';
8
+ export function notifyLaunchError(message, opts = {}) {
9
+ const platform = opts.platform ?? process.platform;
10
+ const home = opts.home ?? process.env.CONARIUM_CONSOLE_HOME ?? homedir();
11
+ const log = join(home, '.conarium', 'console-launch.log');
12
+ try {
13
+ writeBorn0600(log, `${new Date().toISOString()} ${message}\n`);
14
+ }
15
+ catch { /* still try a dialog */ }
16
+ if (platform === 'win32') {
17
+ const ps = `Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('${message.replace(/'/g, "''")}', 'Conarium Console')`;
18
+ spawnSync('powershell.exe', ['-NoProfile', '-Command', ps], { stdio: 'ignore' });
19
+ return;
20
+ }
21
+ if (platform === 'darwin') {
22
+ spawnSync('osascript', ['-e', `display dialog ${JSON.stringify(message)} with title "Conarium Console" buttons {"OK"}`], { stdio: 'ignore' });
23
+ return;
24
+ }
25
+ const zenity = spawnSync('zenity', ['--error', `--text=${message}`, '--title=Conarium Console'], { stdio: 'ignore' });
26
+ if (zenity.status === 0)
27
+ return;
28
+ spawnSync('notify-send', ['Conarium Console', message], { stdio: 'ignore' });
29
+ }
30
+ export function openBrowser(url, platform = process.platform) {
31
+ if (platform === 'win32') {
32
+ spawnSync('cmd', ['/c', 'start', '', url], { stdio: 'ignore' });
33
+ return;
34
+ }
35
+ if (platform === 'darwin') {
36
+ spawnSync('open', [url], { stdio: 'ignore' });
37
+ return;
38
+ }
39
+ spawnSync('xdg-open', [url], { stdio: 'ignore' });
40
+ }
41
+ //# sourceMappingURL=console-notify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-notify.js","sourceRoot":"","sources":["../src/console-notify.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,UAAU,iBAAiB,CAAC,OAAe,EAAE,OAAsD,EAAE;IACzG,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAA;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,EAAE,CAAA;IACxE,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,oBAAoB,CAAC,CAAA;IACzD,IAAI,CAAC;QACH,aAAa,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,OAAO,IAAI,CAAC,CAAA;IAChE,CAAC;IAAC,MAAM,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAEpC,IAAI,QAAQ,KAAK,OAAO,EAAE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;IACR,CAAC;IACD,SAAS,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;AACnD,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare function waitForListen(host: string, port: number, opts?: {
2
+ timeoutMs?: number;
3
+ intervalMs?: number;
4
+ }): Promise<void>;
5
+ //# sourceMappingURL=console-ready.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-ready.d.ts","sourceRoot":"","sources":["../src/console-ready.ts"],"names":[],"mappings":"AAKA,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GACrD,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Wait until a TCP port accepts a connection. No fixed sleep.
3
+ */
4
+ import { createConnection } from 'node:net';
5
+ export async function waitForListen(host, port, opts = {}) {
6
+ const timeoutMs = opts.timeoutMs ?? 15_000;
7
+ const intervalMs = opts.intervalMs ?? 100;
8
+ const start = Date.now();
9
+ while (Date.now() - start < timeoutMs) {
10
+ const ok = await new Promise((resolve) => {
11
+ const sock = createConnection({ host, port });
12
+ const done = (v) => {
13
+ sock.removeAllListeners();
14
+ sock.destroy();
15
+ resolve(v);
16
+ };
17
+ sock.once('connect', () => done(true));
18
+ sock.once('error', () => done(false));
19
+ sock.setTimeout(intervalMs, () => done(false));
20
+ });
21
+ if (ok)
22
+ return;
23
+ await new Promise((r) => setTimeout(r, intervalMs));
24
+ }
25
+ throw new Error(`console did not listen on ${host}:${port} within ${timeoutMs}ms`);
26
+ }
27
+ //# sourceMappingURL=console-ready.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-ready.js","sourceRoot":"","sources":["../src/console-ready.ts"],"names":[],"mappings":"AAAA;;GAEG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AW,SAAS,IAAI,CAAC,CAAA;AACpF,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type Receipt, type ReceiptChainCheck } from './receipt.js';
2
+ export declare const EMPTY_RECEIPTS_MESSAGE = "hen\u00FCz makbuz yok. Gateway `audit.receiptSink` ile \u00E7al\u0131\u015F\u0131yorsa her eri\u015Fim bir sat\u0131r yazar.";
3
+ export declare const NO_SINK_MESSAGE = "hen\u00FCz makbuz yok. `conarium.config.json` i\u00E7inde `audit.receiptSink` yok; denetim kayd\u0131 makbuz de\u011Fildir.";
4
+ export interface ReceiptListItem {
5
+ id: string;
6
+ ts: string;
7
+ actor: string;
8
+ tool: string;
9
+ decision: string;
10
+ maskedCount: number;
11
+ seq: number;
12
+ }
13
+ export interface LoadedReceipts {
14
+ sink: string | null;
15
+ receipts: Receipt[];
16
+ chain: ReceiptChainCheck;
17
+ emptyMessage: string | null;
18
+ }
19
+ export declare function resolveReceiptSink(configFile: string): string | null;
20
+ export declare function readReceiptJsonl(file: string): {
21
+ receipts: Receipt[];
22
+ parseBreak?: number;
23
+ };
24
+ export declare function loadReceiptsForConsole(configFile: string): LoadedReceipts;
25
+ export declare function toListItems(receipts: Receipt[]): ReceiptListItem[];
26
+ export declare function findReceipt(receipts: Receipt[], id: string): Receipt | null;
27
+ /** Public PEM only. Never returns a private key block. */
28
+ export declare function publicPemForPanel(): string | null;
29
+ export declare function verifyCommandFor(sink: string | null): string;
30
+ //# sourceMappingURL=console-receipts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-receipts.d.ts","sourceRoot":"","sources":["../src/console-receipts.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAEvB,MAAM,cAAc,CAAA;AAGrB,eAAO,MAAM,sBAAsB,iIAC0D,CAAA;AAE7F,eAAO,MAAM,eAAe,gIAC+E,CAAA;AAE3G,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,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