my-durable 0.0.53 → 0.0.55

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 (28) hide show
  1. package/apps/dpi-backend/src/daemon.ts +18 -1
  2. package/apps/dpi-backend/src/doctor.ts +4 -3
  3. package/apps/dpi-backend/src/errors.ts +21 -0
  4. package/apps/dpi-backend/src/notify-sinks.ts +11 -4
  5. package/apps/dpi-backend/src/pair-cli.ts +45 -32
  6. package/apps/dpi-backend/src/routes.ts +73 -15
  7. package/apps/dpi-backend/src/store.ts +60 -9
  8. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-_rDvatx4.css → index-BfkkE43K.css} +1 -1
  9. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DKSCI99E.js +81 -0
  10. package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
  11. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/commands.ts +5 -3
  12. package/apps/dpi-playground/apps/dpi-playground-fe/src/client/worktree.ts +78 -0
  13. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/GitPanel.vue +9 -11
  14. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +53 -1
  15. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NetworkSidebar.vue +23 -1
  16. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NewSessionDialog.vue +10 -1
  17. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/SchedulesPanel.vue +4 -1
  18. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TopBar.vue +3 -1
  19. package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TreeRow.vue +15 -0
  20. package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +24 -0
  21. package/apps/dpi-sdk/src/api.ts +4 -1
  22. package/apps/dpi-tui/src/app.ts +37 -4
  23. package/apps/dpi-tui/src/commands.ts +3 -1
  24. package/apps/dpi-tui/src/pickers.ts +33 -1
  25. package/apps/dpi-tui/src/views.ts +11 -2
  26. package/bin/dpi.mjs +16 -3
  27. package/package.json +1 -1
  28. package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-CBxu8tMi.js +0 -81
@@ -7,8 +7,8 @@
7
7
  <meta name="referrer" content="no-referrer" />
8
8
  <link rel="icon" type="image/svg+xml" href="/icons/durable-pi.svg" />
9
9
  <title>Durable Pi | Network</title>
10
- <script type="module" crossorigin src="/assets/index-CBxu8tMi.js"></script>
11
- <link rel="stylesheet" crossorigin href="/assets/index-_rDvatx4.css">
10
+ <script type="module" crossorigin src="/assets/index-DKSCI99E.js"></script>
11
+ <link rel="stylesheet" crossorigin href="/assets/index-BfkkE43K.css">
12
12
  </head>
13
13
  <body>
14
14
  <div id="app"></div>
