ccdeck 3.81.2 → 3.81.4
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/README.md +6 -4
- package/bin/cli/tui.js +4 -2
- package/dist/web/assets/{BrowserWatchModal-BahEbWu-.js → BrowserWatchModal-C2JIHDVZ.js} +1 -1
- package/dist/web/assets/{IntegrationModal-DzIizEQd.js → IntegrationModal-CO1SrDXf.js} +1 -1
- package/dist/web/assets/{RadioPanel-DKmUHqxX.js → RadioPanel-CQ7ILyIZ.js} +1 -1
- package/dist/web/assets/{TrafficRadar-B2G1nwSK.js → TrafficRadar-KOunicu_.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-M0A1co-v.js → UsageHistoryModal-BXiOEbuk.js} +1 -1
- package/dist/web/assets/{app-uL65pD1B.js → app-0jqgYDft.js} +85 -85
- package/dist/web/assets/{index-4-WbGg1k.js → index-K55Tw-ZZ.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/release-notes.json +39 -5
- package/src/server/codex-live-credentials.mjs +31 -3
- package/src/server/codex-live-rpc.mjs +23 -6
- package/src/server/codex-selection.mjs +4 -1
- package/src/server/codex-windows-private.mjs +10 -0
- package/src/server/codex-windows-private.ps1 +53 -2
- package/src/server/deck-client.mjs +9 -1
- package/src/server/deck-home.mjs +3 -2
- package/src/server/depth-facts.mjs +93 -1
- package/src/server/event-routes.mjs +8 -1
- package/src/server/feature-use.mjs +45 -0
- package/src/server/index.mjs +7 -2
- package/src/server/lan-about.mjs +7 -15
- package/src/server/os-version.mjs +57 -0
- package/src/server/reports.mjs +216 -15
- package/src/server/tui-view.mjs +10 -7
- package/src/server/usage-day.mjs +35 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./app-
|
|
1
|
+
import"./app-0jqgYDft.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))i(e);new MutationObserver(e=>{for(const r of e)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function s(e){const r={};return e.integrity&&(r.integrity=e.integrity),e.referrerPolicy&&(r.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?r.credentials="include":e.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(e){if(e.ep)return;e.ep=!0;const r=s(e);fetch(e.href,r)}})();
|
package/dist/web/index.html
CHANGED
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
document.documentElement.setAttribute("data-density", density === "tightest" || density === "tighter" || density === "compact" || density === "comfortable" ? density : "default");
|
|
78
78
|
})();
|
|
79
79
|
</script>
|
|
80
|
-
<script type="module" crossorigin src="/assets/index-
|
|
81
|
-
<link rel="modulepreload" crossorigin href="/assets/app-
|
|
80
|
+
<script type="module" crossorigin src="/assets/index-K55Tw-ZZ.js"></script>
|
|
81
|
+
<link rel="modulepreload" crossorigin href="/assets/app-0jqgYDft.js">
|
|
82
82
|
<link rel="stylesheet" crossorigin href="/assets/app-BIrh5Q0W.css">
|
|
83
83
|
</head>
|
|
84
84
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccdeck",
|
|
3
|
-
"version": "3.81.
|
|
3
|
+
"version": "3.81.4",
|
|
4
4
|
"description": "Local dashboard for Claude Code and Codex CLI sessions: which Claude Code session needs input, every tool call and Claude Code subagent live, token cost and quota, several Claude accounts. Run npx ccdeck.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/release-notes.json
CHANGED
|
@@ -84,6 +84,8 @@
|
|
|
84
84
|
"without one."
|
|
85
85
|
],
|
|
86
86
|
"//summaries": {
|
|
87
|
+
"3.81.4": "Codex account switching works with Windows sandbox logins",
|
|
88
|
+
"3.81.3": "More reliable Codex switching and quieter account rows",
|
|
87
89
|
"3.81.2": "Codex account switches wait through activity changes",
|
|
88
90
|
"3.81.1": "Codex reconnection and Windows fixes",
|
|
89
91
|
"3.81.0": "Codex accounts on a par with Claude's, Codex over Local network, and ccdeck tui for the whole deck",
|
|
@@ -138,9 +140,41 @@
|
|
|
138
140
|
"3.53.1",
|
|
139
141
|
"3.53.3"
|
|
140
142
|
],
|
|
143
|
+
"3.81.4": [
|
|
144
|
+
{
|
|
145
|
+
"title": "🔄 Switch Codex accounts without another sign-in",
|
|
146
|
+
"body": "On Windows, Switch can use your existing native Codex login while keeping its sandbox permissions unchanged.",
|
|
147
|
+
"priority": "highlight",
|
|
148
|
+
"icon": "accounts"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"title": "🔐 New Windows accounts are ready for switching",
|
|
152
|
+
"body": "Accounts added through + now get private folders from the start, and older native login files are recognized."
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"title": "💬 Clearer account-switching errors",
|
|
156
|
+
"body": "If a login cannot be used safely, ccdeck explains the folder-permission problem and how to continue."
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"3.81.3": [
|
|
160
|
+
{
|
|
161
|
+
"title": "🔄 More reliable Codex account switching",
|
|
162
|
+
"body": "ccdeck retries temporary connection failures before switching the open Codex app.",
|
|
163
|
+
"priority": "highlight",
|
|
164
|
+
"icon": "accounts"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"title": "✨ Quieter account switching",
|
|
168
|
+
"body": "Successful switches no longer leave an extra message under the account row."
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"title": "⌨️ Arrow-key navigation in ccdeck tui",
|
|
172
|
+
"body": "The footer and help now show the left and right arrow keys for moving between tabs."
|
|
173
|
+
}
|
|
174
|
+
],
|
|
141
175
|
"3.81.2": [
|
|
142
176
|
{
|
|
143
|
-
"title": "Codex account switches wait through activity changes",
|
|
177
|
+
"title": "🔄 Codex account switches wait through activity changes",
|
|
144
178
|
"body": "If new work starts while a switch is being prepared, ccdeck now waits and retries safely instead of leaving the switch failed.",
|
|
145
179
|
"priority": "highlight",
|
|
146
180
|
"icon": "accounts"
|
|
@@ -148,7 +182,7 @@
|
|
|
148
182
|
],
|
|
149
183
|
"3.81.1": [
|
|
150
184
|
{
|
|
151
|
-
"title": "Fix Codex sharing on Windows",
|
|
185
|
+
"title": "🔐 Fix Codex sharing on Windows",
|
|
152
186
|
"body": "Codex logins blocked by Windows folder permissions can now be prepared for sharing from the Share dialog.",
|
|
153
187
|
"priority": "highlight",
|
|
154
188
|
"icon": "accounts",
|
|
@@ -156,20 +190,20 @@
|
|
|
156
190
|
"notice": "Secure permissions and share is optional and restricts the selected Codex folders and auth.json to your Windows user, including changes to inherited access for their contents. Your login, settings and active account stay in place. Automatic network sync never changes folder permissions."
|
|
157
191
|
},
|
|
158
192
|
{
|
|
159
|
-
"title": "Windows updates reach the copy you use",
|
|
193
|
+
"title": "🪟 Windows updates reach the copy you use",
|
|
160
194
|
"body": "Global npm updates now target the active installation and confirm that newer files arrived before showing installed.",
|
|
161
195
|
"priority": "highlight",
|
|
162
196
|
"noticeLabel": "Already stuck?",
|
|
163
197
|
"notice": "An older Windows installation already stuck at installed may need one manual update to receive this fix. For the desktop app, run the latest Windows installer. For npm, follow the Windows recovery steps in README, then restart ccdeck. Accounts and settings are kept."
|
|
164
198
|
},
|
|
165
199
|
{
|
|
166
|
-
"title": "Reconnect Codex without a false login-change warning",
|
|
200
|
+
"title": "🔄 Reconnect Codex without a false login-change warning",
|
|
167
201
|
"body": "Connecting to an unchanged Codex account no longer pauses control because of its initial account update.",
|
|
168
202
|
"priority": "highlight",
|
|
169
203
|
"icon": "accounts"
|
|
170
204
|
},
|
|
171
205
|
{
|
|
172
|
-
"title": "See why a shared login did not arrive",
|
|
206
|
+
"title": "📡 See why a shared login did not arrive",
|
|
173
207
|
"body": "The network map now shows a failed transfer instead of promising that the login will arrive next round."
|
|
174
208
|
}
|
|
175
209
|
],
|
|
@@ -9,7 +9,7 @@ import { performance } from 'node:perf_hooks';
|
|
|
9
9
|
import { readCodexSelection } from './codex-selection.mjs';
|
|
10
10
|
import { startEngineRpc } from './codex-engine-rpc.mjs';
|
|
11
11
|
import { pathLookup } from './exec-spec.mjs';
|
|
12
|
-
import { holdWindowsPrivatePath } from './codex-windows-private.mjs';
|
|
12
|
+
import { holdWindowsPrivatePath, snapshotWindowsCodexLogin } from './codex-windows-private.mjs';
|
|
13
13
|
|
|
14
14
|
const MAX_AUTH_BYTES = 1024 * 1024;
|
|
15
15
|
// A loaded Windows host can exceed twelve seconds starting a cold CLI while
|
|
@@ -159,11 +159,19 @@ export async function readLiveCodexCredential(profileId, options = {}) {
|
|
|
159
159
|
const selectionOptions = { store: options.store, env };
|
|
160
160
|
const selection = await readCodexSelection(selectionOptions);
|
|
161
161
|
const profile = profileFrom(selection, profileId);
|
|
162
|
+
if (windows && env.CODEX_HOME && (await lstat(env.CODEX_HOME)).isSymbolicLink()) fail('credential_file_unsafe');
|
|
163
|
+
let nativeHomeSnapshot = false;
|
|
162
164
|
if (windows) {
|
|
163
165
|
try { profileGuard = await holdWindowsPrivatePath(profile.home, { ...options.windowsPrivate, kind: 'directory' }); }
|
|
164
|
-
catch {
|
|
166
|
+
catch {
|
|
167
|
+
// Only the user's original native home may carry Codex sandbox ACLs.
|
|
168
|
+
// Imported/managed profiles keep the existing strict private-path gate.
|
|
169
|
+
if (resolve(profile.home).toLowerCase() !== resolve(selection.originalHome).toLowerCase()) fail('credential_file_unsafe');
|
|
170
|
+
nativeHomeSnapshot = true;
|
|
171
|
+
}
|
|
165
172
|
}
|
|
166
173
|
const captured = await captureProfile(profile);
|
|
174
|
+
if (nativeHomeSnapshot && captured.literal.isSymbolicLink()) fail('credential_file_unsafe');
|
|
167
175
|
const childEnv = { ...env, CODEX_HOME: captured.canonical };
|
|
168
176
|
for (const key of Object.keys(childEnv)) if (/^(OPENAI_API_KEY|CODEX_API_KEY)$/i.test(key)) delete childEnv[key];
|
|
169
177
|
phase = 'native_unavailable';
|
|
@@ -176,13 +184,31 @@ export async function readLiveCodexCredential(profileId, options = {}) {
|
|
|
176
184
|
// Native has finished refreshing and its owned process has stopped. No
|
|
177
185
|
// pre-refresh file version is compared with the legitimately renewed file.
|
|
178
186
|
await revalidateProfile(profile, captured, selection.revision, selectionOptions);
|
|
187
|
+
const snapshotCredential = async () => {
|
|
188
|
+
let auth;
|
|
189
|
+
try { auth = await snapshotWindowsCodexLogin(captured.canonical, options.windowsPrivate); }
|
|
190
|
+
catch { fail('credential_file_unsafe'); }
|
|
191
|
+
// Older native file logins omit auth_mode; the native account/read above
|
|
192
|
+
// has already confirmed ChatGPT auth, not an API-key account.
|
|
193
|
+
if (auth?.auth_mode == null && auth?.tokens && auth.OPENAI_API_KEY == null) auth.auth_mode = 'chatgpt';
|
|
194
|
+
// Bind the copied access token to the selected account read by native
|
|
195
|
+
// Codex. No refresh token is copied, persisted, or renewed by the deck.
|
|
196
|
+
const credential = credentialFrom(auth, account, profileId);
|
|
197
|
+
await revalidateProfile(profile, captured, selection.revision, selectionOptions);
|
|
198
|
+
if (credential.expiresAt <= Date.now()) fail('credential_expired');
|
|
199
|
+
return credential;
|
|
200
|
+
};
|
|
201
|
+
if (nativeHomeSnapshot) return await snapshotCredential();
|
|
179
202
|
phase = 'credential_unavailable';
|
|
180
203
|
const file = join(captured.canonical, 'auth.json');
|
|
181
204
|
let handle, fileGuard;
|
|
182
205
|
try {
|
|
183
206
|
if (windows) {
|
|
184
207
|
try { fileGuard = await holdWindowsPrivatePath(file, { ...options.windowsPrivate, kind: 'file' }); }
|
|
185
|
-
catch {
|
|
208
|
+
catch {
|
|
209
|
+
if (resolve(profile.home).toLowerCase() !== resolve(selection.originalHome).toLowerCase()) fail('credential_file_unsafe');
|
|
210
|
+
return await snapshotCredential();
|
|
211
|
+
}
|
|
186
212
|
}
|
|
187
213
|
const initial = await lstat(file, { bigint: true });
|
|
188
214
|
privateFile(initial, windows);
|
|
@@ -202,6 +228,8 @@ export async function readLiveCodexCredential(profileId, options = {}) {
|
|
|
202
228
|
let auth;
|
|
203
229
|
try { auth = JSON.parse(bytes.subarray(0, length).toString('utf8')); }
|
|
204
230
|
catch { fail('invalid_credentials'); }
|
|
231
|
+
if (windows && resolve(profile.home).toLowerCase() === resolve(selection.originalHome).toLowerCase()
|
|
232
|
+
&& auth?.auth_mode == null && auth?.tokens && auth.OPENAI_API_KEY == null) auth.auth_mode = 'chatgpt';
|
|
205
233
|
const credential = credentialFrom(auth, account, profileId);
|
|
206
234
|
await revalidateProfile(profile, captured, selection.revision, selectionOptions);
|
|
207
235
|
if (!sameFile(opened, await handle.stat({ bigint: true })) || !sameFile(opened, await lstat(file, { bigint: true }))) fail('credential_file_changed');
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// that daemon or takes ownership of its conversations.
|
|
3
3
|
import { execFile } from 'node:child_process';
|
|
4
4
|
import { promisify } from 'node:util';
|
|
5
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
6
|
import { lstat, realpath } from 'node:fs/promises';
|
|
6
7
|
import { dirname, isAbsolute, join, resolve, win32 } from 'node:path';
|
|
7
8
|
import { randomUUID } from 'node:crypto';
|
|
@@ -13,6 +14,27 @@ import { RUNNING_VERSION } from './running-version.mjs';
|
|
|
13
14
|
|
|
14
15
|
export const liveError = code => Object.assign(new Error(code), { code });
|
|
15
16
|
const runFile = promisify(execFile);
|
|
17
|
+
|
|
18
|
+
// Only this read-only probe is safe to replay. In particular, never retry a
|
|
19
|
+
// login or an interrupted turn whose outcome may already have committed.
|
|
20
|
+
export async function probeCodexLiveDaemon(executable, env, options = {}) {
|
|
21
|
+
const spec = spawnSpec(executable, ['app-server', 'daemon', 'version'], options.platform ?? process.platform);
|
|
22
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
23
|
+
try {
|
|
24
|
+
const output = await (options.execFile ?? runFile)(spec.file, spec.args,
|
|
25
|
+
{ ...spec.opts, env, timeout: 5000, maxBuffer: 256 * 1024, windowsHide: true });
|
|
26
|
+
return JSON.parse(output.stdout);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
// Keep diagnostics fixed and credential-free, including native stderr.
|
|
29
|
+
const failure = liveError('native_unavailable');
|
|
30
|
+
failure.cause = liveError(error instanceof SyntaxError ? 'native_probe_invalid_response'
|
|
31
|
+
: error.killed || error.code === 'ETIMEDOUT' ? 'native_probe_timeout' : 'native_probe_command_failed');
|
|
32
|
+
// A missing executable cannot recover by waiting.
|
|
33
|
+
if (attempt === 2 || ['ENOENT', 'EACCES', 'EPERM'].includes(error.code)) throw failure;
|
|
34
|
+
await delay(500);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
16
38
|
const unmaterializedHistory = /^thread [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} is not materialized yet; thread\/turns\/list is unavailable before first user message$/i;
|
|
17
39
|
function rejection(method, error) {
|
|
18
40
|
if (method === 'thread/turns/list' && error?.code === -32600 && unmaterializedHistory.test(error.message ?? '')) return liveError('native_thread_not_materialized');
|
|
@@ -56,12 +78,7 @@ export async function resolveCodexLiveEndpoint(home, options = {}) {
|
|
|
56
78
|
if (!executable) throw liveError('cli_unavailable');
|
|
57
79
|
const env = { ...(options.env ?? process.env), CODEX_HOME: canonical };
|
|
58
80
|
for (const key of Object.keys(env)) if (/^(OPENAI_API_KEY|CODEX_API_KEY)$/i.test(key)) delete env[key];
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const spec = spawnSpec(executable, ['app-server', 'daemon', 'version'], platform);
|
|
62
|
-
const output = await (options.execFile ?? runFile)(spec.file, spec.args, { ...spec.opts, env, timeout: 5000, maxBuffer: 256 * 1024, windowsHide: true });
|
|
63
|
-
result = JSON.parse(output.stdout);
|
|
64
|
-
} catch { throw liveError('native_unavailable'); }
|
|
81
|
+
const result = await probeCodexLiveDaemon(executable, env, { ...options, platform });
|
|
65
82
|
const equalPath = windows ? (a, b) => win32.toNamespacedPath(a).toLowerCase() === win32.toNamespacedPath(b).toLowerCase() : (a, b) => resolve(a) === b;
|
|
66
83
|
if (result.status !== 'running' || !(windows ? win32.isAbsolute : isAbsolute)(result.socketPath ?? '') || !equalPath(result.socketPath, advertised)) throw liveError('native_not_running');
|
|
67
84
|
const version = String(result.appServerVersion ?? result.managedCodexVersion ?? '');
|
|
@@ -261,7 +261,10 @@ export async function addCodexProfile({ label = null, operationId: operation } =
|
|
|
261
261
|
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
262
262
|
if (!(await lstat(root)).isDirectory()) fail('registry_corrupt');
|
|
263
263
|
const home = join(root, randomBytes(16).toString('hex'));
|
|
264
|
-
|
|
264
|
+
if ((options.platform ?? process.platform) === 'win32') {
|
|
265
|
+
const { ensureWindowsPrivateDirectory } = await import('./codex-windows-private.mjs');
|
|
266
|
+
await ensureWindowsPrivateDirectory(home);
|
|
267
|
+
} else await mkdir(home, { mode: 0o700 });
|
|
265
268
|
try {
|
|
266
269
|
const id = await codexProfileId(home);
|
|
267
270
|
state.profiles.push({ id, home, label, managed: true });
|
|
@@ -44,6 +44,16 @@ async function check(path, operation, options) {
|
|
|
44
44
|
export const ensureWindowsPrivateDirectory = async (path, options = {}) => (await check(path, 'ensure', { ...options, kind: 'directory' })).path;
|
|
45
45
|
// Only the explicit Share repair may tighten an existing profile.
|
|
46
46
|
export const protectWindowsCodexLogin = async (path, options = {}) => (await check(path, 'protect-login', { ...options, kind: 'directory' })).path;
|
|
47
|
+
// The caller validates the native identity before using this local snapshot.
|
|
48
|
+
// Do not use check()/result(): login material must never become path metadata.
|
|
49
|
+
export async function snapshotWindowsCodexLogin(path, options = {}) {
|
|
50
|
+
try {
|
|
51
|
+
const spec = command(path, 'snapshot-login', { ...options, kind: 'directory' });
|
|
52
|
+
const output = await (options.execFile ?? runFile)(spec.file, spec.args,
|
|
53
|
+
{ timeout: deadline(options), maxBuffer: 2 * 1024 * 1024, windowsHide: true, shell: false });
|
|
54
|
+
return JSON.parse(output.stdout.replace(/^\uFEFF/, ''));
|
|
55
|
+
} catch { throw unsafe(); }
|
|
56
|
+
}
|
|
47
57
|
export const assertWindowsPrivatePath = async (path, options = {}) => (await check(path, 'check', options)).path;
|
|
48
58
|
export async function inspectWindowsPrivateSocket(path, options = {}) {
|
|
49
59
|
const value = await check(path, 'check', { ...options, kind: 'socket' });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
param(
|
|
2
|
-
[ValidateSet('ensure','check','hold','protect-login')][string]$Operation,
|
|
2
|
+
[ValidateSet('ensure','check','hold','protect-login','snapshot-login')][string]$Operation,
|
|
3
3
|
[Parameter(Mandatory=$true)][string]$TargetPath,
|
|
4
4
|
[ValidateSet('directory','file','socket')][string]$Kind = 'directory'
|
|
5
5
|
)
|
|
@@ -126,6 +126,47 @@ public static class CodexPrivatePath {
|
|
|
126
126
|
return canonical;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
// Explicit local import: the source may be shared with Codex's sandbox.
|
|
130
|
+
// Pin owner-controlled objects and read one immutable regular-file handle.
|
|
131
|
+
// Never alter source permissions and never export a refresh token.
|
|
132
|
+
public static string SnapshotLogin(string path) {
|
|
133
|
+
using (var directory = OpenForProtection(path, true)) {
|
|
134
|
+
Require(Owned(directory));
|
|
135
|
+
string canonical = Canonical(directory);
|
|
136
|
+
using (var file = OpenForProtection(Path.Combine(canonical, "auth.json"), false)) {
|
|
137
|
+
Require(Owned(file));
|
|
138
|
+
FileInfo info; Require(GetFileInformationByHandle(file, out info));
|
|
139
|
+
Require(info.SizeHigh == 0 && info.SizeLow <= 1048576);
|
|
140
|
+
using (var stream = new FileStream(file, FileAccess.Read)) {
|
|
141
|
+
var bytes = new byte[info.SizeLow];
|
|
142
|
+
int offset = 0;
|
|
143
|
+
while (offset < bytes.Length) { int n = stream.Read(bytes, offset, bytes.Length - offset); Require(n > 0); offset += n; }
|
|
144
|
+
return Encoding.UTF8.GetString(bytes);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
static bool Owned(SafeFileHandle h) {
|
|
150
|
+
IntPtr owner, group, dacl, sacl, descriptor;
|
|
151
|
+
Require(GetSecurityInfo(h, 1, 5, out owner, out group, out dacl, out sacl, out descriptor) == 0);
|
|
152
|
+
try {
|
|
153
|
+
Require(owner != IntPtr.Zero && dacl != IntPtr.Zero);
|
|
154
|
+
var bytes = new byte[GetSecurityDescriptorLength(descriptor)];
|
|
155
|
+
Marshal.Copy(descriptor, bytes, 0, bytes.Length);
|
|
156
|
+
var sd = new RawSecurityDescriptor(bytes, 0);
|
|
157
|
+
Require(sd.DiscretionaryAcl != null && sd.DiscretionaryAcl.Count > 0);
|
|
158
|
+
foreach (GenericAce entry in sd.DiscretionaryAcl) {
|
|
159
|
+
var ace = entry as CommonAce;
|
|
160
|
+
Require(ace != null && !ace.IsCallback);
|
|
161
|
+
if (ace.AceQualifier == AceQualifier.AccessAllowed) {
|
|
162
|
+
string sid = ace.SecurityIdentifier.Value;
|
|
163
|
+
Require(sid != "S-1-1-0" && sid != "S-1-5-11" && sid != "S-1-5-32-545" && sid != "S-1-5-7");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return sd.Owner == WindowsIdentity.GetCurrent().User;
|
|
167
|
+
}
|
|
168
|
+
finally { if (descriptor != IntPtr.Zero) LocalFree(descriptor); }
|
|
169
|
+
}
|
|
129
170
|
public static string SocketGeneration(string path) {
|
|
130
171
|
// Node/libuv lstat returns EACCES on Windows AF_UNIX entries. Open only
|
|
131
172
|
// reparse metadata, never follow a symlink/junction or read socket bytes.
|
|
@@ -154,7 +195,17 @@ public static class CodexPrivatePath {
|
|
|
154
195
|
$guards = [System.Collections.Generic.List[System.IDisposable]]::new()
|
|
155
196
|
try {
|
|
156
197
|
$path = [IO.Path]::GetFullPath($TargetPath)
|
|
157
|
-
|
|
198
|
+
if ($Operation -eq 'snapshot-login') {
|
|
199
|
+
$auth = [CodexPrivatePath]::SnapshotLogin($TargetPath) | Microsoft.PowerShell.Utility\ConvertFrom-Json
|
|
200
|
+
if ($null -ne $auth.OPENAI_API_KEY -or $null -eq $auth.tokens) { throw 'unsafe' }
|
|
201
|
+
# Only the access/identity material needed by the live daemon crosses this
|
|
202
|
+
# pipe. Native Codex remains the sole owner of refresh-token rotation.
|
|
203
|
+
$safe = @{ auth_mode = $auth.auth_mode; OPENAI_API_KEY = $null; tokens = @{
|
|
204
|
+
access_token = $auth.tokens.access_token; id_token = $auth.tokens.id_token; account_id = $auth.tokens.account_id
|
|
205
|
+
} }
|
|
206
|
+
[Console]::Out.WriteLine(($safe | Microsoft.PowerShell.Utility\ConvertTo-Json -Depth 4 -Compress))
|
|
207
|
+
exit 0
|
|
208
|
+
} elseif ($Operation -eq 'protect-login') {
|
|
158
209
|
if ($Kind -ne 'directory') { throw 'unsafe' }
|
|
159
210
|
$null = [CodexPrivatePath]::ProtectLogin($path)
|
|
160
211
|
}
|
|
@@ -60,8 +60,15 @@ function newer(a, b) {
|
|
|
60
60
|
* the caller has something to say about. `ok` is the HTTP status, and `body` the
|
|
61
61
|
* parsed JSON or null — the deck's own `{ ok: false, reason }` arrives with a
|
|
62
62
|
* 400 and is worth more to the reader than the status alone, so it is kept.
|
|
63
|
+
*
|
|
64
|
+
* `client` names the command asking, in `x-ccdeck-client`, for the deck's
|
|
65
|
+
* usage tally to count where it was looked at from (feature-use.mjs). Only
|
|
66
|
+
* `ccdeck tui` passes one, "tui"; every other command sends nothing new, and a
|
|
67
|
+
* name that is not a bare lowercase word is not sent.
|
|
63
68
|
*/
|
|
64
|
-
export function askDeck(rec, {
|
|
69
|
+
export function askDeck(rec, {
|
|
70
|
+
method = "GET", path, body = undefined, timeoutMs = ASK_MS, request = httpRequest, client = undefined,
|
|
71
|
+
} = {}) {
|
|
65
72
|
return new Promise(resolve => {
|
|
66
73
|
let settled = false;
|
|
67
74
|
const finish = (v) => { if (!settled) { settled = true; resolve(v); } };
|
|
@@ -79,6 +86,7 @@ export function askDeck(rec, { method = "GET", path, body = undefined, timeoutMs
|
|
|
79
86
|
// an Origin or Sec-Fetch-Site would be judged as a page's, and a page
|
|
80
87
|
// is not who this is.
|
|
81
88
|
"x-ccdeck-token": String(rec.token ?? ""),
|
|
89
|
+
...(typeof client === "string" && /^[a-z][a-z0-9-]{0,31}$/.test(client) ? { "x-ccdeck-client": client } : {}),
|
|
82
90
|
...(payload === null
|
|
83
91
|
? { "content-length": "0" }
|
|
84
92
|
: { "content-type": "application/json", "content-length": String(Buffer.byteLength(payload)) }),
|
package/src/server/deck-home.mjs
CHANGED
|
@@ -114,8 +114,9 @@ export function deckLogDir(platform = process.platform, env = process.env, home
|
|
|
114
114
|
/** %LOCALAPPDATA%, or the path it points at on every Windows since Vista. The
|
|
115
115
|
* fallback is not decoration: a service account or a stripped environment can
|
|
116
116
|
* reach this code with the variable unset, and a deck that throws there is a
|
|
117
|
-
* deck that will not start.
|
|
118
|
-
|
|
117
|
+
* deck that will not start. Also where ccdeck.dev's Windows install leaves its
|
|
118
|
+
* mark (depth-facts.mjs installMarkPath). */
|
|
119
|
+
export function localAppData(env = process.env, home = homedir(), platform = process.platform) {
|
|
119
120
|
const { join } = platform === "win32" ? winPath : posixPath;
|
|
120
121
|
return env.LOCALAPPDATA?.trim() || join(home, "AppData", "Local");
|
|
121
122
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// How the deck holds up and who runs it, for the daily "active" report
|
|
2
|
-
// (reports.mjs),
|
|
2
|
+
// (reports.mjs), how an update arrived, for the "update" one, and how a new
|
|
3
|
+
// install arrived, for the "install" one.
|
|
3
4
|
//
|
|
4
5
|
// EVERY VALUE HERE IS A BUCKET, A CATEGORY OR A SMALL COUNT. How long this run
|
|
5
6
|
// took to start, the usage day's peak memory and how many events the deck took
|
|
@@ -13,6 +14,11 @@
|
|
|
13
14
|
// Each bucket is named by its upper edge: "2s" is over one second and up to
|
|
14
15
|
// two, "512m" over 256 MB and up to 512 MB, "1k" a day of 100 to 999 events.
|
|
15
16
|
|
|
17
|
+
import { readFile, stat, unlink } from "node:fs/promises";
|
|
18
|
+
import { homedir } from "node:os";
|
|
19
|
+
import { posix as posixPath, win32 as winPath } from "node:path";
|
|
20
|
+
import { localAppData } from "./deck-home.mjs";
|
|
21
|
+
|
|
16
22
|
export const LAUNCH_BUCKETS = Object.freeze(["1s", "2s", "5s", "10s", "30s", "later"]);
|
|
17
23
|
const LAUNCH_EDGES_MS = [1000, 2000, 5000, 10_000, 30_000];
|
|
18
24
|
|
|
@@ -30,6 +36,22 @@ export const CODEX_PLANS = Object.freeze(["free", "go", "plus", "pro", "pro-lite
|
|
|
30
36
|
* latest, npm run by hand, or a source checkout pulled. */
|
|
31
37
|
export const UPDATE_VIAS = Object.freeze(["self-update", "desktop-updater", "npx", "npm", "checkout"]);
|
|
32
38
|
|
|
39
|
+
/** How a new install arrived: ccdeck.dev's one-line install on macOS (`curl`)
|
|
40
|
+
* or on Windows (PowerShell's `irm`), an installer downloaded by hand, npx, or
|
|
41
|
+
* npm. A source checkout is not an install anybody chose a way for, and says
|
|
42
|
+
* nothing. */
|
|
43
|
+
export const INSTALL_VIAS = Object.freeze(["curl", "irm", "download", "npx", "npm"]);
|
|
44
|
+
|
|
45
|
+
/** How long the one-line installs' mark stays the answer: a script run a week
|
|
46
|
+
* ago is not how an app first opened today arrived. */
|
|
47
|
+
export const INSTALL_MARK_FRESH_MS = 7 * 24 * 60 * 60 * 1000;
|
|
48
|
+
|
|
49
|
+
/** The words the install scripts write in the mark: install.sh's, install.ps1's. */
|
|
50
|
+
const INSTALL_MARK_WORDS = Object.freeze(["curl", "irm"]);
|
|
51
|
+
|
|
52
|
+
/** Past this many bytes the mark is not one word, and is not read. */
|
|
53
|
+
const INSTALL_MARK_MAX_BYTES = 64;
|
|
54
|
+
|
|
33
55
|
/** The most accounts or paired machines a report says; past it, it says this. */
|
|
34
56
|
export const COUNT_CAP = 50;
|
|
35
57
|
|
|
@@ -108,6 +130,76 @@ export function updateVia({ marker, lastVersion, channel, npx = false, now = new
|
|
|
108
130
|
return undefined;
|
|
109
131
|
}
|
|
110
132
|
|
|
133
|
+
/**
|
|
134
|
+
* How this install arrived, for the "install" that says it.
|
|
135
|
+
*
|
|
136
|
+
* An npm install says it by where this copy runs from: npx's cache, or an
|
|
137
|
+
* install somebody ran npm for. The desktop app is a download unless one of
|
|
138
|
+
* ccdeck.dev's one-line installs says otherwise: its script writes one word in a
|
|
139
|
+
* file (installMarkPath) just before it opens the app, and `mark` is that file
|
|
140
|
+
* as read — `{ content, mtimeMs }`, or null. The word counts only when it is
|
|
141
|
+
* one the scripts write and the file is at most INSTALL_MARK_FRESH_MS old. A
|
|
142
|
+
* source checkout says nothing.
|
|
143
|
+
*/
|
|
144
|
+
export function installVia({ channel, npx = false, mark = null, now = new Date() } = {}) {
|
|
145
|
+
if (channel === "npm") return npx ? "npx" : "npm";
|
|
146
|
+
if (channel !== "desktop") return undefined;
|
|
147
|
+
const word = typeof mark?.content === "string" ? mark.content.trim() : "";
|
|
148
|
+
const age = now.getTime() - Number(mark?.mtimeMs);
|
|
149
|
+
return INSTALL_MARK_WORDS.includes(word) && age <= INSTALL_MARK_FRESH_MS ? word : "download";
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Where ccdeck.dev's one-line installs leave their mark: `install-via`, in
|
|
154
|
+
* ccdeck's folder under Application Support on macOS and under %LOCALAPPDATA%
|
|
155
|
+
* on Windows. Linux has none — the desktop app there is always a download — and
|
|
156
|
+
* gets null.
|
|
157
|
+
*
|
|
158
|
+
* A FIXED PATH, NOT THE DECK'S HOME. The scripts cannot know a CCDECK_HOME or a
|
|
159
|
+
* CLAUDE_CONFIG_DIR, and an app opened by an installer or from Finder does not
|
|
160
|
+
* have the shell's environment anyway, so neither moves it. Joined with the
|
|
161
|
+
* target platform's separator, as deck-home.mjs does, so the Windows answer can
|
|
162
|
+
* be checked from any machine.
|
|
163
|
+
*/
|
|
164
|
+
export function installMarkPath(platform = process.platform, env = process.env, home = homedir()) {
|
|
165
|
+
if (platform === "darwin") return posixPath.join(home, "Library", "Application Support", "ccdeck", "install-via");
|
|
166
|
+
if (platform === "win32") return winPath.join(localAppData(env, home, platform), "ccdeck", "install-via");
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The mark, read and taken away, with the file system handed in so a test
|
|
172
|
+
* needs no file outside its own folder. `read()` answers `{ content, mtimeMs }`,
|
|
173
|
+
* or null for no mark, no place for one on this platform, or one that is not a
|
|
174
|
+
* word (too big, unreadable); `remove()` deletes it. Neither throws: a mark is a
|
|
175
|
+
* nicety on one report, and no report waits on it.
|
|
176
|
+
*/
|
|
177
|
+
export function installMarkFile({
|
|
178
|
+
platform = process.platform, env = process.env, home = homedir(), fs = { readFile, stat, unlink },
|
|
179
|
+
} = {}) {
|
|
180
|
+
return {
|
|
181
|
+
async read() {
|
|
182
|
+
try {
|
|
183
|
+
const path = installMarkPath(platform, env, home);
|
|
184
|
+
if (!path) return null;
|
|
185
|
+
const st = await fs.stat(path);
|
|
186
|
+
if (!(st.size <= INSTALL_MARK_MAX_BYTES)) return null;
|
|
187
|
+
return { content: String(await fs.readFile(path, "utf8")), mtimeMs: st.mtimeMs };
|
|
188
|
+
} catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
async remove() {
|
|
193
|
+
try {
|
|
194
|
+
const path = installMarkPath(platform, env, home);
|
|
195
|
+
if (path) await fs.unlink(path);
|
|
196
|
+
} catch {
|
|
197
|
+
// Gone already, or not this deck's to delete: past a week it is ignored anyway.
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
111
203
|
// ── the deck's own readings ──────────────────────────────────────────────────
|
|
112
204
|
//
|
|
113
205
|
// Read only when an "active" is about to go, never on a hot path, and each by
|
|
@@ -18,6 +18,8 @@ import { SEQ_EPOCH, ringHoldsNewerThan, ringSnapshot } from "./event-ring.mjs";
|
|
|
18
18
|
// The one door every event comes through — see event-pipeline.mjs.
|
|
19
19
|
import { pushEvent } from "./event-pipeline.mjs";
|
|
20
20
|
import { noteToolAudit } from "./tool-audit.mjs";
|
|
21
|
+
// Which surface a page is, counted for the usage reports — see feature-use.mjs.
|
|
22
|
+
import { holdPageSurface } from "./feature-use.mjs";
|
|
21
23
|
import { noteLogWriter } from "./event-log.mjs";
|
|
22
24
|
// Which CLIs this deck watches — see deck-scope.mjs.
|
|
23
25
|
import { deckProviders } from "./deck-scope.mjs";
|
|
@@ -284,7 +286,12 @@ export function handleSse(req, res) {
|
|
|
284
286
|
// is already committed to a 200 and its own failure path is to hang up — so
|
|
285
287
|
// start it, keep the router's contract of returning nothing, and make sure a
|
|
286
288
|
// rejection ends the stream rather than the process.
|
|
287
|
-
|
|
289
|
+
const tray = isTrayRequest(req);
|
|
290
|
+
// A page — the app's window or a browser tab — is that surface used, today
|
|
291
|
+
// and on every day it is still connected when the day turns (feature-use.mjs).
|
|
292
|
+
// The tray connection is a reader, not somebody looking.
|
|
293
|
+
if (!tray) holdPageSurface(req);
|
|
294
|
+
resumeSse(req, res, lastId, { tray }).catch(() => dropSse(res));
|
|
288
295
|
}
|
|
289
296
|
|
|
290
297
|
/**
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
// The server names what a request did: the routes below are actions somebody
|
|
7
7
|
// takes on purpose, never something a page polls, so the request is the use.
|
|
8
8
|
// Either way only a name off FEATURES is kept, and only as "used today".
|
|
9
|
+
//
|
|
10
|
+
// And where the deck was looked at from: a page connected to /events is the
|
|
11
|
+
// desktop app's window or a browser tab for as long as it stays (event-routes.mjs),
|
|
12
|
+
// and `ccdeck tui` says so on the requests it makes (deck-client.mjs).
|
|
9
13
|
import { readBody, send } from "./http-io.mjs";
|
|
10
14
|
import { usageDay } from "./usage-day.mjs";
|
|
11
15
|
|
|
@@ -50,3 +54,44 @@ export async function handleFeature(req, res) {
|
|
|
50
54
|
if (!usageDay.noteFeature(name)) return send(res, 400, { ok: false, reason: "unknown_feature" });
|
|
51
55
|
return send(res, 200, { ok: true });
|
|
52
56
|
}
|
|
57
|
+
|
|
58
|
+
/** The desktop app's window says so in its User-Agent, `ccdeck-desktop/<version>`
|
|
59
|
+
* after the browser's own (desktop/main.mjs), and the page reads it the same way
|
|
60
|
+
* (src/web/in-app.ts). */
|
|
61
|
+
const IN_APP = /\bccdeck-desktop\/\d/;
|
|
62
|
+
|
|
63
|
+
/** Which surface a page is: "desktop-window" for the app's window, else
|
|
64
|
+
* "browser-tab" — any browser, on this machine or through a tunnel. */
|
|
65
|
+
export function pageSurface(headers = {}) {
|
|
66
|
+
const ua = headers?.["user-agent"];
|
|
67
|
+
return typeof ua === "string" && IN_APP.test(ua) ? "desktop-window" : "browser-tab";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A page connected to /events: its surface is used today, and on every day it
|
|
71
|
+
* is still connected when the day turns, until the connection closes. Never
|
|
72
|
+
* for the app's tray connection, which is a reader and not somebody looking
|
|
73
|
+
* (sse-clients.mjs): the caller leaves it out. Never throws. */
|
|
74
|
+
export function holdPageSurface(req, usage = usageDay) {
|
|
75
|
+
try {
|
|
76
|
+
const release = usage.holdFeature(pageSurface(req?.headers));
|
|
77
|
+
req.once("close", release);
|
|
78
|
+
} catch {
|
|
79
|
+
// A page this could not count still gets its stream.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** What a terminal client may say it is, in `x-ccdeck-client`, and the feature
|
|
84
|
+
* each is. Anything else — another value, another command — is nothing. */
|
|
85
|
+
const CLIENT_FEATURES = new Map([["tui", "tui"]]);
|
|
86
|
+
|
|
87
|
+
/** Note the client a request says it came from, if it is one off the list and
|
|
88
|
+
* the request carries the deck's own token (`authenticated`, request-gates.mjs
|
|
89
|
+
* presentsDeckToken), which only this user's own commands read off the deck's
|
|
90
|
+
* record: nothing else can pass for a terminal by setting the header. */
|
|
91
|
+
export function noteClientFeature(headers = {}, authenticated = false, usage = usageDay) {
|
|
92
|
+
if (!authenticated) return;
|
|
93
|
+
const raw = headers?.["x-ccdeck-client"];
|
|
94
|
+
if (typeof raw !== "string") return;
|
|
95
|
+
const name = CLIENT_FEATURES.get(raw.trim().toLowerCase());
|
|
96
|
+
if (name) usage.noteFeature(name);
|
|
97
|
+
}
|
package/src/server/index.mjs
CHANGED
|
@@ -19,7 +19,9 @@ import { challengeDeck, challengeProof, isProcessAlive } from "./deck-probe.mjs"
|
|
|
19
19
|
export { challengeDeck, challengeProof, isProcessAlive };
|
|
20
20
|
// The gates in front of the route table — see src/server/request-gates.mjs,
|
|
21
21
|
// which also holds the per-process token the strictest of them checks.
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
OPEN_MUTATIONS, isAuthorizedDataRead, isAuthorizedMutation, isGuardedRead, isTrustedMutation, isTrustedRead, presentsDeckToken,
|
|
24
|
+
} from "./request-gates.mjs";
|
|
23
25
|
import { trafficCapture } from "./traffic-radar-capture.mjs";
|
|
24
26
|
import { trafficRadar } from "./traffic-radar.mjs";
|
|
25
27
|
import { handleTrafficCapture, isAuthorizedTrafficIngest } from "./traffic-radar-routes.mjs";
|
|
@@ -71,7 +73,7 @@ import { serveStatic } from "./static-serve.mjs";
|
|
|
71
73
|
// session-tracking.mjs.
|
|
72
74
|
import { handleForget, startOutputWatch } from "./session-tracking.mjs";
|
|
73
75
|
// Which features were used today, for the usage reports — see feature-use.mjs.
|
|
74
|
-
import { handleFeature, noteRouteFeature } from "./feature-use.mjs";
|
|
76
|
+
import { handleFeature, noteClientFeature, noteRouteFeature } from "./feature-use.mjs";
|
|
75
77
|
// Exported from this file before it moved, and still.
|
|
76
78
|
export { HARD_TRACKED_SESSIONS } from "./session-tracking.mjs";
|
|
77
79
|
// The desktop app's update as its window sees it — the state the app reports
|
|
@@ -316,6 +318,9 @@ export async function startServer({ port = 4317, host = "127.0.0.1", persist = n
|
|
|
316
318
|
// account, pairing a deck — counts as that feature used today. Past the
|
|
317
319
|
// gates above, so only the deck's own callers count. See feature-use.mjs.
|
|
318
320
|
noteRouteFeature(req.method, url.pathname);
|
|
321
|
+
// And `ccdeck tui` saying it is the one asking, on a request with the
|
|
322
|
+
// deck's own token — which only this user's own commands hold.
|
|
323
|
+
noteClientFeature(req.headers, presentsDeckToken(req.headers));
|
|
319
324
|
|
|
320
325
|
// `?persist=0` — another deck was elected to write this event to the log
|
|
321
326
|
// the two of them share. Absent, this deck writes it.
|