quick-acp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +405 -2
- package/dist/acp/agent.js +371 -0
- package/dist/acp-smoke.js +163 -0
- package/dist/concurrent-test.js +101 -0
- package/dist/doctor.js +86 -0
- package/dist/e2e.js +206 -0
- package/dist/fresh-machine-e2e.js +151 -0
- package/dist/inject-turn-test.js +119 -0
- package/dist/login-cli.js +86 -0
- package/dist/main.js +77 -0
- package/dist/no-outpost-e2e.js +86 -0
- package/dist/probe.js +308 -0
- package/dist/quick/auth.js +371 -0
- package/dist/quick/codec.js +499 -0
- package/dist/quick/credstore.js +439 -0
- package/dist/quick/gateway-contract.js +104 -0
- package/dist/quick/login.js +522 -0
- package/dist/quick/oidc.js +152 -0
- package/dist/quick/session-direct.js +200 -0
- package/dist/quick/session.js +385 -0
- package/dist/quick/transport.js +343 -0
- package/dist/tools/registry.js +411 -0
- package/dist/tools/strategies.js +188 -0
- package/dist/wss-smoke.js +230 -0
- package/package.json +53 -4
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the Quick session straight out of the OS credential store.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS REPLACES THE OUTPOST PATH
|
|
5
|
+
* ----------------------------------
|
|
6
|
+
* The first cut of this bridge asked the user to paste `QUICK_ACP_INSTANCE_TOKEN`
|
|
7
|
+
* — the shared secret the Electron main process hands its outpost over stdin.
|
|
8
|
+
* That was the wrong design: the token lives only in the app's memory, so it
|
|
9
|
+
* forced a manual copy of an ephemeral value on every restart.
|
|
10
|
+
*
|
|
11
|
+
* The durable artifact is the LOGIN, and it is already on disk:
|
|
12
|
+
*
|
|
13
|
+
* Windows Credential Manager, generic entries (verified on the target machine):
|
|
14
|
+
* Target "quickwork-social-<profileId>" -> {"__chunks__":N,"__sha__":"..."}
|
|
15
|
+
* Target "quickwork-social-<profileId>_chunk_K" -> one base64 fragment each
|
|
16
|
+
*
|
|
17
|
+
* Concatenating the chunks and base64-decoding yields a SQLite database
|
|
18
|
+
* fragment holding `login_metadata`, which includes refresh_token, client_id,
|
|
19
|
+
* client_secret, issuer_url, tenant_url. macOS/Linux use the same logical
|
|
20
|
+
* layout behind their own keychains.
|
|
21
|
+
*
|
|
22
|
+
* So: read the blob, reassemble, and refresh the OIDC token ourselves. No user
|
|
23
|
+
* copy-paste, no dependency on the app being open.
|
|
24
|
+
*/
|
|
25
|
+
import { execFileSync, execFile } from 'node:child_process';
|
|
26
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
27
|
+
import { writeFile, mkdtemp, rm } from 'node:fs/promises';
|
|
28
|
+
import { homedir, tmpdir } from 'node:os';
|
|
29
|
+
import { join } from 'node:path';
|
|
30
|
+
import { promisify } from 'node:util';
|
|
31
|
+
const execFileAsync = promisify(execFile);
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Windows credential store
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
const CRED_PS = (target) => `
|
|
36
|
+
Add-Type -TypeDefinition @"
|
|
37
|
+
using System;
|
|
38
|
+
using System.Runtime.InteropServices;
|
|
39
|
+
public class QwCred {
|
|
40
|
+
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
|
|
41
|
+
public struct CREDENTIAL {
|
|
42
|
+
public int Flags; public int Type; public string TargetName; public string Comment;
|
|
43
|
+
public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten;
|
|
44
|
+
public int CredentialBlobSize; public IntPtr CredentialBlob;
|
|
45
|
+
public int Persist; public int AttributeCount; public IntPtr Attributes;
|
|
46
|
+
public string TargetAlias; public string UserName;
|
|
47
|
+
}
|
|
48
|
+
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
|
|
49
|
+
public static extern bool CredReadW(string target, int type, int flags, out IntPtr credential);
|
|
50
|
+
[DllImport("advapi32.dll")] public static extern void CredFree(IntPtr cred);
|
|
51
|
+
}
|
|
52
|
+
"@
|
|
53
|
+
$ptr = [IntPtr]::Zero
|
|
54
|
+
if ([QwCred]::CredReadW('${target.replace(/'/g, "''")}', 1, 0, [ref]$ptr)) {
|
|
55
|
+
$c = [System.Runtime.InteropServices.Marshal]::PtrToStructure($ptr, [type][QwCred+CREDENTIAL])
|
|
56
|
+
$bytes = New-Object byte[] $c.CredentialBlobSize
|
|
57
|
+
[System.Runtime.InteropServices.Marshal]::Copy($c.CredentialBlob, $bytes, 0, $c.CredentialBlobSize)
|
|
58
|
+
# Write the raw bytes, base64-wrapped, so no console encoding can corrupt them.
|
|
59
|
+
[Console]::Out.Write([Convert]::ToBase64String($bytes))
|
|
60
|
+
[QwCred]::CredFree($ptr)
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
/**
|
|
64
|
+
* Read one credential target. Returns the decoded blob text, or null.
|
|
65
|
+
*
|
|
66
|
+
* The script goes into a temp .ps1 rather than a `-Command` argument: the
|
|
67
|
+
* here-string contains `@"`/`"@` and nested quotes that the Windows command
|
|
68
|
+
* line mangles, which shows up as an empty read (indistinguishable from
|
|
69
|
+
* "credential missing") rather than an error.
|
|
70
|
+
*/
|
|
71
|
+
async function readWindowsCredential(target) {
|
|
72
|
+
const dir = await mkdtemp(join(tmpdir(), 'quick-acp-cred-'));
|
|
73
|
+
const scriptPath = join(dir, 'read.ps1');
|
|
74
|
+
const debug = process.env.QUICK_ACP_DEBUG === '1';
|
|
75
|
+
try {
|
|
76
|
+
await writeFile(scriptPath, CRED_PS(target), 'utf8');
|
|
77
|
+
const { stdout } = await execFileAsync('powershell', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File', scriptPath], { maxBuffer: 16 * 1024 * 1024, windowsHide: true });
|
|
78
|
+
const b64 = stdout.trim();
|
|
79
|
+
if (!b64) {
|
|
80
|
+
if (debug)
|
|
81
|
+
console.error(`[credstore] ${target}: empty output (credential absent?)`);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
// The script prints base64 so no console encoding can corrupt the bytes.
|
|
85
|
+
const raw = Buffer.from(b64, 'base64');
|
|
86
|
+
const text = decodeBlob(raw);
|
|
87
|
+
if (debug)
|
|
88
|
+
console.error(`[credstore] ${target}: read ${raw.length} bytes`);
|
|
89
|
+
return text;
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
// Never swallow: a broken read must be distinguishable from "not signed in".
|
|
93
|
+
if (debug) {
|
|
94
|
+
const err = e;
|
|
95
|
+
console.error(`[credstore] ${target}: FAILED ${err.message ?? String(e)}`);
|
|
96
|
+
if (err.stderr)
|
|
97
|
+
console.error(`[credstore] stderr: ${err.stderr.slice(0, 400)}`);
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
void rm(dir, { recursive: true, force: true }).catch(() => { });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Decode one credential blob to text.
|
|
107
|
+
*
|
|
108
|
+
* Small entries are JSON and large ones are base64 fragments, both stored as
|
|
109
|
+
* UTF-16LE — the same interleaved-NUL shape. If it is not valid utf16 we treat
|
|
110
|
+
* it as utf8 rather than mangling it.
|
|
111
|
+
*/
|
|
112
|
+
function decodeBlob(buf) {
|
|
113
|
+
return decodeUtf16LeIfLikely(buf) ?? buf.toString('utf8');
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The credential blobs are stored as UTF-16LE text. Node can decode that
|
|
117
|
+
* directly, so no byte swapping is needed — swapping produces the CJK-looking
|
|
118
|
+
* mojibake that made these entries look encrypted during analysis.
|
|
119
|
+
*/
|
|
120
|
+
function decodeUtf16LeIfLikely(buf) {
|
|
121
|
+
if (buf.length < 2)
|
|
122
|
+
return null;
|
|
123
|
+
// Heuristic: for ASCII-range utf16 text the odd bytes are 0x00. A big-endian
|
|
124
|
+
// blob would have the zeroes at the even offsets instead, so check both.
|
|
125
|
+
let zeroOdd = 0;
|
|
126
|
+
let zeroEven = 0;
|
|
127
|
+
const sample = Math.min(buf.length, 512);
|
|
128
|
+
const pairs = Math.floor(sample / 2);
|
|
129
|
+
for (let i = 0; i < pairs; i++) {
|
|
130
|
+
if (buf[i * 2 + 1] === 0)
|
|
131
|
+
zeroOdd++;
|
|
132
|
+
if (buf[i * 2] === 0)
|
|
133
|
+
zeroEven++;
|
|
134
|
+
}
|
|
135
|
+
if (pairs === 0)
|
|
136
|
+
return null;
|
|
137
|
+
if (zeroOdd / pairs >= 0.6) {
|
|
138
|
+
return buf.toString('utf16le').replace(/\0+$/, '');
|
|
139
|
+
}
|
|
140
|
+
if (zeroEven / pairs >= 0.6) {
|
|
141
|
+
// Big-endian UTF-16: swap into little-endian first.
|
|
142
|
+
const swapped = Buffer.from(buf);
|
|
143
|
+
swapped.swap16();
|
|
144
|
+
return swapped.toString('utf16le').replace(/\0+$/, '');
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
function quickworkHome() {
|
|
149
|
+
return process.env.QUICK_ACP_QUICKWORK_HOME ?? join(homedir(), '.quickwork');
|
|
150
|
+
}
|
|
151
|
+
function readProfiles() {
|
|
152
|
+
const path = join(quickworkHome(), 'profiles.json');
|
|
153
|
+
if (!existsSync(path))
|
|
154
|
+
return null;
|
|
155
|
+
try {
|
|
156
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Pick the active profile, or the only one. */
|
|
163
|
+
export function activeProfileId() {
|
|
164
|
+
const profiles = readProfiles();
|
|
165
|
+
if (!profiles?.entries?.length)
|
|
166
|
+
return null;
|
|
167
|
+
if (profiles.last_active) {
|
|
168
|
+
const hit = profiles.entries.find((e) => e.id === profiles.last_active);
|
|
169
|
+
if (hit)
|
|
170
|
+
return hit.id;
|
|
171
|
+
}
|
|
172
|
+
return profiles.entries[0]?.id ?? null;
|
|
173
|
+
}
|
|
174
|
+
/** Read the tenant/issuer/client hints the profile records in the clear. */
|
|
175
|
+
export function profileHints() {
|
|
176
|
+
const profiles = readProfiles();
|
|
177
|
+
if (!profiles?.entries?.length)
|
|
178
|
+
return null;
|
|
179
|
+
const id = activeProfileId();
|
|
180
|
+
const entry = profiles.entries.find((e) => e.id === id) ?? profiles.entries[0];
|
|
181
|
+
return entry?.login_metadata ?? null;
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
// Reassemble the login from the chunked credential
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
/**
|
|
187
|
+
* Parse the credential envelope: {"__chunks__":N,"__sha__":"..."} — the real
|
|
188
|
+
* payload is spread across N sibling entries.
|
|
189
|
+
*/
|
|
190
|
+
function parseChunkEnvelope(text) {
|
|
191
|
+
try {
|
|
192
|
+
const parsed = JSON.parse(text);
|
|
193
|
+
const chunks = parsed['__chunks__'];
|
|
194
|
+
const sha = parsed['__sha__'];
|
|
195
|
+
if (typeof chunks === 'number' && chunks > 0) {
|
|
196
|
+
return { chunks, sha: typeof sha === 'string' ? sha : '' };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// Not an envelope; maybe a direct payload.
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Pull login_metadata out of the assembled chunk text.
|
|
206
|
+
*
|
|
207
|
+
* The reassembled bytes are a SQLite page (or a fragment of one) whose cell
|
|
208
|
+
* payload is the JSON we want, so this scans rather than assuming a document
|
|
209
|
+
* shape. Two forms occur in practice and both are handled:
|
|
210
|
+
*
|
|
211
|
+
* - chunk 0 carries the JSON text directly: {"refresh_token": "..."}
|
|
212
|
+
* - later chunks carry base64 fragments of further page content
|
|
213
|
+
*
|
|
214
|
+
* Because the JSON is embedded in binary, quoting may appear escaped (\").
|
|
215
|
+
*/
|
|
216
|
+
function extractLoginMetadata(blob) {
|
|
217
|
+
// Normalise escaped quotes so the same scanner finds JSON in either form.
|
|
218
|
+
const candidates = [blob, blob.replace(/\\"/g, '"')];
|
|
219
|
+
for (const text of candidates) {
|
|
220
|
+
// Fast path: the whole thing is JSON.
|
|
221
|
+
const direct = tryJsonObject(text.trim());
|
|
222
|
+
if (direct && looksLikeLogin(direct))
|
|
223
|
+
return direct;
|
|
224
|
+
}
|
|
225
|
+
for (const text of candidates) {
|
|
226
|
+
const parsed = scanForJsonWith(text, 'refresh_token');
|
|
227
|
+
if (parsed)
|
|
228
|
+
return parsed;
|
|
229
|
+
const alt = scanForJsonWith(text, 'access_token');
|
|
230
|
+
if (alt)
|
|
231
|
+
return alt;
|
|
232
|
+
const alt2 = scanForJsonWith(text, 'client_id');
|
|
233
|
+
if (alt2)
|
|
234
|
+
return alt2;
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
/** Find the smallest enclosing JSON object containing `marker`. */
|
|
239
|
+
function scanForJsonWith(text, marker) {
|
|
240
|
+
const needle = `"${marker}"`;
|
|
241
|
+
let from = 0;
|
|
242
|
+
while (true) {
|
|
243
|
+
const at = text.indexOf(needle, from);
|
|
244
|
+
if (at < 0)
|
|
245
|
+
return null;
|
|
246
|
+
from = at + 1;
|
|
247
|
+
const start = text.lastIndexOf('{', at);
|
|
248
|
+
if (start < 0)
|
|
249
|
+
continue;
|
|
250
|
+
const end = matchBrace(text, start);
|
|
251
|
+
if (end < 0)
|
|
252
|
+
continue;
|
|
253
|
+
const obj = tryJsonObject(text.slice(start, end + 1));
|
|
254
|
+
if (obj && looksLikeLogin(obj))
|
|
255
|
+
return obj;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function tryJsonObject(text) {
|
|
259
|
+
const candidates = [text, sanitizeJsonControlChars(text)];
|
|
260
|
+
for (const candidate of candidates) {
|
|
261
|
+
try {
|
|
262
|
+
const v = JSON.parse(candidate);
|
|
263
|
+
if (v && typeof v === 'object' && !Array.isArray(v))
|
|
264
|
+
return v;
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
/* try the next form */
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Strip control characters that SQLite page padding leaves inside the JSON.
|
|
274
|
+
*
|
|
275
|
+
* Two adjacent pages concatenate in the middle of a string literal, so the
|
|
276
|
+
* recovered text has raw bytes (0x00-0x1f) where the page boundary was. JSON
|
|
277
|
+
* forbids those unescaped, and they carry no information we need.
|
|
278
|
+
*/
|
|
279
|
+
function sanitizeJsonControlChars(text) {
|
|
280
|
+
// Fast path: already clean.
|
|
281
|
+
if (!/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(text))
|
|
282
|
+
return text;
|
|
283
|
+
const schema = /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g;
|
|
284
|
+
// Decode JSON escaped backslashes first so the scanner is not thrown off.
|
|
285
|
+
return text.replace(schema, '');
|
|
286
|
+
}
|
|
287
|
+
function looksLikeLogin(obj) {
|
|
288
|
+
return (typeof obj.refresh_token === 'string' ||
|
|
289
|
+
typeof obj.access_token === 'string' ||
|
|
290
|
+
typeof obj.client_id === 'string');
|
|
291
|
+
}
|
|
292
|
+
/** Find the index of the brace closing the object opened at `start`. */
|
|
293
|
+
function matchBrace(text, start) {
|
|
294
|
+
let depth = 0;
|
|
295
|
+
let inString = false;
|
|
296
|
+
let escape = false;
|
|
297
|
+
for (let i = start; i < text.length; i++) {
|
|
298
|
+
const ch = text[i];
|
|
299
|
+
if (escape) {
|
|
300
|
+
escape = false;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (ch === '\\') {
|
|
304
|
+
escape = true;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (ch === '"') {
|
|
308
|
+
inString = !inString;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (inString)
|
|
312
|
+
continue;
|
|
313
|
+
if (ch === '{')
|
|
314
|
+
depth++;
|
|
315
|
+
else if (ch === '}') {
|
|
316
|
+
depth--;
|
|
317
|
+
if (depth === 0)
|
|
318
|
+
return i;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return -1;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Read the stored login for the active profile.
|
|
325
|
+
*
|
|
326
|
+
* Returns null with a reason rather than throwing, so the caller can decide
|
|
327
|
+
* between falling back to the outpost or asking the user to sign in.
|
|
328
|
+
*/
|
|
329
|
+
export async function readStoredLogin() {
|
|
330
|
+
const profileId = activeProfileId();
|
|
331
|
+
if (!profileId) {
|
|
332
|
+
return { ok: false, reason: `no Quick profile found under ${quickworkHome()}/profiles.json` };
|
|
333
|
+
}
|
|
334
|
+
if (process.platform !== 'win32') {
|
|
335
|
+
// macOS/Linux keychains are readable via `security` / `secret-tool`; not
|
|
336
|
+
// implemented yet, so fail with the concrete next step instead of guessing.
|
|
337
|
+
return {
|
|
338
|
+
ok: false,
|
|
339
|
+
reason: `automatic credential read is implemented for Windows only. ` +
|
|
340
|
+
`On ${process.platform}, sign in to Quick and set QUICK_ACP_INSTANCE_TOKEN, ` +
|
|
341
|
+
`or provide QUICK_ACP_REFRESH_TOKEN manually.`,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const targets = [
|
|
345
|
+
`quickwork-social-${profileId}`,
|
|
346
|
+
`quickwork-enterprise-${profileId}`,
|
|
347
|
+
`quickwork-${profileId}`,
|
|
348
|
+
];
|
|
349
|
+
for (const rawTarget of targets) {
|
|
350
|
+
// CredReadW takes the BARE target name. `cmdkey /list` prints it prefixed
|
|
351
|
+
// with "LegacyGeneric:target=", but that prefix is a display form, not part
|
|
352
|
+
// of the name — passing it makes the lookup fail with ERROR_NOT_FOUND.
|
|
353
|
+
const head = await readWindowsCredential(rawTarget);
|
|
354
|
+
if (!head)
|
|
355
|
+
continue;
|
|
356
|
+
const envelope = parseChunkEnvelope(head);
|
|
357
|
+
if (!envelope) {
|
|
358
|
+
const direct = extractLoginMetadata(head);
|
|
359
|
+
if (direct)
|
|
360
|
+
return { ok: true, login: direct, source: `${rawTarget} (single entry)` };
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
const parts = [];
|
|
364
|
+
// Chunk suffixes are ZERO-based: "__chunks__": 2 means _chunk_0 and
|
|
365
|
+
// _chunk_1. Starting at 1 silently drops the first fragment.
|
|
366
|
+
for (let i = 0; i < envelope.chunks; i++) {
|
|
367
|
+
const chunk = await readWindowsCredential(`${rawTarget}_chunk_${i}`);
|
|
368
|
+
if (!chunk) {
|
|
369
|
+
return {
|
|
370
|
+
ok: false,
|
|
371
|
+
reason: `credential "${rawTarget}" reports ${envelope.chunks} chunk(s) but ` +
|
|
372
|
+
`chunk ${i} is missing or unreadable`,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
parts.push(expandChunk(chunk));
|
|
376
|
+
}
|
|
377
|
+
// Join with NO separator: the chunks are consecutive fragments of one
|
|
378
|
+
// page stream, and a newline here lands inside a JSON string literal,
|
|
379
|
+
// which is illegal JSON and makes the whole payload unparsable.
|
|
380
|
+
const login = extractLoginMetadata(parts.join(''));
|
|
381
|
+
if (login) {
|
|
382
|
+
return { ok: true, login, source: `${rawTarget} (${envelope.chunks} chunk(s))` };
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
ok: false,
|
|
386
|
+
reason: `read ${envelope.chunks} chunk(s) from "${rawTarget}" but found no login_metadata. ` +
|
|
387
|
+
'The entry may be encrypted or the format changed.',
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
ok: false,
|
|
392
|
+
reason: `no Quick credential found for profile "${profileId}". ` +
|
|
393
|
+
'Sign in to the Quick desktop app once, then retry.',
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Normalise one chunk body.
|
|
398
|
+
*
|
|
399
|
+
* A chunk is a fragment of a SQLite page. The interesting JSON is usually
|
|
400
|
+
* present as PLAIN TEXT inside the page, but the tail of a page is often
|
|
401
|
+
* another base64 blob, so the same chunk can contain both. We therefore return
|
|
402
|
+
* the original text AND, when the tail decodes to text, that too — the scanner
|
|
403
|
+
* then searches all of it.
|
|
404
|
+
*/
|
|
405
|
+
function expandChunk(text) {
|
|
406
|
+
const out = [text];
|
|
407
|
+
const cleaned = text.replace(/\s+/g, '');
|
|
408
|
+
if (/^[A-Za-z0-9+/=]+$/.test(cleaned) && cleaned.length >= 16) {
|
|
409
|
+
try {
|
|
410
|
+
const decoded = Buffer.from(cleaned, 'base64').toString('utf8');
|
|
411
|
+
const printable = decoded.replace(/[^\x20-\x7e\r\n\t]/g, '');
|
|
412
|
+
if (printable.length >= decoded.length * 0.8)
|
|
413
|
+
out.push(decoded);
|
|
414
|
+
}
|
|
415
|
+
catch {
|
|
416
|
+
/* keep the raw text */
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return out.join('\n');
|
|
420
|
+
}
|
|
421
|
+
/** Synchronous convenience for diagnostics that only need to know it is there. */
|
|
422
|
+
export function credentialTargetsExistSync() {
|
|
423
|
+
if (process.platform !== 'win32')
|
|
424
|
+
return [];
|
|
425
|
+
const profileId = activeProfileId();
|
|
426
|
+
if (!profileId)
|
|
427
|
+
return [];
|
|
428
|
+
try {
|
|
429
|
+
const out = execFileSync('cmdkey', ['/list'], { encoding: 'utf8', windowsHide: true });
|
|
430
|
+
return out
|
|
431
|
+
.split('\n')
|
|
432
|
+
.filter((l) => l.includes(`quickwork-`) && l.includes(profileId))
|
|
433
|
+
.map((l) => l.trim());
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
//# sourceMappingURL=credstore.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verified gateway behaviour — every constant here was proven against the LIVE
|
|
3
|
+
* gateway, not inferred from the shipped JavaScript. Reading the renderer's
|
|
4
|
+
* source gives three answers that the server actually rejects, so this file is
|
|
5
|
+
* the authority for connection parameters.
|
|
6
|
+
*
|
|
7
|
+
* ── What was wrong in the source, and what works ──────────────────────────
|
|
8
|
+
*
|
|
9
|
+
* 1. OUTBOUND FRAMING
|
|
10
|
+
* renderer CUe() : plain text utf8(JSON{eventType,payload:{payload:b64}})
|
|
11
|
+
* main buildGatewayInputFrame() : event-stream + CBOR
|
|
12
|
+
* The renderer form is the one the server accepts for CHAT MESSAGES.
|
|
13
|
+
* With CBOR framing the socket opens and `session_connect` is acknowledged,
|
|
14
|
+
* but every later business message (session_list, user_message) is silently
|
|
15
|
+
* dropped. That asymmetry is what makes this bug so hard to see: the
|
|
16
|
+
* connection looks healthy.
|
|
17
|
+
* => USE 'json-base64'.
|
|
18
|
+
*
|
|
19
|
+
* 2. AUTH PLACEMENT
|
|
20
|
+
* source: Authorization: Bearer header
|
|
21
|
+
* server: query string `?token=...&surfaceType=...`
|
|
22
|
+
* A Bearer header yields 401 even with a valid token. `surfaceType` is
|
|
23
|
+
* mandatory; without it the upgrade is refused.
|
|
24
|
+
*
|
|
25
|
+
* 3. PATH
|
|
26
|
+
* /streaming/quickwork-chat-bidirectional-stream -> works
|
|
27
|
+
* /ws/service/SpaceNeedleConversationService/... -> 404
|
|
28
|
+
*
|
|
29
|
+
* ── Confirmed inbound frame flow for one turn ─────────────────────────────
|
|
30
|
+
*
|
|
31
|
+
* message_start {payload:{role:'assistant'}, message_id, thread_id}
|
|
32
|
+
* title_generated {payload:{conversation_id,title}}
|
|
33
|
+
* text_delta {payload:{delta, kernel_thread_id}}
|
|
34
|
+
* turn_usage {payload:{input_tokens,output_tokens,cache_read_tokens,
|
|
35
|
+
* cache_write_tokens,resolved_model_id,...}}
|
|
36
|
+
* text_complete {payload:{text}}
|
|
37
|
+
* message_complete {payload:{text,tool_calls,initiator}}
|
|
38
|
+
*
|
|
39
|
+
* `resolved_model_id` is how the caller learns WHICH model actually answered —
|
|
40
|
+
* e.g. `us.anthropic.claude-opus-5-5`. The client cannot choose it.
|
|
41
|
+
*
|
|
42
|
+
* ── Keepalive ─────────────────────────────────────────────────────────────
|
|
43
|
+
* The server reaps the socket with
|
|
44
|
+
* {"type":"error","code":"IDLE_TIMEOUT","message":"Client sent no frames
|
|
45
|
+
* for >95 seconds"}
|
|
46
|
+
* unless a frame arrives inside that window. 45 s is safe. A `ping` sent as a
|
|
47
|
+
* plain text frame (not event-stream) also gets `{"type":"status",
|
|
48
|
+
* "payload":{"status":"pong"}}` back.
|
|
49
|
+
*/
|
|
50
|
+
/** The single path that works for a social (non-enterprise) tenant. */
|
|
51
|
+
export const WORKING_PATH = '/streaming/quickwork-chat-bidirectional-stream';
|
|
52
|
+
/** Wrong for this tenant; kept only so diagnostics can label a 404. */
|
|
53
|
+
export const RENDERER_PATH = '/ws/service/SpaceNeedleConversationService/operation/ChatBidirectionalStream';
|
|
54
|
+
/**
|
|
55
|
+
* Outbound framing that the server actually accepts.
|
|
56
|
+
*
|
|
57
|
+
* 'json-base64' = plain text frame: utf8(JSON.stringify({eventType, payload:{payload: b64}}))
|
|
58
|
+
* 'cbor' = event-stream + CBOR; opens the socket but drops business messages.
|
|
59
|
+
*
|
|
60
|
+
* Default changed to json-base64 after live verification.
|
|
61
|
+
*/
|
|
62
|
+
export const WORKING_FRAMING = 'json-base64';
|
|
63
|
+
/** Server's own idle-reap threshold, from its IDLE_TIMEOUT error. */
|
|
64
|
+
export const SERVER_IDLE_REAP_MS = 95_000;
|
|
65
|
+
/** Send a keepalive comfortably inside that window. */
|
|
66
|
+
export const KEEPALIVE_INTERVAL_MS = 45_000;
|
|
67
|
+
/**
|
|
68
|
+
* Build the gateway URL that opens.
|
|
69
|
+
* Auth and surfaceType go in the query; no Authorization header.
|
|
70
|
+
*/
|
|
71
|
+
export function buildWorkingUrl(opts) {
|
|
72
|
+
const path = opts.path ?? WORKING_PATH;
|
|
73
|
+
const params = new URLSearchParams({ surfaceType: opts.surfaceType, token: opts.jwt });
|
|
74
|
+
if (opts.outpostId)
|
|
75
|
+
params.set('outpostId', opts.outpostId);
|
|
76
|
+
if (opts.workingSessionId)
|
|
77
|
+
params.set('workingSessionId', opts.workingSessionId);
|
|
78
|
+
return `wss://${opts.wsHost}${path}?${params.toString()}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The `connected` frame belongs to the WebRTC voice path
|
|
82
|
+
* (`LiveConversationWebRtcClient*`), not chat. Chat does not wait on it, so its
|
|
83
|
+
* absence is not a failure.
|
|
84
|
+
*/
|
|
85
|
+
export const CONNECTED_FRAME_IS_VOICE_RELATED = true;
|
|
86
|
+
/**
|
|
87
|
+
* Inbound types that are housekeeping, not part of a turn.
|
|
88
|
+
* Kept here so the session layer does not have to hardcode the list twice.
|
|
89
|
+
*/
|
|
90
|
+
export const HOUSEKEEPING_FRAME_TYPES = new Set([
|
|
91
|
+
'keepalive',
|
|
92
|
+
'task_list_update',
|
|
93
|
+
'runs_updated',
|
|
94
|
+
'status',
|
|
95
|
+
'session_established',
|
|
96
|
+
'connected',
|
|
97
|
+
'session_list',
|
|
98
|
+
]);
|
|
99
|
+
/**
|
|
100
|
+
* Frame types that mark the end of a turn. `message_complete` is the
|
|
101
|
+
* authoritative one; `text_complete` arrives just before it.
|
|
102
|
+
*/
|
|
103
|
+
export const TURN_END_FRAME_TYPES = new Set(['message_complete', 'turn_usage']);
|
|
104
|
+
//# sourceMappingURL=gateway-contract.js.map
|