@deep-podder/dsh-remote-mobile 0.0.5 → 0.0.7

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 (46) hide show
  1. package/PROTOCOL.md +97 -9
  2. package/README.md +49 -12
  3. package/SECURITY.md +8 -0
  4. package/auth.js +16 -0
  5. package/bridge.js +336 -9
  6. package/client.js +6 -1
  7. package/docs/api-notes.md +12 -4
  8. package/docs/engineering-audit.md +252 -0
  9. package/docs/reference-chat-demo.md +41 -0
  10. package/docs/screenshots/chat-light.png +0 -0
  11. package/docs/screenshots/commands-dark.png +0 -0
  12. package/docs/screenshots/pairing-light.png +0 -0
  13. package/docs/screenshots/sessions-light.png +0 -0
  14. package/docs/verification.md +40 -4
  15. package/index.js +1 -1
  16. package/mobile/README.md +81 -35
  17. package/mobile/app.js +4268 -906
  18. package/mobile/index.html +28 -17
  19. package/mobile/lib/away.js +45 -0
  20. package/mobile/lib/constants.js +5 -0
  21. package/mobile/lib/errors.js +42 -0
  22. package/mobile/lib/format.js +94 -0
  23. package/mobile/lib/lock.js +21 -0
  24. package/mobile/manifest.webmanifest +24 -0
  25. package/mobile/mock-server.js +442 -17
  26. package/mobile/model/history.js +119 -0
  27. package/mobile/model/question.js +318 -0
  28. package/mobile/model/turns.js +57 -0
  29. package/mobile/styles/base.css +143 -0
  30. package/mobile/{styles.css → styles/components.css} +1170 -826
  31. package/mobile/styles/overrides.css +269 -0
  32. package/mobile/styles/tokens.css +169 -0
  33. package/mobile/sw.js +28 -4
  34. package/package.json +34 -20
  35. package/protocol.js +87 -0
  36. package/push-policy.js +58 -0
  37. package/server/frames/activity.js +110 -0
  38. package/server/frames/connection.js +21 -0
  39. package/server/frames/history.js +23 -0
  40. package/server/frames/interactions.js +77 -0
  41. package/server/frames/prompts.js +29 -0
  42. package/server/frames/queue.js +58 -0
  43. package/server/frames/sessions.js +201 -0
  44. package/server/frames/settings.js +38 -0
  45. package/server/frames/subagents.js +50 -0
  46. package/server.js +341 -423
