my-durable 0.0.54 → 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.
@@ -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>
@@ -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,
@@ -208,6 +209,26 @@ async function action(node: TreeNode, name: string) {
208
209
  submit: "Save name",
209
210
  run: (value) => client.session(s.id).rename(value),
210
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
+ };
211
232
  else if (name === "archive")
212
233
  ui.dialog = {
213
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>
@@ -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"
@@ -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;
@@ -1062,7 +1062,7 @@ export class App {
1062
1062
  if (!wide) return table;
1063
1063
  const selected = this.sessions.find((s) => s.id === (this.selectedId ?? this.sessionId));
1064
1064
  if (selected?.cwd) this.refreshGit(selected.cwd);
1065
- 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);
1066
1066
  return joinPanel(table, panel, tableW, w, h);
1067
1067
  }
1068
1068
 
@@ -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);
@@ -302,6 +302,8 @@ export function renderHerdPanel(
302
302
  ctxLeft?: number,
303
303
  device?: string,
304
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,
305
307
  ): string[] {
306
308
  // No session selected: a blank panel next to the divider is what made the
307
309
  // wide layout look broken — herdr's panel always carries a device header.
@@ -321,10 +323,13 @@ export function renderHerdPanel(
321
323
  const agents = s.agents.map((a) =>
322
324
  a.kind === "fork" ? `⑂ ${a.name}` : a.kind === "subagent" ? `↳ ${a.name}` : `● ${a.name}`,
323
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;
324
329
  const lines = [
325
330
  c.muted(" OVERVIEW"),
326
331
  ` ${c.bold(s.name)}`,
327
- ` ${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)") : ""}`,
328
333
  git?.repo
329
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") : ""}`
330
335
  : "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-durable",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "description": "Durable Pi — the durable agent network: hub web UI, device backend daemon, TUI admin and the shared SDK, packaged as one runnable monorepo install",
5
5
  "license": "MIT",
6
6
  "repository": {