@@ -7,6 +7,7 @@ import {
7
7
  refreshDetail,
8
8
  select,
9
9
  selected,
10
+ sessionAgents,
10
11
  sessionHandle,
11
12
  showInspector,
12
13
  ui,
@@ -50,9 +51,10 @@ export const commands: SlashCommand[] = [
50
51
  description: "New agent in this workspace",
51
52
  run: async (arg) => {
52
53
  const t = need(selected.value, "workspace");
53
- const created = await need(sessionHandle.value, "workspace").createAgent(
54
- arg ? { name: arg } : {},
55
- );
54
+ // The device API requires a name (B6); without an argument, number the new agent.
55
+ const created = await need(sessionHandle.value, "workspace").createAgent({
56
+ name: arg || `Agent ${sessionAgents.value.length + 1}`,
57
+ });
56
58
  select({ ...t, agentId: created.id });
57
59
  notify(`New agent ${created.name}.`);
58
60
  },
@@ -0,0 +1,78 @@
1
+ // Worktree sessions, shared by the Git tab and the session tree (F3): the
2
+ // sibling-target rule (<parent>/<base>-<branch>) lives here once so the two
3
+ // entry points cannot drift. GitPanel keeps its own busy/notify chrome around
4
+ // the same calls; the session list gets the whole flow in one function.
5
+ import type { DpiClient, GitStatus } from "@sdk/client";
6
+ import type { SessionSummary } from "@sdk/api";
7
+
8
+ /** What the flow needs from a device client — structural, so a stub (tests,
9
+ * other transports) can stand in without constructing a real DpiClient. */
10
+ export interface WorktreeApi {
11
+ gitStatus: DpiClient["gitStatus"];
12
+ gitOp: DpiClient["gitOp"];
13
+ createSession: DpiClient["createSession"];
14
+ }
15
+
16
+ /** Sibling checkout target: <parent>/<base>-<branch>. Path separators in the
17
+ * branch are flattened to dashes — a branch may contain them, a folder may not. */
18
+ export function worktreeTarget(root: string, branch: string): string {
19
+ const parent = root.slice(0, root.lastIndexOf("/"));
20
+ const base = root.slice(root.lastIndexOf("/") + 1);
21
+ return `${parent}/${base}-${branch.replace(/[/\\]+/g, "-")}`;
22
+ }
23
+
24
+ /** `git worktree add` into the sibling target — the extracted half of the old
25
+ * GitPanel.addWorktree. Returns the target plus the op's first line (notify). */
26
+ export async function addWorktree(
27
+ deviceApi: Pick<WorktreeApi, "gitOp">,
28
+ cwd: string,
29
+ root: string,
30
+ branch: string,
31
+ ): Promise<{ target: string; text: string }> {
32
+ const target = worktreeTarget(root, branch);
33
+ const r = await deviceApi.gitOp(cwd, "worktree-add", { branch, target });
34
+ return { target, text: r.text.split("\n")[0] ?? `worktree ${target}` };
35
+ }
36
+
37
+ /** Open a session in an existing folder — the extracted half of the old
38
+ * GitPanel.sessionOn. Model optional: absent = the device's (or the
39
+ * project's) default, the same rule as every other create call. */
40
+ export async function createSessionOn(
41
+ deviceApi: Pick<WorktreeApi, "createSession">,
42
+ path: string,
43
+ name: string,
44
+ model?: { provider: string; modelId: string },
45
+ ): Promise<SessionSummary> {
46
+ return deviceApi.createSession(model ? { name, cwd: path, model } : { name, cwd: path });
47
+ }
48
+
49
+ export interface CreateWorktreeSessionArgs {
50
+ deviceApi: WorktreeApi;
51
+ cwd: string;
52
+ sessionName: string;
53
+ branch: string;
54
+ /** Repo root when the caller already has it (GitPanel's cached status);
55
+ * resolved from the device otherwise. */
56
+ root?: string;
57
+ }
58
+
59
+ /** Worktree + session in one call (session tree, F3): add the sibling
60
+ * checkout, then open the session right in it. worktree-add runs first, so a
61
+ * rejected add never leaves a session behind, and the session's cwd is
62
+ * exactly the folder git just made. */
63
+ export async function createWorktreeSession({
64
+ deviceApi,
65
+ cwd,
66
+ sessionName,
67
+ branch,
68
+ root,
69
+ }: CreateWorktreeSessionArgs): Promise<SessionSummary> {
70
+ let repoRoot = root;
71
+ if (!repoRoot) {
72
+ const status: GitStatus = await deviceApi.gitStatus(cwd);
73
+ if (!status.repo || !status.root) throw Error(`${cwd} is not a git repository`);
74
+ repoRoot = status.root;
75
+ }
76
+ const { target } = await addWorktree(deviceApi, cwd, repoRoot, branch);
77
+ return createSessionOn(deviceApi, target, sessionName);
78
+ }
@@ -35,6 +35,7 @@ import {
35
35
  import { deviceId, network, sessionSummary, notify, select } from "../client/store";
36
36
  import { deviceClient } from "../client/hub";
37
37
  import { ensureGit, gitEntry, wireGitAutoRefresh } from "../client/git-store";
38
+ import { addWorktree as gitAddWorktree, createSessionOn } from "../client/worktree";
38
39
  import type { GitStatus } from "@sdk/client";
39
40
 
40
41
  const props = defineProps<{ deviceId?: string; cwd?: string }>();
@@ -717,14 +718,10 @@ watch(cpsOpen, (open) => {
717
718
  async function addWorktree(branch: string) {
718
719
  wtMenu.value = false;
719
720
  if (!devId.value || !cwd.value || !status.value?.root) return;
720
- const root = status.value.root;
721
- const parent = root.slice(0, root.lastIndexOf("/"));
722
- const base = root.slice(root.lastIndexOf("/") + 1);
723
- const target = `${parent}/${base}-${branch.replace(/[/\\]+/g, "-")}`;
724
721
  busy.value = "wt";
725
722
  try {
726
- const r = await deviceClient(devId.value).gitOp(cwd.value, "worktree-add", { branch, target });
727
- notify(r.text.split("\n")[0] ?? `worktree ${target}`);
723
+ const r = await gitAddWorktree(deviceClient(devId.value), cwd.value, status.value.root, branch);
724
+ notify(r.text);
728
725
  newBranch.value = "";
729
726
  await refresh();
730
727
  } catch (e) {
@@ -741,11 +738,12 @@ async function sessionOn(path: string, branch: string | null) {
741
738
  const info = network.devices.value.find((d) => d.id === devId.value)?.info;
742
739
  const model = modelCandidates(info)[0];
743
740
  if (!model) return notify(`no model available on ${devId.value} — cannot create a session`);
744
- const s = await deviceClient(devId.value).createSession({
745
- name: branch ?? path.slice(path.lastIndexOf("/") + 1),
746
- cwd: path,
747
- model: { provider: model.provider, modelId: model.id },
748
- });
741
+ const s = await createSessionOn(
742
+ deviceClient(devId.value),
743
+ path,
744
+ branch ?? path.slice(path.lastIndexOf("/") + 1),
745
+ { provider: model.provider, modelId: model.id },
746
+ );
749
747
  select({ deviceId: devId.value, sessionId: s.id, agentId: 1 });
750
748
  notify(`session "${s.name}" on ${path}`);
751
749
  } catch (e) {
@@ -204,6 +204,57 @@ function renameSession() {
204
204
  };
205
205
  }
206
206
 
207
+ /** Per-project default models (same fetch as NewSessionDialog): they decide
208
+ * what "(default)" means for the current session — the project's model when
209
+ * the cwd names a registered root, the device's otherwise. */
210
+ const projectModels = ref<Record<string, { provider: string; modelId: string }>>({});
211
+ watch(
212
+ device,
213
+ async (d) => {
214
+ projectModels.value = {};
215
+ if (!d) return;
216
+ try {
217
+ const { projects } = await deviceClient(d.id).projects(true);
218
+ projectModels.value = Object.fromEntries(
219
+ projects.filter((p) => p.model).map((p) => [p.rootPath, p.model!]),
220
+ );
221
+ } catch {
222
+ /* older device: no project defaults, the device default stays */
223
+ }
224
+ },
225
+ { immediate: true },
226
+ );
227
+ /** The current model with provenance: the agent's configured model when set,
228
+ * else the model the session was created with (SessionSummary). */
229
+ const sessionModel = computed(() => {
230
+ const m = agentState.value.agent.model;
231
+ if (m?.modelId) return m;
232
+ const s = sessionSummary.value;
233
+ return s?.model ? { provider: s.provider ?? "", modelId: s.model } : undefined;
234
+ });
235
+ /** Longest registered root wins — the same rule the device applies on create. */
236
+ const modelIsDefault = computed(() => {
237
+ const m = sessionModel.value;
238
+ if (!m) return false;
239
+ const cwd = sessionSummary.value?.cwd;
240
+ const roots = Object.keys(projectModels.value)
241
+ .filter((root) => cwd === root || (cwd ?? "").startsWith(`${root}/`))
242
+ .sort((a, b) => b.length - a.length);
243
+ const projectDefault = roots.length ? projectModels.value[roots[0]] : undefined;
244
+ const key = projectDefault
245
+ ? `${projectDefault.provider}/${projectDefault.modelId}`
246
+ : (device.value?.info?.defaultModel ?? "");
247
+ return Boolean(key) && key === `${m.provider}/${m.modelId}`;
248
+ });
249
+ /** "model: <id> (<provider>)" + " (default)" when it is the effective default. */
250
+ const modelLine = computed(
251
+ () =>
252
+ sessionModel.value &&
253
+ `model: ${sessionModel.value.modelId} (${sessionModel.value.provider})${
254
+ modelIsDefault.value ? " (default)" : ""
255
+ }`,
256
+ );
257
+
207
258
  // ------------------------------------------------------------ App State (device-wide document)
208
259
 
209
260
  const shared = deviceFeed.sharedState;
@@ -396,11 +447,12 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
396
447
  </div>
397
448
  <ChevronDown :size="18" />
398
449
  </button>
450
+ <p v-if="modelLine" class="hint model-provenance">{{ modelLine }}</p>
399
451
  <div class="thinking-row">
400
452
  <span>Thinking</span
401
453
  ><select
402
454
  aria-label="Thinking level"
403
- :value="agentState.agent.thinkingLevel ?? 'low'"
455
+ :value="agentState.agent.thinkingLevel ?? 'medium'"
404
456
  @change="
405
457
  configure(
406
458
  { thinkingLevel: ($event.target as HTMLSelectElement).value as ThinkingLevel },
@@ -6,6 +6,7 @@ import type { TreeNode } from "@sdk/models";
6
6
  import TreeRow from "./TreeRow.vue";
7
7
  import ProjectBar from "./ProjectBar.vue";
8
8
  import { deviceClient, hub } from "../client/hub";
9
+ import { createWorktreeSession } from "../client/worktree";
9
10
  import {
10
11
  attempt,
11
12
  expanded,
@@ -193,7 +194,8 @@ async function action(node: TreeNode, name: string) {
193
194
  if (node.type === "session") {
194
195
  const s = node.session;
195
196
  if (name === "new-agent") {
196
- const created = await attempt(() => client.session(s.id).createAgent({}));
197
+ // The device API requires a name (B6); number the new agent from the tree.
198
+ const created = await attempt(() => client.session(s.id).createAgent({ name: `Agent ${s.agents.length + 1}` }));
197
199
  if (created) {
198
200
  select({ deviceId: device.id, sessionId: s.id, agentId: created.id });
199
201
  notify("New agent. Same session, same shared App State.");
@@ -207,6 +209,26 @@ async function action(node: TreeNode, name: string) {
207
209
  submit: "Save name",
208
210
  run: (value) => client.session(s.id).rename(value),
209
211
  };
212
+ else if (name === "worktree")
213
+ ui.dialog = {
214
+ kind: "prompt",
215
+ title: "New worktree session",
216
+ label: "Branch name",
217
+ value: s.name.replace(/[/\\]+/g, "-"),
218
+ hint: `Adds a sibling checkout of ${s.cwd} on the branch (git worktree add) and opens a session in it.`,
219
+ submit: "Create worktree session",
220
+ run: async (branch) => {
221
+ const created = await createWorktreeSession({
222
+ deviceApi: client,
223
+ cwd: s.cwd,
224
+ sessionName: branch,
225
+ branch,
226
+ });
227
+ const root = created.agents.find((a) => a.kind === "root") ?? created.agents[0];
228
+ select({ deviceId: device.id, sessionId: created.id, agentId: root?.id ?? 1 });
229
+ notify(`session "${created.name}" on ${created.cwd}`);
230
+ },
231
+ };
210
232
  else if (name === "archive")
211
233
  ui.dialog = {
212
234
  kind: "prompt",
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, ref, watch } from "vue";
3
3
  import { Plus, X } from "lucide-vue-next";
4
+ import { THINKING_LEVELS, type ThinkingLevel } from "@sdk/api";
4
5
  import DirBrowser from "./DirBrowser.vue";
5
6
  import { deviceClient, message } from "../client/hub";
6
7
  import { network, notify, select } from "../client/store";
@@ -41,7 +42,7 @@ const catalogEmpty = computed(
41
42
  /** The device lists its built-in catalog but chat needs the key (0.0.12+ devices). */
42
43
  const keyless = computed(() => !!(device.value?.info as { providerKeyMissing?: boolean } | undefined)?.providerKeyMissing);
43
44
  const key = (m: { provider: string; id: string }) => `${m.provider}/${m.id}`;
44
- const draft = ref({ name: "", cwd: "", model: "" });
45
+ const draft = ref({ name: "", cwd: "", model: "", thinking: "medium" as ThinkingLevel });
45
46
  /** orca new-workspace composer: the last N working dirs per device, one click
46
47
  * away. localStorage only — the device never learns about recents. */
47
48
  const RECENT_KEY = "dpi-recent-cwds";
@@ -123,6 +124,7 @@ async function create() {
123
124
  name: draft.value.name.trim() || "New session",
124
125
  cwd: draft.value.cwd.trim(),
125
126
  model: { provider: model.provider, modelId: model.id },
127
+ thinkingLevel: draft.value.thinking,
126
128
  });
127
129
  rememberCwd(device.value.id, created.cwd);
128
130
  const root = created.agents.find((a) => a.kind === "root") ?? created.agents[0];
@@ -202,6 +204,13 @@ async function create() {
202
204
  </option>
203
205
  </select></label
204
206
  >
207
+ <label
208
+ >Thinking<select v-model="draft.thinking" aria-label="New session thinking level">
209
+ <option v-for="level in THINKING_LEVELS" :key="level" :value="level">
210
+ {{ level }}
211
+ </option>
212
+ </select></label
213
+ >
205
214
  </template>
206
215
  <p v-if="error" class="message-error" role="alert">{{ error }}</p>
207
216
  <footer>
@@ -35,6 +35,9 @@ async function load() {
35
35
  loading.value = false;
36
36
  }
37
37
  }
38
+ /** The empty state must wait for the first fetch: a tunnel first-hit can take
39
+ * seconds, and "No schedules yet." painted at ~11ms was a lie the real list
40
+ * replaced at ~4s. Same class as the modelsLoading fix (0.0.47). */
38
41
  watch(deviceId, load, { immediate: true });
39
42
 
40
43
  const when = (at: number | null) => {
@@ -168,7 +171,7 @@ async function save() {
168
171
  </form>
169
172
 
170
173
  <p v-if="!adding && !schedules.length && deviceId && !error" class="hint">
171
- No schedules yet. Press + to add one.
174
+ {{ loading ? "Reading schedules…" : "No schedules yet. Press + to add one." }}
172
175
  </p>
173
176
 
174
177
  <ul v-if="schedules.length" class="schedule-list">
@@ -13,6 +13,7 @@ import {
13
13
  online,
14
14
  select,
15
15
  selected,
16
+ sessionAgents,
16
17
  sessionHandle,
17
18
  streamState,
18
19
  ui,
@@ -61,7 +62,8 @@ async function newAgent() {
61
62
  const t = selected.value;
62
63
  if (!handle || !t || creatingAgent.value) return;
63
64
  creatingAgent.value = true;
64
- const created = await attempt(() => handle.createAgent({}));
65
+ // The device API requires a name (B6); without a prompt, number the new agent.
66
+ const created = await attempt(() => handle.createAgent({ name: `Agent ${sessionAgents.value.length + 1}` }));
65
67
  creatingAgent.value = false;
66
68
  if (created) {
67
69
  select({ ...t, agentId: created.id });
@@ -12,6 +12,7 @@ import {
12
12
  RefreshCw,
13
13
  Archive,
14
14
  KeyRound,
15
+ Split,
15
16
  } from "lucide-vue-next";
16
17
  import DeviceIcon from "./DeviceIcon.vue";
17
18
  import type { TreeNode } from "@sdk/models";
@@ -176,6 +177,12 @@ const title = computed(() => {
176
177
  <b class="name">{{ label }}</b>
177
178
  <span class="path">…/{{ session.cwd.split("/").filter(Boolean).at(-1) }}</span>
178
179
  <span v-if="branch" class="branch" :title="`git branch of ${session.cwd}`">⎇ {{ branch }}</span>
180
+ <span
181
+ v-if="session.model"
182
+ class="tag"
183
+ :title="session.provider ? `${session.provider} / ${session.model}` : session.model"
184
+ >{{ session.model }}</span
185
+ >
179
186
  <i v-if="busy" class="dot work" title="Working" />
180
187
  <span v-if="background" class="bg-count" :title="`${background} background task(s)`"
181
188
  ><i class="dot bg" />{{ background }} bg</span
@@ -197,6 +204,14 @@ const title = computed(() => {
197
204
  @click="emit('action', 'rename')"
198
205
  >
199
206
  <Pencil :size="16" /></button
207
+ ><button
208
+ class="icon-button"
209
+ :disabled="!online"
210
+ :aria-label="`New worktree session from ${label}`"
211
+ title="New worktree session: branch this folder's repo and open a session in the sibling checkout"
212
+ @click="emit('action', 'worktree')"
213
+ >
214
+ <Split :size="16" /></button
200
215
  ><button
201
216
  class="icon-button"
202
217
  :disabled="!online"
@@ -40,7 +40,31 @@ import {
40
40
  HUB_BUFFER_BUDGET_BYTES,
41
41
  } from "../../../../dpi-sdk/src/protocol/limits.js";
42
42
 
43
+ // Help must never boot the server: the flag parser below only knows value
44
+ // flags, so --help has to be answered here — before the registry opens, a
45
+ // token is minted or the listener binds.
46
+ const HUB_USAGE = `dpi hub — web UI + device tunnel server
47
+
48
+ Usage:
49
+ dpi hub [--port 4781] [--host 127.0.0.1] [--public-host <host>] [--dev]
50
+
51
+ --port N hub port (DPI_HUB_PORT, default 4781)
52
+ --host H interface to bind (DPI_HUB_HOST, default 127.0.0.1)
53
+ --public-host H browser-facing host when behind the TLS proxy
54
+ (DPI_HUB_PUBLIC_HOST; also turns on the require-TLS checks,
55
+ DPI_HUB_REQUIRE_TLS overrides either way)
56
+ --dev serve the web client from Vite instead of the built shell
57
+ (local development only)
58
+
59
+ Environment: DPI_HOME, DPI_HUB_PORT, DPI_HUB_HOST, DPI_HUB_PUBLIC_HOST,
60
+ DPI_HUB_ORIGIN, DPI_HUB_REQUIRE_TLS
61
+ `;
62
+
43
63
  const args = process.argv.slice(2);
64
+ if (args.includes("--help") || args.includes("-h") || args[0] === "help") {
65
+ process.stdout.write(HUB_USAGE);
66
+ process.exit(0);
67
+ }
44
68
  const option = (key: string, fallback: string) => {
45
69
  const i = args.indexOf(key);
46
70
  if (i < 0) return fallback;
@@ -54,7 +54,7 @@ export type ErrorCode =
54
54
  | "offline"
55
55
  | "rate_limited"
56
56
  | "timeout";
57
- export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
57
+ export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
58
58
  export const THINKING_LEVELS: readonly ThinkingLevel[] = [
59
59
  "off",
60
60
  "minimal",
@@ -62,6 +62,7 @@ export const THINKING_LEVELS: readonly ThinkingLevel[] = [
62
62
  "medium",
63
63
  "high",
64
64
  "xhigh",
65
+ "max",
65
66
  ];
66
67
  export type WhenBusy = "followUp" | "steer" | "reject";
67
68
 
@@ -146,6 +147,8 @@ export interface SessionSummary {
146
147
  name: string;
147
148
  cwd: string;
148
149
  model: string;
150
+ /** Provider id of the session's model ("faux" offline; same column the catalog stores). */
151
+ provider: string;
149
152
  createdAt: number;
150
153
  dbPath: string;
151
154
  busy: boolean;
@@ -84,19 +84,48 @@ export function slashSuggestions(
84
84
  return names.length ? { names, prefix } : null;
85
85
  }
86
86
 
87
+ // The palette mirrors the "slash" door: the 4 view switches first, then
88
+ // every command COMMANDS (commands.ts) knows — the same handler runs for both
89
+ // entrances, so behavior can never drift between them.
87
90
  const PALETTE: { name: string; hint: string; run: (a: App) => void }[] = [
88
91
  { name: "herd", hint: "session dashboard", run: (a) => a.setView("herd") },
89
92
  { name: "network", hint: "devices and sessions", run: (a) => a.setView("network") },
90
93
  { name: "agent", hint: "back to the conversation", run: (a) => a.setView("agent") },
91
94
  { name: "log", hint: "device events", run: (a) => a.setView("log") },
92
95
  { name: "sessions", hint: "switch or create a session", run: (a) => void a.command("sessions") },
96
+ { name: "agents", hint: "switch agent: roots, forks, subagents", run: (a) => void a.command("agents") },
93
97
  { name: "model", hint: "choose this agent's model", run: (a) => void a.command("model") },
98
+ { name: "devices", hint: "switch device", run: (a) => void a.command("devices") },
99
+ { name: "new", hint: "new agent in this session", run: (a) => void a.command("new") },
94
100
  { name: "fork", hint: "fork at the last reply", run: (a) => void a.command("fork") },
101
+ { name: "thinking", hint: "set the thinking level", run: (a) => void a.command("thinking") },
95
102
  { name: "compact", hint: "summarize older context", run: (a) => void a.command("compact") },
103
+ { name: "reset", hint: "start a fresh context", run: (a) => void a.command("reset") },
104
+ { name: "name", hint: "rename this agent", run: (a) => void a.command("name") },
105
+ { name: "tasks", hint: "live tasks in this session", run: (a) => void a.command("tasks") },
106
+ { name: "git", hint: "git on the session's folder", run: (a) => void a.command("git") },
107
+ { name: "help", hint: "keys and commands", run: (a) => void a.command("help") },
96
108
  { name: "pair", hint: "pair this device with a hub", run: (a) => void a.command("pair") },
97
109
  { name: "quit", hint: "exit (the agent keeps running)", run: (a) => a.exit() },
98
110
  ];
99
111
 
112
+ /** The palette's live filter — ONE predicate shared by the rendered list and
113
+ * enter, so what enter runs is always a row the filter actually showed
114
+ * (typing "device events" narrows to `log`; enter used to answer
115
+ * ◆ no command "device events"). */
116
+ const paletteRows = (query: string) =>
117
+ PALETTE.filter((p) => p.name.includes(query) || p.hint.includes(query));
118
+
119
+ /** Enter's deterministic pick: an exact name wins; otherwise the query must
120
+ * narrow the palette to exactly one row; anything wider (or empty) keeps the
121
+ * no-command toast rather than guessing which row was meant. */
122
+ const palettePick = (query: string) => {
123
+ const exact = PALETTE.find((p) => p.name === query);
124
+ if (exact) return exact;
125
+ const rows = paletteRows(query);
126
+ return rows.length === 1 ? rows[0] : undefined;
127
+ };
128
+
100
129
  const newId = () => crypto.randomUUID();
101
130
  const shellWord = (s: string) => (/^[\w.:@/~-]+$/.test(s) ? s : `'${s}'`);
102
131
  const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
@@ -709,7 +738,7 @@ export class App {
709
738
  this.cursor = 0;
710
739
  this.notify(this.filter ? `filter: ${this.filter}` : "filter cleared");
711
740
  } else if (input.kind === "palette") {
712
- const cmd = PALETTE.find((p) => p.name.startsWith(value.trim()));
741
+ const cmd = palettePick(value.trim());
713
742
  if (cmd) cmd.run(this);
714
743
  else this.notify(`no command “${value.trim()}”`);
715
744
  } else if (input.kind === "kill") {
@@ -1033,7 +1062,7 @@ export class App {
1033
1062
  if (!wide) return table;
1034
1063
  const selected = this.sessions.find((s) => s.id === (this.selectedId ?? this.sessionId));
1035
1064
  if (selected?.cwd) this.refreshGit(selected.cwd);
1036
- const panel = renderHerdPanel(panelW, h, selected, this.contextLeft(), this.device.name, this.gitOf(selected?.cwd));
1065
+ const panel = renderHerdPanel(panelW, h, selected, this.contextLeft(), this.device.name, this.gitOf(selected?.cwd), this.info.defaultModel);
1037
1066
  return joinPanel(table, panel, tableW, w, h);
1038
1067
  }
1039
1068
 
@@ -1184,7 +1213,11 @@ export class App {
1184
1213
  private logBody(w: number, h: number): string[] {
1185
1214
  const rows = this.events.filter((e) => !this.filter || e.text.toLowerCase().includes(this.filter.toLowerCase()));
1186
1215
  const lines = [c.muted(` ${this.events.length} events · this client`)];
1187
- const visible = h - 1;
1216
+ // A committed filter persists here like the herd's `filter: X` line — a
1217
+ // transient toast alone read as "events vanished", not "events hidden".
1218
+ if (this.filter)
1219
+ lines.push(c.warn(` filter: ${this.filter} · ${rows.length}/${this.events.length} shown — esc clears`));
1220
+ const visible = h - lines.length;
1188
1221
  for (const e of rows.slice(-visible)) lines.push(` ${c.muted(e.at)} ${c.accent(e.glyph)} ${c.text(e.text.slice(0, w - 18))}`);
1189
1222
  return lines;
1190
1223
  }
@@ -1245,7 +1278,7 @@ export class App {
1245
1278
 
1246
1279
  private palettePanel(w: number, h: number): string[] {
1247
1280
  const query = (this.input?.value ?? "").trim();
1248
- const items = PALETTE.filter((p) => p.name.includes(query) || p.hint.includes(query));
1281
+ const items = paletteRows(query);
1249
1282
  const width = Math.min(62, w - 4);
1250
1283
  const height = Math.min(items.length + 2, h);
1251
1284
  const x = Math.floor((w - width) / 2);
@@ -133,7 +133,9 @@ export async function runCommand(app: App, text: string): Promise<boolean> {
133
133
  break;
134
134
  }
135
135
  await app.run(async () => {
136
- const created = await app.client.session(app.sessionId!).createAgent(arg ? { name: arg } : {});
136
+ // The device API requires a name (B6); without an argument, number the new agent.
137
+ const name = arg || `Agent ${app.session.state.agents.length + 1}`;
138
+ const created = await app.client.session(app.sessionId!).createAgent({ name });
137
139
  await app.attach(app.sessionId!, created.id);
138
140
  app.flash(`New agent ${created.name}`);
139
141
  });
@@ -11,6 +11,7 @@ import {
11
11
  type Focusable,
12
12
  type SelectItem,
13
13
  } from "@earendil-works/pi-tui";
14
+ import { THINKING_LEVELS, type ThinkingLevel } from "../../dpi-sdk/src/api.ts";
14
15
  import { agentTree, type TreeNode } from "../../dpi-sdk/src/models.ts";
15
16
  import type { App } from "./app.ts";
16
17
  import { c, selectTheme } from "./theme.ts";
@@ -286,8 +287,17 @@ export async function newSession(app: App, presetName?: string) {
286
287
  ? await chooseModel(app, app.info.defaultModel)
287
288
  : { provider: (app.info as { provider?: string }).provider ?? "openrouter", id: app.info.defaultModel, name: "(device default)" };
288
289
  if (!model) return;
290
+ // Thinking rides the create call: pick a level up front instead of paying
291
+ // for "high" on a scratch session the device default never asked for.
292
+ const thinking = await chooseThinking(app);
293
+ if (!thinking) return;
289
294
  await app.run(async () => {
290
- const s = await app.client.createSession({ name: name || "New session", cwd, model: { provider: model.provider, modelId: model.id } });
295
+ const s = await app.client.createSession({
296
+ name: name || "New session",
297
+ cwd,
298
+ model: { provider: model.provider, modelId: model.id },
299
+ thinkingLevel: thinking,
300
+ });
291
301
  await app.attach(s.id, s.agents.find((a) => a.kind === "root")?.id ?? 1);
292
302
  app.flash(`Session created in ${cwd}`);
293
303
  if (!models.length) app.flash(`no model catalog on the device — using its default (${app.info.defaultModel})`);
@@ -346,6 +356,28 @@ function chooseModel(app: App, current?: string) {
346
356
  });
347
357
  }
348
358
 
359
+ /** The new-session thinking step: the same levels `y` cycles in-session. */
360
+ function chooseThinking(app: App) {
361
+ return new Promise<ThinkingLevel | undefined>((done) => {
362
+ const picker = new Picker(
363
+ "Thinking level",
364
+ THINKING_LEVELS.map((level) => ({ value: level, label: level })),
365
+ (item) => {
366
+ app.closeOverlay();
367
+ done(item.value as ThinkingLevel);
368
+ },
369
+ () => {
370
+ app.closeOverlay();
371
+ done(undefined);
372
+ },
373
+ );
374
+ // Preselect the backend's create default, so a bare enter keeps "medium".
375
+ const index = THINKING_LEVELS.indexOf("medium");
376
+ if (index >= 0) picker.list.setSelectedIndex(index);
377
+ app.overlay(picker);
378
+ });
379
+ }
380
+
349
381
  export async function pickModel(app: App) {
350
382
  if (!app.handle) return;
351
383
  const model = await chooseModel(app, app.model.state.agent.model?.modelId);
@@ -150,7 +150,11 @@ export function renderHerd(
150
150
  if (showAge) line += ` ${fit(c.muted(ageOf(s.createdAt)), cols.age)}`;
151
151
  lines.push(atCursor && !selected ? c.inverse(fit(line, w)) : fit(line, w));
152
152
  }
153
- if (!rows.length && !opts.filter) {
153
+ if (!rows.length && opts.filter) {
154
+ // A filter that matches nothing must say so: 0 rows alone reads as
155
+ // "the sessions vanished", not "your filter is hiding them".
156
+ lines.push("", ` ${c.muted(`no sessions match “${opts.filter}” — esc clears`)}`);
157
+ } else if (!rows.length) {
154
158
  // herdr never shows a bare header over nothing: the empty state points at
155
159
  // the next move instead of a wall of blank rows.
156
160
  lines.push(
@@ -298,6 +302,8 @@ export function renderHerdPanel(
298
302
  ctxLeft?: number,
299
303
  device?: string,
300
304
  git?: { repo: boolean; branch?: string; head?: string; staged?: number; unstaged?: number; untracked?: number; ahead?: number; behind?: number; worktreeOf?: string },
305
+ /** The device's advertised default model id — a session on it is "(default)". */
306
+ defaultModel?: string,
301
307
  ): string[] {
302
308
  // No session selected: a blank panel next to the divider is what made the
303
309
  // wide layout look broken — herdr's panel always carries a device header.
@@ -317,10 +323,13 @@ export function renderHerdPanel(
317
323
  const agents = s.agents.map((a) =>
318
324
  a.kind === "fork" ? `⑂ ${a.name}` : a.kind === "subagent" ? `↳ ${a.name}` : `● ${a.name}`,
319
325
  );
326
+ // A session on exactly the device's default model says so, muted — the same
327
+ // signal the web dialog's "(device default)" row carries.
328
+ const onDefault = defaultModel !== undefined && s.model === defaultModel;
320
329
  const lines = [
321
330
  c.muted(" OVERVIEW"),
322
331
  ` ${c.bold(s.name)}`,
323
- ` ${c.muted(basename(s.cwd))} ${c.muted("·")} ${c.text(basename(s.model) || s.model)}`,
332
+ ` ${c.muted(basename(s.cwd))} ${c.muted("·")} ${c.text(basename(s.model) || s.model)}${onDefault ? c.muted(" (default)") : ""}`,
324
333
  git?.repo
325
334
  ? ` ${c.muted("⎇")} ${c.text(git.branch ?? git.head ?? "?")}${c.muted("±")}${c.text(String((git.staged ?? 0) + (git.unstaged ?? 0) + (git.untracked ?? 0)))}${git.ahead ? c.text(` ↑${git.ahead}`) : ""}${git.behind ? c.text(` ↓${git.behind}`) : ""}${git.worktreeOf ? c.muted(" · worktree") : ""}`
326
335
  : "",