package/bridge.js CHANGED
@@ -622,11 +622,16 @@ export function createBridge(ctx, options = {}) {
622
622
  /**
623
623
  * Validate an answer batch against its questions and fill skipped items with
624
624
  * the documented blank answer `{ id, selected: [] }` (desktop Skip semantics).
625
+ *
626
+ * The single-select rule is enforced here too: `custom` overrides the chosen
627
+ * label, so a batch carrying both (an older cached SPA, or a future client)
628
+ * still reaches the agent in the documented shape.
625
629
  */
626
630
  function normalizeAnswerBatch(answers, questions) {
627
631
  if (!Array.isArray(answers)) throw new Error('answers must be an array');
628
632
  const known = new Set(questions.map((question) => question.id));
629
- const byId = new Map();
633
+ const byId = new Map(questions.map((question) => [question.id, question]));
634
+ const entries = new Map();
630
635
  for (const item of answers) {
631
636
  if (!isPlainObject(item) || typeof item.id !== 'string') throw new Error('every answer needs an id');
632
637
  if (!known.has(item.id)) throw new Error(`unknown answer id ${item.id}`);
@@ -635,10 +640,14 @@ export function createBridge(ctx, options = {}) {
635
640
  : [];
636
641
  const entry = { id: item.id, selected };
637
642
  if (typeof item.custom === 'string' && item.custom.length > 0) entry.custom = item.custom;
638
- byId.set(item.id, entry);
643
+ const question = byId.get(item.id);
644
+ if (question !== undefined && question.multiSelect !== true && entry.custom !== undefined) {
645
+ entry.selected = [];
646
+ }
647
+ entries.set(item.id, entry);
639
648
  }
640
- if (byId.size !== answers.length) throw new Error('duplicate answer ids');
641
- return { answers: questions.map((question) => byId.get(question.id) ?? { id: question.id, selected: [] }) };
649
+ if (entries.size !== answers.length) throw new Error('duplicate answer ids');
650
+ return { answers: questions.map((question) => entries.get(question.id) ?? { id: question.id, selected: [] }) };
642
651
  }
643
652
 
644
653
  /** Read the `answers` array out of a downstream answer object. */
@@ -961,6 +970,54 @@ export function createBridge(ctx, options = {}) {
961
970
  }
962
971
  }
963
972
 
973
+ /**
974
+ * Normalize one filesystem path into the shape a Workspace record holds:
975
+ * absolute, no trailing separator, and case-folded on Windows.
976
+ * Unresolvable input compares by its trimmed text so a missing drive letter
977
+ * never turns a lookup into a throw.
978
+ */
979
+ function comparablePath(value) {
980
+ const text = typeof value === 'string' ? value.trim() : '';
981
+ if (text.length === 0) return '';
982
+ let normalized = text;
983
+ try {
984
+ normalized = resolve(text);
985
+ } catch {
986
+ normalized = text;
987
+ }
988
+ normalized = normalized.replace(/[\\/]+$/, '');
989
+ return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
990
+ }
991
+
992
+ /**
993
+ * The registered project whose root is exactly `cwd`, if any.
994
+ *
995
+ * DSH files a Session under a project only when creation names the Workspace:
996
+ * `session.create` takes `workspaceId` xor `cwd`, and a cwd-only Session is
997
+ * never attached to a Workspace, so the desktop sidebar lists it as
998
+ * ungrouped. A directory that *is* a project root is therefore promoted to a
999
+ * `workspaceId` request, which also covers an older client that only sent a
1000
+ * path (a project chip used to fill the directory box).
1001
+ */
1002
+ function workspaceForPath(cwd) {
1003
+ const wanted = comparablePath(cwd);
1004
+ if (wanted.length === 0) return '';
1005
+ try {
1006
+ const registry = service('workspaceRegistry');
1007
+ if (!registry || typeof registry.list !== 'function') return '';
1008
+ const workspaces = registry.list();
1009
+ for (const workspace of Array.isArray(workspaces) ? workspaces : []) {
1010
+ const id = workspace === null || workspace === undefined ? '' : String(workspace.id ?? '');
1011
+ if (id.length === 0) continue;
1012
+ const path = typeof workspace.path === 'string' ? workspace.path : '';
1013
+ if (path.length > 0 && comparablePath(path) === wanted) return id;
1014
+ }
1015
+ } catch (error) {
1016
+ log.warn(`workspace path lookup failed: ${errorMessage(error)}`);
1017
+ }
1018
+ return '';
1019
+ }
1020
+
964
1021
  /** Whether the Host currently has a live Agent attached for this session. */
965
1022
  function agentIsLive(sessionId) {
966
1023
  return getLiveAgent(sessionId) !== undefined;
@@ -1047,6 +1104,14 @@ export function createBridge(ctx, options = {}) {
1047
1104
  if (action === 'archive' && /active/i.test(errorMessage(error))) {
1048
1105
  return failure('the session is running; stop it first or retry with stopActivity', 'bad-request');
1049
1106
  }
1107
+ if (action === 'attach' && /attach session/i.test(errorMessage(error))) {
1108
+ // The Host message quotes both absolute paths; the phone only needs the
1109
+ // reason, and path-free text keeps the wire free of Host locations.
1110
+ return failure(
1111
+ "this session's working directory is not that project's folder, so it cannot join it",
1112
+ 'bad-request',
1113
+ );
1114
+ }
1050
1115
  return failure(error);
1051
1116
  }
1052
1117
 
@@ -1448,11 +1513,34 @@ export function createBridge(ctx, options = {}) {
1448
1513
  }
1449
1514
 
1450
1515
  /** `agent/status` payload: `{ agent, status }` with status `'idle' | 'running'`. */
1451
- function onAgentStatus(payload) {
1516
+ async function onAgentStatus(payload) {
1452
1517
  const agent = payload?.agent;
1453
- if (!agent || isSubagentAgent(agent)) return;
1518
+ if (!agent) return;
1454
1519
  const sessionId = typeof agent.session?.id === 'string' ? agent.session.id : undefined;
1455
1520
  if (!sessionId) return;
1521
+ if (isSubagentAgent(agent)) {
1522
+ const header = agent.session?.header;
1523
+ let parentSessionId =
1524
+ (typeof header?.parentSessionId === 'string' && header.parentSessionId) ||
1525
+ (typeof agent.session?.parentSessionId === 'string' && agent.session.parentSessionId) ||
1526
+ '';
1527
+ if (!parentSessionId) {
1528
+ try {
1529
+ const summary = await findSummary(sessionId);
1530
+ if (typeof summary?.parentSessionId === 'string') parentSessionId = summary.parentSessionId;
1531
+ } catch (error) {
1532
+ log.warn(`subagent parent lookup failed: ${errorMessage(error)}`);
1533
+ }
1534
+ }
1535
+ if (parentSessionId) {
1536
+ emit('onSubagentStatus', {
1537
+ parentSessionId,
1538
+ subagentId: sessionId,
1539
+ running: payload.status === 'running',
1540
+ });
1541
+ }
1542
+ return;
1543
+ }
1456
1544
  emit('onStatus', { sessionId, running: payload.status === 'running' });
1457
1545
  }
1458
1546
 
@@ -1667,6 +1755,7 @@ export function createBridge(ctx, options = {}) {
1667
1755
 
1668
1756
  const wait = isPlainObject(request.wait) ? request.wait : undefined;
1669
1757
  const callId = wait !== undefined && typeof wait.callId === 'string' ? wait.callId : null;
1758
+ const timedWait = wait !== undefined && wait.timed === true;
1670
1759
  const requestId = newId();
1671
1760
  const signal = request.signal;
1672
1761
  const configuredHandoff = Number(opts.questionHandoffMs);
@@ -1721,7 +1810,15 @@ export function createBridge(ctx, options = {}) {
1721
1810
 
1722
1811
  const onAbort = () => {
1723
1812
  if (settled) return;
1724
- emit('onQuestionResolved', { sessionId, requestId, callId, answers: null, outcome: 'declined' });
1813
+ // A timed question whose foreground window closed is continued, not
1814
+ // declined: the Host still accepts an answer through the call id.
1815
+ emit('onQuestionResolved', {
1816
+ sessionId,
1817
+ requestId,
1818
+ callId,
1819
+ answers: null,
1820
+ outcome: timedWait && callId !== null ? 'continued' : 'declined',
1821
+ });
1725
1822
  finish(undefined);
1726
1823
  };
1727
1824
 
@@ -1842,7 +1939,108 @@ export function createBridge(ctx, options = {}) {
1842
1939
  // Public bridge surface
1843
1940
  // ---------------------------------------------------------------------------
1844
1941
 
1942
+ function subagentMode(entry) {
1943
+ const mode = entry?.mode;
1944
+ return mode === 'one-shot' || mode === 'external' || mode === 'continuable' ? mode : 'unknown';
1945
+ }
1946
+
1947
+ /** Map Host subagent catalog entries + summaries to the phone wire shape. */
1948
+ function wireSubagent(entry, summary, fallbackParentId) {
1949
+ const values = isPlainObject(summary?.projections?.values) ? summary.projections.values : {};
1950
+ const title =
1951
+ (typeof values.title === 'string' && values.title.trim()) ||
1952
+ (typeof entry?.label === 'string' && entry.label.trim()) ||
1953
+ 'Subagent';
1954
+ const base = summary ? wireSession(summary, {}) : null;
1955
+ const id = typeof entry?.id === 'string' ? entry.id : '';
1956
+ const live = agentIsLive(id) ? getLiveAgent(id) : null;
1957
+ const running = summary?.running === true || live?.status === 'running';
1958
+ const createdAt = Number.isFinite(entry?.createdAt) ? entry.createdAt : Number(summary?.updatedAt) || 0;
1959
+ const updatedAt = Number(summary?.updatedAt) || createdAt;
1960
+ return {
1961
+ id,
1962
+ parentId:
1963
+ (typeof entry?.parentId === 'string' && entry.parentId) ||
1964
+ (typeof summary?.parentSessionId === 'string' && summary.parentSessionId) ||
1965
+ fallbackParentId ||
1966
+ null,
1967
+ depth: Number.isInteger(entry?.depth) && entry.depth > 0 ? entry.depth : 1,
1968
+ label: typeof entry?.label === 'string' ? truncate(entry.label, 120) : '',
1969
+ mode: subagentMode(entry),
1970
+ title: truncate(title, 160),
1971
+ running,
1972
+ status: running ? 'running' : summary ? 'idle' : live ? 'idle' : 'unknown',
1973
+ createdAt,
1974
+ updatedAt,
1975
+ model: base?.model ?? null,
1976
+ preset: base?.preset ?? null,
1977
+ };
1978
+ }
1979
+
1845
1980
  return {
1981
+ /**
1982
+ * Read the subagent tree under one parent. Uses the cold-safe catalog when
1983
+ * available and falls back to persisted summaries; never streams prompts.
1984
+ */
1985
+ async listSubagents(parentSessionId) {
1986
+ if (!isSessionId(parentSessionId)) return [];
1987
+ let entries = [];
1988
+ try {
1989
+ const subagents = service('subagents');
1990
+ if (subagents && typeof subagents.listDescendants === 'function') {
1991
+ entries = await withSignal(
1992
+ (signal) => subagents.listDescendants(parentSessionId, signal),
1993
+ timeoutMs,
1994
+ );
1995
+ } else if (subagents && typeof subagents.listChildren === 'function') {
1996
+ entries = await withSignal(
1997
+ (signal) => subagents.listChildren(parentSessionId, signal),
1998
+ timeoutMs,
1999
+ );
2000
+ }
2001
+ } catch (error) {
2002
+ // The projection may be absent on older deployments; summaries still work.
2003
+ log.warn(`listDescendants failed: ${errorMessage(error)}`);
2004
+ entries = [];
2005
+ }
2006
+ let summaries = [];
2007
+ try {
2008
+ summaries = (await readSummaries()) ?? [];
2009
+ } catch (error) {
2010
+ summaries = [];
2011
+ }
2012
+ const children = summaries.filter(
2013
+ (item) => item && item.origin === 'subagent' && item.parentSessionId === parentSessionId,
2014
+ );
2015
+ if (entries.length === 0) {
2016
+ entries = children.map((item) => ({
2017
+ id: item.sessionId,
2018
+ parentId: item.parentSessionId,
2019
+ depth: 1,
2020
+ createdAt: Number(item.updatedAt) || 0,
2021
+ label: '',
2022
+ mode: 'unknown',
2023
+ }));
2024
+ }
2025
+ const byId = new Map();
2026
+ for (const summary of summaries) {
2027
+ if (summary?.sessionId) byId.set(summary.sessionId, summary);
2028
+ }
2029
+ const items = [];
2030
+ const seen = new Set();
2031
+ for (const entry of entries) {
2032
+ if (!entry || typeof entry.id !== 'string' || entry.id.length === 0) continue;
2033
+ if (seen.has(entry.id)) continue;
2034
+ seen.add(entry.id);
2035
+ items.push(wireSubagent(entry, byId.get(entry.id), parentSessionId));
2036
+ }
2037
+ items.sort((a, b) => {
2038
+ if (a.running !== b.running) return a.running ? -1 : 1;
2039
+ return b.createdAt - a.createdAt;
2040
+ });
2041
+ return items;
2042
+ },
2043
+
1846
2044
  /** All visible sessions, newest activity first. Subagent sessions are hidden. */
1847
2045
  async listSessions() {
1848
2046
  try {
@@ -1955,7 +2153,18 @@ export function createBridge(ctx, options = {}) {
1955
2153
  }
1956
2154
  },
1957
2155
 
1958
- /** Create a blank session, optionally bound to an agent preset. */
2156
+ /**
2157
+ * Create a blank session, optionally bound to an agent preset and to a
2158
+ * project.
2159
+ *
2160
+ * `workspaceId` and `cwd` are exclusive on the Host: a Workspace files the
2161
+ * Session under that project (desktop sidebar and phone both group it),
2162
+ * while a bare `cwd` creates a directory-only Session that stays ungrouped.
2163
+ * A `cwd` that is exactly a registered project root is sent as that
2164
+ * project's `workspaceId` instead.
2165
+ *
2166
+ * @returns the wire session (with `workspaceId`) or an error envelope.
2167
+ */
1959
2168
  async createSession(createOptions = {}) {
1960
2169
  try {
1961
2170
  const controller = service('sessionController');
@@ -1966,7 +2175,16 @@ export function createBridge(ctx, options = {}) {
1966
2175
  const preset = createOptions && typeof createOptions.preset === 'string' ? createOptions.preset : '';
1967
2176
  if (preset.length > 0) request.agentPreset = preset;
1968
2177
  const cwd = createOptions && typeof createOptions.cwd === 'string' ? createOptions.cwd.trim() : '';
1969
- if (cwd.length > 0) request.cwd = cwd;
2178
+ const workspaceId = createOptions && typeof createOptions.workspaceId === 'string'
2179
+ ? createOptions.workspaceId.trim()
2180
+ : '';
2181
+ if (workspaceId.length > 0) {
2182
+ request.workspaceId = workspaceId;
2183
+ } else if (cwd.length > 0) {
2184
+ const project = workspaceForPath(cwd);
2185
+ if (project.length > 0) request.workspaceId = project;
2186
+ else request.cwd = cwd;
2187
+ }
1970
2188
  const created = await controller.create(request);
1971
2189
  const id = typeof created?.sessionId === 'string' ? created.sessionId : '';
1972
2190
  if (!id) return failure('session creation returned no session id', 'internal');
@@ -1984,6 +2202,12 @@ export function createBridge(ctx, options = {}) {
1984
2202
  model: selectionRoute(defaultSelection()),
1985
2203
  }, workspace);
1986
2204
  } catch (error) {
2205
+ if (errorCode(error) === 'workspace/not-found') {
2206
+ return failure('that project does not exist any more; reopen the session sheet', 'not-found');
2207
+ }
2208
+ if (errorCode(error) === 'session/workspace-attach-failed') {
2209
+ return failure('the session was created but could not join that project', 'bad-request');
2210
+ }
1987
2211
  return failure(error);
1988
2212
  }
1989
2213
  },
@@ -2109,6 +2333,43 @@ export function createBridge(ctx, options = {}) {
2109
2333
  }
2110
2334
  },
2111
2335
 
2336
+ /**
2337
+ * Attach one existing Session to a registered project workspace.
2338
+ *
2339
+ * Navigation only: it changes which project section lists the Session, not
2340
+ * the Session's cwd, preset or sandbox. The Host's `attachSession` validates
2341
+ * that the Session's stored cwd resolves to the workspace root, so a Session
2342
+ * created in a subdirectory (or in a temp dir) is refused instead of being
2343
+ * misfiled. This is the repair path for Sessions created before the phone
2344
+ * named a project, and for paths typed by hand.
2345
+ *
2346
+ * @returns `{ ok:true, sessionId, workspaceId }` or an error envelope.
2347
+ */
2348
+ async attachSessionToWorkspace(sessionId, workspaceId) {
2349
+ try {
2350
+ if (!isSessionId(sessionId)) return failure('invalid sessionId', 'bad-request');
2351
+ if (typeof workspaceId !== 'string' || workspaceId.trim().length === 0) {
2352
+ return failure('workspaceId is required', 'bad-request');
2353
+ }
2354
+ const id = workspaceId.trim();
2355
+ const registry = service('workspaceRegistry');
2356
+ if (!registry || typeof registry.get !== 'function') {
2357
+ return failure('projects are unavailable in this deployment', 'internal');
2358
+ }
2359
+ const workspace = registry.get(id);
2360
+ if (workspace === undefined || workspace === null) {
2361
+ return failure('that project does not exist any more; reopen the list', 'not-found');
2362
+ }
2363
+ if (typeof workspace.attachSession !== 'function') {
2364
+ return failure('projects are unavailable in this deployment', 'internal');
2365
+ }
2366
+ await workspace.attachSession(sessionId);
2367
+ return { ok: true, sessionId, workspaceId: id };
2368
+ } catch (error) {
2369
+ return mapWorkspaceFailure(error, 'attach');
2370
+ }
2371
+ },
2372
+
2112
2373
  /**
2113
2374
  * Pin or unpin one session (registry-global; cold-safe).
2114
2375
  *
@@ -2280,6 +2541,49 @@ export function createBridge(ctx, options = {}) {
2280
2541
  }
2281
2542
  },
2282
2543
 
2544
+ /**
2545
+ * Read a subagent transcript. Generic session routing treats subagent
2546
+ * identities as owned by subagent routing, so read the child session
2547
+ * directly through sessionQuery and skip its inherited seed events.
2548
+ */
2549
+ async subagentHistory(parentSessionId, subagentId, historyOptions = {}) {
2550
+ if (!isSessionId(parentSessionId) || !isSessionId(subagentId)) return [];
2551
+ const limit = clampLimit(historyOptions && historyOptions.limit);
2552
+ const query = service('sessionQuery');
2553
+ if (!query || typeof query.observeSession !== 'function') return [];
2554
+ let source = null;
2555
+ try {
2556
+ source = await withSignal(
2557
+ (signal) => query.observeSession(subagentId, { signal }),
2558
+ HISTORY_TIMEOUT_MS,
2559
+ );
2560
+ if (!source || !Array.isArray(source.events)) return [];
2561
+ const header = isPlainObject(source.header) ? source.header : {};
2562
+ const owner =
2563
+ (typeof header.parentSession === 'string' && header.parentSession) ||
2564
+ (typeof header.parentSessionId === 'string' && header.parentSessionId) ||
2565
+ (typeof source.parentSessionId === 'string' && source.parentSessionId);
2566
+ if (owner && owner !== parentSessionId) return [];
2567
+ const inherited = Number.isSafeInteger(source.inheritedEventCount)
2568
+ ? Math.max(0, source.inheritedEventCount)
2569
+ : 0;
2570
+ const events = source.events.slice(inherited).slice(-limit);
2571
+ return mapHistory(events);
2572
+ } catch (error) {
2573
+ log.warn(`subagent history failed for ${subagentId}: ${errorMessage(error)}`);
2574
+ return [];
2575
+ } finally {
2576
+ // observeSession returns a disposable observation; release it so
2577
+ // polling a running child does not accumulate handles.
2578
+ try {
2579
+ if (source && typeof source[Symbol.dispose] === 'function') source[Symbol.dispose]();
2580
+ else if (source && typeof source.dispose === 'function') source.dispose();
2581
+ } catch {
2582
+ /* best effort */
2583
+ }
2584
+ }
2585
+ },
2586
+
2283
2587
  /**
2284
2588
  * Save one file uploaded by the phone into the session's workspace, so the
2285
2589
  * agent can read it with its normal file tools (images via read_image).
@@ -2927,6 +3231,29 @@ export function createBridge(ctx, options = {}) {
2927
3231
  }
2928
3232
  },
2929
3233
 
3234
+ /**
3235
+ * Dismiss a pending question from the phone, matching the desktop card's
3236
+ * close control: the Host waterfall settles without an answer batch instead
3237
+ * of receiving an all-blank one.
3238
+ *
3239
+ * @param {object} payload - `{ requestId? , callId? }`
3240
+ * @returns true when a live request was dismissed; false when it is gone.
3241
+ */
3242
+ async cancelQuestion(payload) {
3243
+ try {
3244
+ const requestId = typeof payload?.requestId === 'string' ? payload.requestId : undefined;
3245
+ if (requestId === undefined) return false;
3246
+ const pending = pendingQuestions.get(requestId);
3247
+ if (pending === undefined) return false;
3248
+ if (typeof pending.cancel !== 'function') return false;
3249
+ pending.cancel();
3250
+ return true;
3251
+ } catch (error) {
3252
+ log.warn(`cancelQuestion failed: ${errorMessage(error)}`);
3253
+ return false;
3254
+ }
3255
+ },
3256
+
2930
3257
  /**
2931
3258
  * Subscribe to live bridge events.
2932
3259
  * @param {object} subscription - `{ onAssistant, onTool, onApproval,
package/client.js CHANGED
@@ -3,7 +3,12 @@
3
3
  // expiry countdown and paired-device management. All data comes from the Host
4
4
  // server over a key-gated loopback endpoint.
5
5
  window.__ModuleLoader__.load({
6
- id: 'dsh-remote-mobile',
6
+ // The registration id MUST equal the client module's manifest row id (the
7
+ // package name). The module system keys factories by package name; a short
8
+ // id (e.g. `dsh-remote-mobile`) leaves the package row unresolved, so the
9
+ // bundle is loaded a second time and the second registration throws
10
+ // "duplicate factory registration".
11
+ id: '@deep-podder/dsh-remote-mobile',
7
12
  factory(require) {
8
13
  const React = require('react')
9
14
  const h = React.createElement
package/docs/api-notes.md CHANGED
@@ -115,7 +115,12 @@ Notes verified in `lib/types/history/controller.js` and `lib/types/history.js`:
115
115
  cold session, and returns `{ accepted: true }`. `mode` is required by the type
116
116
  and defaults to queue behaviour in the implementation; the bridge sends `'queue'`.
117
117
  - `create()` writes to `defaultCwd` (`process.cwd()` of the harness) when neither
118
- `workspaceId` nor `cwd` is given. The bridge deliberately never sends `cwd`.
118
+ `workspaceId` nor `cwd` is given. A `workspaceId` makes the Host attach the new session to
119
+ that Workspace (`workspace.attachSession`); a bare `cwd` never attaches, which is why a
120
+ phone-created chat used to appear **Ungrouped** on the desktop. The bridge sends
121
+ `workspaceId` for the project the phone picked and promotes a `cwd` that exactly equals a
122
+ registered project root; any other `cwd` stays ungrouped. `attachSession(sessionId,
123
+ workspaceId)` (`workspaceRegistry.get(id).attachSession`) moves an existing session in.
119
124
 
120
125
  ---
121
126
 
@@ -462,7 +467,8 @@ All bridge methods resolve; none reject.
462
467
  `listPresets → {presets:[],current:null}`.
463
468
  - `openSession` returns either `{ session, history }` or
464
469
  `{ ok: false, error: '<message>', errorCode: 'not-found'|'bad-request'|'internal' }`.
465
- - `createSession` returns a session object with `id`, or the same error envelope.
470
+ - `createSession` returns a session object with `id` (and `workspaceId` for a project create),
471
+ or the same error envelope.
466
472
  - `prompt`/`cancel`/`selectModel`/`selectPreset` resolve `undefined` on success
467
473
  and the error envelope on failure. `server.js`'s `callBridge()` already treats
468
474
  any object with `ok === false` as a thrown failure (`new Error(value.error)`),
@@ -563,7 +569,8 @@ All bridge methods resolve; none reject.
563
569
  |---|---|
564
570
  | `listSessions()` | `sessionController.list({}, signal)`; fallback `agents.list()` |
565
571
  | `openSession(id)` | `sessionController.events({address:{kind:'session',id},maxMessages:50})` + `list()` / `projections()` / `state()` |
566
- | `createSession({preset})` | `sessionController.create({agentPreset?})` |
572
+ | `createSession({preset,workspaceId,cwd})` | `sessionController.create({agentPreset?, workspaceId} \| {cwd})`; a `cwd` equal to a registered project root is sent as that `workspaceId` |
573
+ | `attachSessionToWorkspace(id,workspaceId)` | `workspaceRegistry.get(workspaceId).attachSession(id)` (navigation only; the Host validates the session's cwd) |
567
574
  | `history(id,{limit})` | `sessionController.events({..., maxMessages:limit})` |
568
575
  | `prompt(id,text,requestId)` | `sessionController.prompt({sessionId,requestId,mode:'queue',content:[{type:'text',text}]}, signal)` |
569
576
  | `cancel(id)` | `sessionController.cancel({sessionId})`; fallback `agent.cancel({kind:'user'})` |
@@ -576,7 +583,8 @@ All bridge methods resolve; none reject.
576
583
  | `subscribe(handlers)` | `ctx.on('agent/assistant-stream'|'session/event'|'agent/status'|'agent/error'|'approval/request'|'user-questions/request', {global:true})` |
577
584
  | `dispose()` | dispose listeners, settle pending approvals/questions, clear maps |
578
585
 
579
- The v2 surface (`createSession`, `renameSession`, `forkSession`, `searchSessions`,
586
+ The v2 surface (`createSession`, `attachSessionToWorkspace`, `renameSession`, `forkSession`,
587
+ `searchSessions`,
580
588
  `setSessionPinned/Archived`, `listQueue`/`updateQueue`, `contextFor`, `changesList/Diff`,
581
589
  `listCommands`/`executeCommand`, `saveUpload`/`readUpload`, `imageLimits`, `listModels`,
582
590
  `selectModel`, `listPresets`, `selectPreset`) is documented method-by-method in