@adhdev/daemon-core 0.9.82-rc.535 → 0.9.82-rc.536
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/dist/index.js +35 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -5
- package/dist/index.mjs.map +1 -1
- package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +13 -0
- package/dist/providers/spec/types.d.ts +17 -0
- package/package.json +3 -3
- package/src/providers/sdk/v1/builders/cli/parse-session.ts +22 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +1 -1
- package/src/providers/spec/native-history-executor.ts +50 -1
- package/src/providers/spec/types.ts +17 -0
|
@@ -51,6 +51,19 @@ export interface TranscriptPtySpec {
|
|
|
51
51
|
* so the plain assistant answer is the only assistant bubble left. Matched
|
|
52
52
|
* against the raw pre-strip line; the visible text is still ANSI-stripped
|
|
53
53
|
* for the bubble content.
|
|
54
|
+
*
|
|
55
|
+
* Value-agnostic mode: the sentinel "*" (or "48;*" / "bg") matches ANY
|
|
56
|
+
* background-color SGR — 256-color `48;5;<n>` OR truecolor `48;2;<r>;<g>;<b>`
|
|
57
|
+
* — instead of an allowlist of exact color numbers. This is the robust form:
|
|
58
|
+
* the earlier allowlist bug recurred every time a TUI changed its exact box
|
|
59
|
+
* color (cursor `48;5;233` guess, opencode rc.531), because a hard-coded
|
|
60
|
+
* color that no longer matched let the boxed user echo fall through to the
|
|
61
|
+
* permissive assistantPrefix. The sentinel keys off the *presence* of a
|
|
62
|
+
* background-color param group — the structural signal of a boxed turn —
|
|
63
|
+
* so a genuine assistant line (no background SGR) is still classified
|
|
64
|
+
* assistant. Chrome patterns are filtered BEFORE this check, so bg-colored
|
|
65
|
+
* chrome (e.g. the "→ Add a follow-up" composer footer) is already excluded
|
|
66
|
+
* and does not become a spurious user bubble.
|
|
54
67
|
*/
|
|
55
68
|
userBackgroundSgr?: string[];
|
|
56
69
|
}
|
|
@@ -76,6 +76,23 @@ export interface NativeHistoryJsonlSource {
|
|
|
76
76
|
message_filter?: {
|
|
77
77
|
where: string;
|
|
78
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* Fallback workspace attribution when the transcript carries no
|
|
81
|
+
* `session_meta` cwd record. Some stores (cursor-agent) do NOT write a
|
|
82
|
+
* session_meta line and keep the workspace only in the on-disk project-slug
|
|
83
|
+
* directory (`~/.cursor/projects/<slug>/…`), which is a lossy, sometimes
|
|
84
|
+
* truncated+hashed transform of the real path and cannot be reversed. When
|
|
85
|
+
* this flag is set and no session_meta workspace was found, the executor
|
|
86
|
+
* stamps `input.workspace` onto each message — but ONLY after confirming the
|
|
87
|
+
* resolved file actually lives under that workspace's project slug (a path
|
|
88
|
+
* segment matches the input workspace's cursor/claude slug, allowing for
|
|
89
|
+
* cursor's length-truncation). This closes the first-turn read gap (before a
|
|
90
|
+
* provider session id is pinned, the downstream hasSafeNativeHistoryMapping
|
|
91
|
+
* guard needs a per-message workspace) without risking cross-workspace
|
|
92
|
+
* aliasing: a slug mismatch leaves the workspace unset and the read fails
|
|
93
|
+
* closed as before.
|
|
94
|
+
*/
|
|
95
|
+
workspace_from_input?: boolean;
|
|
79
96
|
message_map: NativeHistoryMessageMap;
|
|
80
97
|
}
|
|
81
98
|
export interface NativeHistorySqliteSource {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhdev/daemon-core",
|
|
3
|
-
"version": "0.9.82-rc.
|
|
3
|
+
"version": "0.9.82-rc.536",
|
|
4
4
|
"description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"author": "vilmire",
|
|
48
48
|
"license": "AGPL-3.0-or-later",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@adhdev/mesh-shared": "0.9.82-rc.
|
|
51
|
-
"@adhdev/session-host-core": "0.9.82-rc.
|
|
50
|
+
"@adhdev/mesh-shared": "0.9.82-rc.536",
|
|
51
|
+
"@adhdev/session-host-core": "0.9.82-rc.536",
|
|
52
52
|
"@agentclientprotocol/sdk": "^0.16.1",
|
|
53
53
|
"ajv": "^8.20.0",
|
|
54
54
|
"ajv-formats": "^3.0.1",
|
|
@@ -58,6 +58,19 @@ export interface TranscriptPtySpec {
|
|
|
58
58
|
* so the plain assistant answer is the only assistant bubble left. Matched
|
|
59
59
|
* against the raw pre-strip line; the visible text is still ANSI-stripped
|
|
60
60
|
* for the bubble content.
|
|
61
|
+
*
|
|
62
|
+
* Value-agnostic mode: the sentinel "*" (or "48;*" / "bg") matches ANY
|
|
63
|
+
* background-color SGR — 256-color `48;5;<n>` OR truecolor `48;2;<r>;<g>;<b>`
|
|
64
|
+
* — instead of an allowlist of exact color numbers. This is the robust form:
|
|
65
|
+
* the earlier allowlist bug recurred every time a TUI changed its exact box
|
|
66
|
+
* color (cursor `48;5;233` guess, opencode rc.531), because a hard-coded
|
|
67
|
+
* color that no longer matched let the boxed user echo fall through to the
|
|
68
|
+
* permissive assistantPrefix. The sentinel keys off the *presence* of a
|
|
69
|
+
* background-color param group — the structural signal of a boxed turn —
|
|
70
|
+
* so a genuine assistant line (no background SGR) is still classified
|
|
71
|
+
* assistant. Chrome patterns are filtered BEFORE this check, so bg-colored
|
|
72
|
+
* chrome (e.g. the "→ Add a follow-up" composer footer) is already excluded
|
|
73
|
+
* and does not become a spurious user bubble.
|
|
61
74
|
*/
|
|
62
75
|
userBackgroundSgr?: string[]
|
|
63
76
|
}
|
|
@@ -223,7 +236,16 @@ export function buildParseSessionFromTui(spec: ParseSessionTuiSpec): (input: any
|
|
|
223
236
|
const userBgList = Array.isArray(spec.transcriptPty.userBackgroundSgr)
|
|
224
237
|
? spec.transcriptPty.userBackgroundSgr.map(s => String(s).trim()).filter(Boolean)
|
|
225
238
|
: []
|
|
239
|
+
// Value-agnostic sentinel: "*" / "48;*" / "bg" matches ANY background-color
|
|
240
|
+
// SGR (256-color `48;5;<n>` OR truecolor `48;2;<r>;<g>;<b>`) as the boxed-user
|
|
241
|
+
// signal, instead of an allowlist of exact colors that breaks whenever a TUI
|
|
242
|
+
// changes its box color. The param group must sit inside an SGR run terminated
|
|
243
|
+
// by `m`; 3-digit color indices / channels are matched structurally.
|
|
244
|
+
const ANY_BG_SENTINELS = new Set(['*', '48;*', 'bg', '48'])
|
|
226
245
|
const userBgRes = userBgList.map(code => {
|
|
246
|
+
if (ANY_BG_SENTINELS.has(code.toLowerCase())) {
|
|
247
|
+
return new RegExp('\\x1b\\[[0-9;]*\\b48;(?:5;\\d{1,3}|2;\\d{1,3};\\d{1,3};\\d{1,3})[0-9;]*m')
|
|
248
|
+
}
|
|
227
249
|
// Match the code inside an SGR run: `\x1b[<...>48;5;233<...>m`. The code
|
|
228
250
|
// (e.g. "48;5;233") appears somewhere in the `;`-separated parameter list
|
|
229
251
|
// terminated by `m`. Escape regex-special chars in the code first.
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"userBackgroundSgr": {
|
|
83
83
|
"type": "array",
|
|
84
84
|
"items": { "type": "string" },
|
|
85
|
-
"description": "Optional SGR background-color codes (e.g. \"48;5;233\") that mark a USER turn. Some TUIs (cursor-agent) render the user's submitted message and composer echo inside a colored box while rendering the assistant answer as a plain no-background line. After ANSI stripping both are bare lines, so a permissive assistantPrefix grabs the user echo as an assistant bubble. When set, a raw line whose ANSI carries any of these background codes is classified as a user turn regardless of its stripped text, leaving the plain assistant answer as the only assistant bubble. Checked against the raw pre-strip line before prefix matching."
|
|
85
|
+
"description": "Optional SGR background-color codes (e.g. \"48;5;233\") that mark a USER turn. Some TUIs (cursor-agent) render the user's submitted message and composer echo inside a colored box while rendering the assistant answer as a plain no-background line. After ANSI stripping both are bare lines, so a permissive assistantPrefix grabs the user echo as an assistant bubble. When set, a raw line whose ANSI carries any of these background codes is classified as a user turn regardless of its stripped text, leaving the plain assistant answer as the only assistant bubble. Checked against the raw pre-strip line before prefix matching (chrome patterns are filtered first, so bg-colored chrome is not misclassified as a user turn).\n\nValue-agnostic sentinel: the entry \"*\" (also \"48;*\" / \"bg\") matches ANY background-color SGR — 256-color `48;5;<n>` OR truecolor `48;2;<r>;<g>;<b>` — instead of an exact-color allowlist. Prefer \"*\": a hard-coded color re-breaks every time the TUI changes its box color (cursor \"48;5;233\", opencode), whereas \"*\" keys off the structural presence of a bg box. A genuine assistant line carries no background SGR, so it still classifies as assistant."
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -106,7 +106,12 @@ function executeJsonl(src: NativeHistoryJsonlSource, input: NativeHistoryInput):
|
|
|
106
106
|
const mtime = safeMtimeMs(sourcePath);
|
|
107
107
|
const lines = readJsonlLines(sourcePath);
|
|
108
108
|
if (lines.length === 0) return null;
|
|
109
|
-
|
|
109
|
+
// Prefer an in-transcript session_meta cwd; fall back to the input workspace
|
|
110
|
+
// only when the spec opts in AND the resolved file lives under that
|
|
111
|
+
// workspace's project slug (cursor-agent writes no session_meta and hides the
|
|
112
|
+
// workspace in the lossy on-disk slug — see workspace_from_input).
|
|
113
|
+
const transcriptWorkspace = readSessionMetaWorkspace(lines)
|
|
114
|
+
?? (src.workspace_from_input ? workspaceFromInputIfSlugMatches(sourcePath, input) : undefined);
|
|
110
115
|
|
|
111
116
|
// session id: filename uuid or extracted from first record
|
|
112
117
|
let providerSessionId: string | undefined;
|
|
@@ -248,6 +253,50 @@ function readSessionMetaWorkspace(lines: any[]): string | undefined {
|
|
|
248
253
|
return undefined;
|
|
249
254
|
}
|
|
250
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Return `input.workspace` when the resolved transcript file provably lives
|
|
258
|
+
* under that workspace's project-slug directory, else undefined.
|
|
259
|
+
*
|
|
260
|
+
* cursor-agent stores transcripts at `~/.cursor/projects/<slug>/…` where
|
|
261
|
+
* `<slug>` is the workspace realpath with every non-`[A-Za-z0-9_-]` char turned
|
|
262
|
+
* into `-` (the same transform claude uses, minus the leading dash from the root
|
|
263
|
+
* `/`). Long slugs are truncated and suffixed with a short hash
|
|
264
|
+
* (`<prefix>-<7hex>`). The transform is lossy, so we cannot reconstruct the real
|
|
265
|
+
* path from the slug — but we CAN verify a candidate workspace matches it. We
|
|
266
|
+
* compute the workspace's slug (both the claude form and the leading-`/`-stripped
|
|
267
|
+
* cursor form) and accept when a path segment of the file equals it OR is a
|
|
268
|
+
* truncated `<prefix>-<hash>` of it. On match the caller stamps the KNOWN real
|
|
269
|
+
* `input.workspace`, so downstream workspace comparison (path.resolve-based)
|
|
270
|
+
* still works; on mismatch we return undefined and the read fails closed rather
|
|
271
|
+
* than aliasing another workspace's transcript.
|
|
272
|
+
*/
|
|
273
|
+
function workspaceFromInputIfSlugMatches(sourcePath: string, input: NativeHistoryInput): string | undefined {
|
|
274
|
+
const wsRaw = typeof input.workspace === 'string' ? input.workspace.trim() : '';
|
|
275
|
+
if (!wsRaw) return undefined;
|
|
276
|
+
let wsReal = wsRaw;
|
|
277
|
+
try { wsReal = fs.realpathSync(wsRaw); } catch { /* keep raw */ }
|
|
278
|
+
const slugs = new Set<string>();
|
|
279
|
+
for (const w of [wsReal, wsRaw]) {
|
|
280
|
+
if (!w) continue;
|
|
281
|
+
slugs.add(claudeProjectDirName(w)); // "-Users-…" (leading dash)
|
|
282
|
+
slugs.add(claudeProjectDirName(w.replace(/^\/+/, ''))); // cursor form, no leading dash
|
|
283
|
+
}
|
|
284
|
+
const segments = sourcePath.split(path.sep);
|
|
285
|
+
for (const seg of segments) {
|
|
286
|
+
if (!seg) continue;
|
|
287
|
+
for (const slug of slugs) {
|
|
288
|
+
if (!slug) continue;
|
|
289
|
+
if (seg === slug) return wsRaw;
|
|
290
|
+
// Truncated+hashed cursor slug: `<prefix>-<7+hex>` where prefix is a
|
|
291
|
+
// leading portion of the full slug. Require a non-trivial prefix so a
|
|
292
|
+
// short common head can't false-match an unrelated workspace.
|
|
293
|
+
const m = seg.match(/^(.*)-[0-9a-f]{6,}$/);
|
|
294
|
+
if (m && m[1] && m[1].length >= 8 && slug.startsWith(m[1])) return wsRaw;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
|
|
251
300
|
function readJsonlLines(p: string): any[] {
|
|
252
301
|
let text: string;
|
|
253
302
|
try { text = fs.readFileSync(p, 'utf8'); } catch { return []; }
|
|
@@ -95,6 +95,23 @@ export interface NativeHistoryJsonlSource {
|
|
|
95
95
|
session_id_from?: 'filename_uuid' | 'first_record';
|
|
96
96
|
session_id_path?: string;
|
|
97
97
|
message_filter?: { where: string };
|
|
98
|
+
/**
|
|
99
|
+
* Fallback workspace attribution when the transcript carries no
|
|
100
|
+
* `session_meta` cwd record. Some stores (cursor-agent) do NOT write a
|
|
101
|
+
* session_meta line and keep the workspace only in the on-disk project-slug
|
|
102
|
+
* directory (`~/.cursor/projects/<slug>/…`), which is a lossy, sometimes
|
|
103
|
+
* truncated+hashed transform of the real path and cannot be reversed. When
|
|
104
|
+
* this flag is set and no session_meta workspace was found, the executor
|
|
105
|
+
* stamps `input.workspace` onto each message — but ONLY after confirming the
|
|
106
|
+
* resolved file actually lives under that workspace's project slug (a path
|
|
107
|
+
* segment matches the input workspace's cursor/claude slug, allowing for
|
|
108
|
+
* cursor's length-truncation). This closes the first-turn read gap (before a
|
|
109
|
+
* provider session id is pinned, the downstream hasSafeNativeHistoryMapping
|
|
110
|
+
* guard needs a per-message workspace) without risking cross-workspace
|
|
111
|
+
* aliasing: a slug mismatch leaves the workspace unset and the read fails
|
|
112
|
+
* closed as before.
|
|
113
|
+
*/
|
|
114
|
+
workspace_from_input?: boolean;
|
|
98
115
|
message_map: NativeHistoryMessageMap;
|
|
99
116
|
}
|
|
100
117
|
|