kaizen-agent 1.59.1 → 1.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/cli/add-project.test.ts +169 -0
  2. package/cli/add-project.ts +132 -0
  3. package/cli/board.test.ts +15 -0
  4. package/cli/chat.ts +1 -1
  5. package/cli/dashboard.ts +6 -2
  6. package/cli/install.test.ts +1 -1
  7. package/cli/install.ts +18 -9
  8. package/cli/pty.test.ts +82 -3
  9. package/cli/pty.ts +122 -6
  10. package/cli/restart.test.ts +169 -0
  11. package/cli/settings.test.ts +35 -0
  12. package/cli/settings.ts +69 -18
  13. package/cli/state.test.ts +119 -3
  14. package/cli/state.ts +171 -13
  15. package/cli/usage.test.ts +130 -1
  16. package/cli/web-accept.test.ts +54 -0
  17. package/cli/web-symlink.test.ts +28 -0
  18. package/cli/web.ts +320 -100
  19. package/cli/worktree.test.ts +43 -1
  20. package/cli/worktree.ts +97 -2
  21. package/cli/writeback.ts +1 -1
  22. package/package.json +1 -1
  23. package/skills/kaizen/SKILL.md +5 -1
  24. package/skills/kaizen/config.default.yml +15 -2
  25. package/skills/kaizen/settings.md +1 -0
  26. package/skills/kaizen/spec-main.md +28 -2
  27. package/skills/kaizen-help/SKILL.md +1 -0
  28. package/web/board/add-project.ts +136 -0
  29. package/web/board/api.ts +1 -1
  30. package/web/board/badge.ts +5 -5
  31. package/web/board/cards.ts +11 -3
  32. package/web/board/context.ts +1 -0
  33. package/web/board/fixes.ts +3 -2
  34. package/web/board/git.ts +2 -0
  35. package/web/board/home.ts +7 -1
  36. package/web/board/ideas.ts +20 -3
  37. package/web/board/live.ts +1 -1
  38. package/web/board/main.ts +26 -9
  39. package/web/board/panel.ts +18 -3
  40. package/web/board/phone.ts +26 -3
  41. package/web/board/projects.ts +6 -85
  42. package/web/board/run-pick.ts +41 -0
  43. package/web/board/run-view.ts +261 -104
  44. package/web/board/settings.ts +42 -5
  45. package/web/board/store.ts +3 -1
  46. package/web/board/toast.ts +4 -1
  47. package/web/board/views.ts +6 -2
  48. package/web/board/workspace.ts +125 -38
  49. package/web/board/ws-board-ui.ts +84 -0
  50. package/web/board/ws-board.test.ts +71 -0
  51. package/web/board/ws-board.ts +45 -0
  52. package/web/board/ws-tabs.test.ts +171 -0
  53. package/web/board/ws-tabs.ts +170 -0
  54. package/web/board.html +92 -43
  55. package/web/board.js +44 -43
  56. package/web/notebook.js +24 -25
  57. package/web/notes.html +26 -21
  58. package/web/term.js +1 -1
  59. package/web/video.html +26 -21
  60. package/web/video.js +56 -57
@@ -6,6 +6,8 @@ import { store } from "./store.ts";
6
6
  import { $, html, ico, raw } from "./dom.ts";
7
7
  import { age, NAMES } from "./labels.ts";
8
8
  import { key, runPopup } from "./cards.ts";
9
+ import { load, post } from "./api.ts";
10
+ import { toast } from "./toast.ts";
9
11
  import { openWorkspace } from "./run-view.ts";
10
12
  import { open } from "./panel.ts";
11
13
  import { refreshBoardBadge } from "./badge.ts";
@@ -86,12 +88,13 @@ function draw() {
86
88
  html`${[["ideas", "Ideas first"], ["runs", "Running first"]].map(([v, l]) => html`<button type="button" role="menuitemradio" data-sort="${v}" aria-checked="${String(f.sort === v)}"><span>${l}</span>${ck}</button>`)}`,
87
89
  )
88
90
  : "";
89
- const extra = html`<span class="iseg">${seg("open", "Open")}${seg("running", "Running")}${seg("done", "Done")}</span>${sortPop}${sources}<button class="ib" id="ideas-ref" title="Refresh" aria-label="Refresh">${ico("refresh")}</button>`;
91
+ // Scope and filters first; search, refresh and New idea sit at the right (CSS order).
92
+ const extra = html`${sources}<span class="iseg">${seg("open", "Open")}${seg("running", "Running")}${seg("done", "Done")}</span>${sortPop}<button class="ib" id="ideas-ref" title="Refresh" aria-label="Refresh">${ico("refresh")}</button>`;
90
93
  const table = html`<table class="itable"><thead><tr><th></th><th>Title / context</th><th>Status</th><th>Updated</th><th></th></tr></thead><tbody>${rows.map((c, i) => {
91
94
  const name = nameOf(c.state, projects),
92
95
  st = stateOf(c),
93
96
  agent = (c.tags ?? []).find((t) => AGENTS.includes(t));
94
- return html`<tr><td>${logo(c.state, name, projects)}</td><td><b>${titleOf(c)}</b><div class="ctx">${name}${agent ? html`<span class="tag">${NAMES[agent]}</span>` : ""}</div></td><td><span class="stc"><span class="si ${st}"></span>${WORDS[st]}</span></td><td class="d">${c.moved || c.added ? age(c.moved || c.added, now) + " ago" : ""}</td><td><button class="go" data-i="${i}">${c.kind === "idea" ? "Start" : "Open"} ${ico("arrow")}</button></td></tr>`;
97
+ return html`<tr><td>${logo(c.state, name, projects)}</td><td><b>${titleOf(c)}</b><div class="ctx">${name}${agent ? html`<span class="tag">${NAMES[agent]}</span>` : ""}</div></td><td><span class="stc"><span class="si ${st}"></span>${WORDS[st]}</span></td><td class="d">${c.moved || c.added ? age(c.moved || c.added, now) + " ago" : ""}</td><td><div class="acts">${asking === key(c) ? html`<span class="q">Delete?</span><button class="btn ghost" data-keep="1">Keep</button><button class="btn danger" data-yes="${i}">Delete</button>` : html`${c.kind === "idea" ? html`<button class="del" data-i="${i}" title="Delete idea" aria-label="Delete idea">${ico("trash")}</button>` : ""}<button class="go" data-i="${i}">${c.kind === "idea" ? "Start" : "Open"} ${ico("arrow")}</button>`}</div></td></tr>`;
95
98
  })}</tbody></table>${rows.length ? "" : html`<p class="none">Nothing matches.</p>`}`;
96
99
  const hx = $("hx");
97
100
  // Not while a pop-up in it is open: redrawing would close it under the pointer.
@@ -113,7 +116,12 @@ function draw() {
113
116
  hx.querySelectorAll<HTMLElement>("[data-show]").forEach((b) => (b.onclick = () => ((f.show = b.dataset.show!), (hx.innerHTML = ""), draw())));
114
117
  $("ideas-ref").onclick = () => (void drawSources(true), void refreshBoardBadge());
115
118
  box.querySelectorAll<HTMLElement>("button.go").forEach((b) => (b.onclick = () => act(rows[+b.dataset.i!])));
116
- box.querySelectorAll<HTMLElement>("tbody tr").forEach((tr, i) => (tr.onclick = (e) => !(e.target as Element).closest("button") && detail(rows[i])));
119
+ // The trash icon asks in its own row, as the board's card menu does; a redraw keeps the question.
120
+ box.querySelectorAll<HTMLElement>("button.del").forEach((b) => (b.onclick = () => ((asking = key(rows[+b.dataset.i!])), draw())));
121
+ box.querySelectorAll<HTMLElement>("[data-keep]").forEach((b) => (b.onclick = () => ((asking = null), draw())));
122
+ box.querySelectorAll<HTMLElement>("[data-yes]").forEach((b) => (b.onclick = () => del(rows[+b.dataset.yes!])));
123
+ // A click moves the highlight to its row too: it marks the keyboard's row, not the panel's.
124
+ box.querySelectorAll<HTMLElement>("tbody tr").forEach((tr, i) => (tr.onclick = (e) => !(e.target as Element).closest("button") && ((sel = i), mark(), detail(rows[i]))));
117
125
  shownRows = rows;
118
126
  sel = Math.max(0, Math.min(sel, rows.length - 1));
119
127
  mark();
@@ -131,6 +139,15 @@ function act(c) {
131
139
  runPopup(here);
132
140
  }
133
141
 
142
+ // An idea is deleted as the board's card menu does it, not recorded anywhere.
143
+ let asking: string | null = null;
144
+ async function del(c) {
145
+ asking = null;
146
+ const r = await post("/inbox", { op: "delete", dir: c.state, text: c.text });
147
+ if (r.ok) toast("Deleted");
148
+ load();
149
+ }
150
+
134
151
  // A row's own click: the card's detail panel over this page. Another project's card goes
135
152
  // through the board's deep link, which opens the same panel there.
136
153
  function detail(c) {
package/web/board/live.ts CHANGED
@@ -33,7 +33,7 @@ function listen() {
33
33
  // Back to the project picked last time, unless the URL says which view it wants. A
34
34
  // plain fetch: a project that is gone should fall back to all, not raise a toast.
35
35
  // A page named in the address shows from the first paint; it is filled once the board has loaded.
36
- const v0 = ((v) => (v === "icebox" ? "sources" : v))(new URLSearchParams(location.search).get("view"));
36
+ const v0 = ((v) => (v === "icebox" ? "sources" : v === "ws" ? "run" : v))(new URLSearchParams(location.search).get("view"));
37
37
 
38
38
  export function initLive() {
39
39
  addEventListener("kz-view", () => { if (pendingReload && !document.body.classList.contains("homev")) location.reload(); });
package/web/board/main.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  // tick that reloads the board. See design.md for the visual rules.
7
7
  import { initPanel } from "./panel.ts";
8
8
  import { initViews } from "./views.ts";
9
- import { initProjects } from "./projects.ts";
9
+ import { initProjects, pick } from "./projects.ts";
10
10
  import { initUpdate } from "./update.ts";
11
11
  import { initKeys } from "./keys.ts";
12
12
  import { filterBox, statusSheet } from "./cards.ts";
@@ -14,10 +14,9 @@ import { initLive } from "./live.ts";
14
14
  import { store } from "./store.ts";
15
15
  import { initViewer } from "./viewer.ts";
16
16
  import { initContext } from "./context.ts";
17
- import { initFooter, initRail } from "./workspace.ts";
17
+ import { cardHref, initFooter, initRail, markCurrent, wsHref } from "./workspace.ts";
18
18
  import { go } from "./views.ts";
19
19
  import { openWorkspace } from "./run-view.ts";
20
- import { newIdea } from "./cards.ts";
21
20
 
22
21
  initPanel();
23
22
  initViews();
@@ -32,17 +31,35 @@ statusSheet();
32
31
  initRail();
33
32
  initFooter(() => go("terminal", true));
34
33
  // The rail's rows and + open a card or the new-idea form here, on the board, when it has them.
34
+ // A row of another project than the one picked switches the board to that project first.
35
35
  addEventListener("kz-open-card", (e: any) => {
36
36
  const { dir, id, text } = e.detail;
37
- const c = store.S.cards.find((x) => x.state === dir && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === text));
38
- if (!c) return;
37
+ const find = () =>
38
+ store.S.cards.find(
39
+ (x) => x.state === dir && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === text),
40
+ );
41
+ const c = find();
42
+ if (c) {
43
+ e.preventDefault();
44
+ return openWorkspace(c);
45
+ }
46
+ if (!dir || dir === store.dir) return;
39
47
  e.preventDefault();
40
- openWorkspace(c);
48
+ const href = cardHref({ state: dir, kind: id ? "run" : "idea", id, text });
49
+ pick(dir)
50
+ .then(() => {
51
+ const c = find();
52
+ if (c) openWorkspace(c);
53
+ else location.href = href;
54
+ })
55
+ .catch(() => (location.href = href));
41
56
  });
42
- addEventListener("kz-new-idea", (e) => {
43
- // A modal over whatever page is showing: the idea appears in the menu and Ideas by the usual refresh.
57
+ // A workspace row opens in place: the run view resolves it (showRunView).
58
+ addEventListener("kz-open-ws", (e: any) => {
44
59
  e.preventDefault();
45
- newIdea({ dir: e.detail?.dir ?? null });
60
+ history.pushState(null, "", wsHref(e.detail.dir, e.detail.ws));
61
+ markCurrent();
62
+ go("ws");
46
63
  });
47
64
 
48
65
  // One popup at a time: a press anywhere first shuts every open popup it is not inside,
@@ -87,7 +87,7 @@ export function open(c, keepTab) {
87
87
  if (!keepTab)
88
88
  store.lastTab = store.tab =
89
89
  c.status === "abandoned" ? "plan" : { 1: "plan", 2: "backlog", 3: "review", 4: "preview" }[c.column] || "request";
90
- openRun(c, false);
90
+ return openRun(c, false);
91
91
  }
92
92
  // A building run's Backlog tab opens with its progress, above the deferred items. The
93
93
  // first draw of a run animates nothing; later ones animate what moved, the bar included.
@@ -136,7 +136,8 @@ function meta(c) {
136
136
  }
137
137
  // An idea's panel: its terminal while the run it started is being born there, else its notes.
138
138
  export function ideaBody(c) {
139
- if (c.pty && view !== "run") showTerm(c); // in the run workspace the agent is a centre tab
139
+ // In the run workspace the agent is a centre tab; on the Ideas page an idea shows its notes only.
140
+ if (c.pty && view !== "run" && view !== "ideas") showTerm(c);
140
141
  else {
141
142
  termStop();
142
143
  chat(c, c.notes, c.archived || c.status !== "idea");
@@ -145,6 +146,8 @@ export function ideaBody(c) {
145
146
  export async function openRun(c, refresh, again) {
146
147
  if (!refresh || !store.runDoc || store.runDoc.id !== c.id || again) {
147
148
  const d = await fetch(`/run/${encodeURIComponent(c.id)}?dir=${encodeURIComponent(c.state)}`).then((r) => r.json());
149
+ // Another card opened while this was fetched: its doc would redraw that card as this run.
150
+ if (store.openKey !== key(c)) return;
148
151
  // A file list being confirmed, or a push under way, keeps the doc it was drawn from.
149
152
  if (refresh && $("pfoot").querySelector(".inl,[data-busy],.more[open]")) return;
150
153
  store.runDoc = d;
@@ -214,7 +217,7 @@ export async function openRun(c, refresh, again) {
214
217
  ? raw(md(doc, k === "backlog"))
215
218
  : html`<p style="color:var(--dim)">No ${{ request: "request", plan: "plan", impl: "work report", preview: "preview", review: "review", backlog: "backlog" }[k]} yet.</p>`;
216
219
  if (k === "backlog") showProgress(c);
217
- if (k === "review") fixForm(c);
220
+ if (k === "review" && !c.healed) fixForm(c);
218
221
  // The notebook's notes that link here, each opening that note: above the run's own notes.
219
222
  if (k === "notes" && store.runDoc.linkedFrom && store.runDoc.linkedFrom.length)
220
223
  $("pbody").insertAdjacentHTML(
@@ -241,6 +244,8 @@ export async function openRun(c, refresh, again) {
241
244
  // Its in-card agent ended on a waiting or done run: reopen that conversation, nothing sent.
242
245
  const rs = c.pty && !c.pty.alive ? `<button class="btn" data-a="resume">Resume session</button>` : "";
243
246
  if (c.archived) foot.innerHTML = raw(arch);
247
+ else if (c.healed && c.awaiting === "approvals.review")
248
+ foot.innerHTML = html`<span class="note">Finished by its agent without your approval. Nothing is committed until you approve.</span>${raw(arch + rs)}<button class="btn pri" data-a="accept">Approve</button>`;
244
249
  else if ((c.status === "waiting" || c.awaiting === "findings") && APPROVAL[c.awaiting]) {
245
250
  const sent = decided.has(answer(c)),
246
251
  asks = !pq
@@ -255,6 +260,8 @@ export async function openRun(c, refresh, again) {
255
260
  foot.innerHTML = html`<span class="note">${sent ? "Sent to your agent." : APPROVAL[c.awaiting] + asks}</span><details class="more"><summary class="btn ghost">More</summary><div class="menu-pop">${raw(more)}</div></details>${raw(rs)}<span class="dec"><button class="btn" data-a="revise"${sent ? " disabled" : ""}>Revise</button><button class="btn pri" data-a="approve"${sent ? " disabled" : ""}>${c.awaiting === "findings" ? "Approve as-is" : "Approve"}</button></span>`;
256
261
  } else if (c.status === "waiting")
257
262
  foot.innerHTML = html`<span class="note">Waiting on you: ${need(c.awaiting)}. Answer in the ${c.pty && c.pty.alive ? "terminal (button at the top)" : "terminal running this run"}.</span>${raw(arch)}<button class="btn ghost" data-a="ab">Abandon</button>${raw(rs)}`;
263
+ else if (c.status === "done" && c.accept === "needs")
264
+ foot.innerHTML = html`<span class="note">Done, not approved: its agent finished without your approval. Nothing is committed until you approve.</span>${raw(arch + rs)}<button class="btn pri" data-a="accept">Approve</button>`;
258
265
  else if (c.status === "done") foot.innerHTML = raw(arch + rs);
259
266
  else if (c.status === "abandoned") foot.innerHTML = raw(arch);
260
267
  else
@@ -275,6 +282,14 @@ export async function openRun(c, refresh, again) {
275
282
  confirmCommit(c);
276
283
  return;
277
284
  }
285
+ if (a === "accept") {
286
+ b.disabled = true;
287
+ post("/accept", { dir: c.state, id: c.id }).then((r) => {
288
+ if (r.ok) toast("Approved");
289
+ else b.disabled = false;
290
+ });
291
+ return;
292
+ }
278
293
  if (a === "approve") {
279
294
  if (qs.length) confirmAnswers(c, qs);
280
295
  else decide(c, b);
@@ -13,6 +13,9 @@ let mode: "home" | "device" | null = null;
13
13
 
14
14
  const chev = raw(`<svg class="pchev" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>`);
15
15
  const runs = () => railData().cards.filter((c) => c.kind === "run" && !c.archived);
16
+ // Ideas not started yet: a phone has no Ideas page, so the Runs page lists them.
17
+ const ideas = () => railData().cards.filter((c) => c.kind === "idea" && !c.archived);
18
+ const rowKey = (c) => (c.kind === "run" ? c.id : c.text);
16
19
  const projName = (dir: string) => {
17
20
  const l = railData().projects?.find((p) => p.dir === dir)?.label || dir.replace(/[\\/]\.kaizen$/, "");
18
21
  return l.split(/[\\/]/).pop() || l;
@@ -20,7 +23,7 @@ const projName = (dir: string) => {
20
23
 
21
24
  function row(c, now: number) {
22
25
  const name = projName(c.state);
23
- return html`<a class="prow" href="${cardHref(c)}" data-dir="${c.state}" data-id="${c.id}"><span class="si ${stateOf(c)}"></span><span class="pmain"><b>${titleOf(c)}</b><small>${logo(c.state, name, railData().projects)}${name}</small><code>${subline(c, now)}</code></span></a>`;
26
+ return html`<a class="prow" href="${cardHref(c)}" data-dir="${c.state}" data-id="${rowKey(c)}"><span class="si ${stateOf(c)}"></span><span class="pmain"><b>${titleOf(c)}</b><small>${logo(c.state, name, railData().projects)}${name}</small><code>${subline(c, now)}</code></span></a>`;
24
27
  }
25
28
 
26
29
  function home() {
@@ -47,7 +50,8 @@ function device() {
47
50
  const active = all.filter((c) => !wait.includes(c) && !done.includes(c));
48
51
  const group = (title: string, cs: any[], shut = false) =>
49
52
  cs.length ? html`<details class="pgrp"${raw(shut ? "" : " open")}><summary>${title}<span>${cs.length}</span></summary><div class="plist2">${cs.map((c) => row(c, now))}</div></details>` : "";
50
- return html`${group("Waiting on you", wait)}${group("Active", active)}${group("Done", done, true)}${all.length ? "" : html`<p class="pnote">No runs yet.</p>`}`;
53
+ const idle = ideas().sort((a, b) => (b.moved ?? b.added ?? 0) - (a.moved ?? a.added ?? 0));
54
+ return html`${group("Waiting on you", wait)}${group("Active", active)}${group("Ideas", idle)}${group("Done", done, true)}${all.length || idle.length ? "" : html`<p class="pnote">No runs yet.</p>`}`;
51
55
  }
52
56
 
53
57
  function draw() {
@@ -75,8 +79,27 @@ export function openPhone(m: "home" | "device" | null) {
75
79
  if (m === "home") void fetchNet();
76
80
  }
77
81
 
82
+ // A light tick on every tap of something pressable. Android has vibrate; iOS (18+) has none,
83
+ // but Safari ticks when a switch checkbox toggles, so a hidden one is toggled through its label.
84
+ let tick: HTMLLabelElement | null = null;
85
+ function haptic() {
86
+ if (navigator.vibrate) return void navigator.vibrate(8);
87
+ if (!tick) {
88
+ tick = document.createElement("label");
89
+ tick.hidden = true;
90
+ tick.innerHTML = `<input type="checkbox" switch>`;
91
+ document.body.append(tick);
92
+ }
93
+ tick.click();
94
+ }
95
+
78
96
  export function initPhone(go: (v: string, push?: boolean) => void, openRun: (c) => void) {
79
97
  addEventListener("kz-cards", draw);
98
+ addEventListener(
99
+ "click",
100
+ (e) => isPhone() && e.isTrusted && (e.target as HTMLElement).closest?.("button,a,summary,label,select,[role=button],input[type=checkbox]") && haptic(),
101
+ true,
102
+ );
80
103
  $("phome")?.addEventListener("click", (e) => {
81
104
  if ((e as MouseEvent).ctrlKey || (e as MouseEvent).metaKey) return;
82
105
  const a = (e.target as HTMLElement).closest<HTMLAnchorElement>("a");
@@ -84,7 +107,7 @@ export function initPhone(go: (v: string, push?: boolean) => void, openRun: (c)
84
107
  if (a.dataset.dev) return (e.preventDefault(), go("device", true));
85
108
  if (a.getAttribute("aria-disabled")) return e.preventDefault();
86
109
  if (a.classList.contains("prow")) {
87
- const c = runs().find((x) => x.state === a.dataset.dir && x.id === a.dataset.id);
110
+ const c = [...runs(), ...ideas()].find((x) => x.state === a.dataset.dir && rowKey(x) === a.dataset.id);
88
111
  if (c) (e.preventDefault(), openRun(c));
89
112
  }
90
113
  });
@@ -2,9 +2,10 @@ import { store } from "./store.ts";
2
2
  import { startDir } from "./labels.ts";
3
3
  import { load, post } from "./api.ts";
4
4
  import { newIdea, render } from "./cards.ts";
5
- import { $, html, ico, modal } from "./dom.ts";
5
+ import { $, html, ico } from "./dom.ts";
6
6
  import { openSources, srcOpen } from "./icebox.ts";
7
7
  import { toast } from "./toast.ts";
8
+ import { openAdd } from "./add-project.ts";
8
9
  import { view } from "./views.ts";
9
10
 
10
11
  // The picked project outlives a reload. Saved only where the user changes it, so a
@@ -55,90 +56,10 @@ export async function pick(v) {
55
56
  toast("Searching…");
56
57
  const j = await post("/find", {});
57
58
  if (j.ok) toast(j.added ? `Found ${j.added} new project${j.added === 1 ? "" : "s"}` : "No new projects found");
58
- } else if (v === "__new") {
59
- // A name, and where it goes: the projects folder unless typed or picked.
60
- const dl = modal(
61
- `<b>New project</b><input name="name" placeholder="Project name" aria-label="Project name" spellcheck="false" autocomplete="off"><div class="row"><input name="to" placeholder="Folder to create" aria-label="Create in" spellcheck="false" autocomplete="off"><button type="button" class="btn ghost" data-a="pick">Pick…</button></div><div class="row"><button type="button" class="btn ghost" data-a="x">Cancel</button><button class="btn pri">Create</button></div>`,
62
- );
63
- const f = dl.querySelector("form"),
64
- name = f.querySelector("[name=name]"),
65
- to = f.querySelector("[name=to]");
66
- let auto = ""; // the folder this form filled in; one the user typed is left alone
67
- name.oninput = async () => {
68
- const n = name.value.trim();
69
- if (!n || /[\\/:*?"<>|]/.test(n) || (to.value.trim() && to.value !== auto)) return; // a bad name is reported once, at Create
70
- const d = await post("/new-project", { name: n, check: true });
71
- if (d.ok && name.value.trim() === n) to.value = auto = d.to;
72
- };
73
- f.querySelector("[data-a=x]").onclick = () => dl.close();
74
- f.querySelector("[data-a=pick]").onclick = async () => {
75
- const p = await post("/pick-folder", {});
76
- if (p.path)
77
- to.value = p.path.replace(/[\\/]+$/, "") + (p.path.includes("\\") ? "\\" : "/") + (name.value.trim() || "");
78
- };
79
- name.focus();
80
- const dir = await new Promise((done) => {
81
- dl.addEventListener("close", () => done(null));
82
- f.onsubmit = async (e) => {
83
- e.preventDefault();
84
- if (!name.value.trim()) return name.focus();
85
- const j = await post("/new-project", { name: name.value.trim(), to: to.value.trim() || undefined });
86
- if (!j.ok) return;
87
- done(j.dir);
88
- dl.close();
89
- };
90
- });
91
- if (!dir) return;
92
- await post("/cd", { dir });
93
- store.all = false;
94
- store.dir = dir;
95
- keep(dir);
96
- toast("Project created");
97
- } else if (v === "__clone") {
98
- // One form: the link, then where it goes. The folder fills in once the link names a repo.
99
- const dl = modal(
100
- `<b>Clone from GitHub</b><input name="url" placeholder="https://github.com/owner/repo" aria-label="GitHub link (https or ssh)" spellcheck="false" autocomplete="off"><div class="row"><input name="to" placeholder="Folder to clone into" aria-label="Clone into" spellcheck="false" autocomplete="off"><button type="button" class="btn ghost" data-a="pick">Pick…</button></div><div class="row"><button type="button" class="btn ghost" data-a="x">Cancel</button><button class="btn pri">Clone</button></div>`,
101
- );
102
- const f = dl.querySelector("form"),
103
- url = f.querySelector("[name=url]"),
104
- to = f.querySelector("[name=to]");
105
- let name = "",
106
- auto = ""; // the folder this form filled in; one the user typed is left alone
107
- const check = async () => {
108
- const u = url.value.trim();
109
- if (!u) return null;
110
- const d = await post("/clone", { url: u, check: true });
111
- if (!d.ok) return null;
112
- name = d.name;
113
- if (!to.value.trim() || to.value === auto) to.value = auto = d.to;
114
- return d;
115
- };
116
- url.onchange = check;
117
- f.querySelector("[data-a=x]").onclick = () => dl.close();
118
- f.querySelector("[data-a=pick]").onclick = async () => {
119
- if (!(await check())) return url.focus();
120
- const p = await post("/pick-folder", {});
121
- if (p.path) to.value = p.path.replace(/[\\/]+$/, "") + (p.path.includes("\\") ? "\\" : "/") + name;
122
- };
123
- url.focus();
124
- const dir = await new Promise((done) => {
125
- dl.addEventListener("close", () => done(null));
126
- f.onsubmit = async (e) => {
127
- e.preventDefault();
128
- if (!(await check())) return url.focus();
129
- toast("Cloning…");
130
- const j = await post("/clone", { url: url.value.trim(), to: to.value.trim() || undefined });
131
- if (!j.ok) return;
132
- done(j.dir);
133
- dl.close();
134
- };
135
- });
136
- if (!dir) return;
137
- await post("/cd", { dir });
138
- store.all = false;
139
- store.dir = dir;
140
- keep(dir);
141
- toast("Cloned");
59
+ } else if (v === "__new" || v === "__clone") {
60
+ // The same sheet as the side menu's +; it adds the project and reloads onto it.
61
+ openAdd({ start: v === "__new" ? "create" : "clone" });
62
+ return;
142
63
  } else if (v === "all") {
143
64
  store.all = true;
144
65
  keep();
@@ -0,0 +1,41 @@
1
+ // The run picker at the top of the workspace's run panel (#ppick, popover #ppop): the runs not
2
+ // over (waiting on you first), then History. run-view.ts decides which run the panel shows.
3
+ import { $, html } from "./dom.ts";
4
+ import { key } from "./cards.ts";
5
+ import { age } from "./labels.ts";
6
+ import { awaiting, dueWord, gitDue } from "./ws-tabs.ts";
7
+ import { stateOf, titleOf } from "./workspace.ts";
8
+
9
+ let sig = "";
10
+ export const setOpen = (on: boolean) => {
11
+ $("ppop").hidden = !on;
12
+ $("ppick").setAttribute("aria-expanded", String(on));
13
+ };
14
+ export const drawPick = (live: any[], hist: any[], cur: any) => {
15
+ const now = Date.now(),
16
+ other = live.some((c) => c !== cur && awaiting(c)),
17
+ row = (c) => html`<button type="button" role="option" class="pk${c === cur ? " on" : ""}" aria-selected="${String(c === cur)}" data-pk="${key(c)}"><span class="si ${stateOf(c)}"></span><b>${titleOf(c)}</b><small>${gitDue(c) ? `waiting on you · ${dueWord(c)}` : awaiting(c) ? "needs you" : c.status} · ${age(c.moved ?? now, now)}</small></button>`;
18
+ const out = String(html`${live.map(row)}${hist.length ? html`<b class="mh">History</b>${hist.map(row)}` : ""}`);
19
+ const label = String(html`<span class="si ${stateOf(cur)}"></span><b>${titleOf(cur)}</b>${other ? html`<i class="pdot" title="Another run needs you"></i>` : ""}<svg class="fchev" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`);
20
+ if (sig === out + label) return;
21
+ sig = out + label;
22
+ $("ppop").innerHTML = out;
23
+ $("ppick").innerHTML = label;
24
+ };
25
+ export const hidePick = () => ((sig = ""), setOpen(false));
26
+ // Wires the trigger once: a click on a row calls pick(key); Esc and a press outside close it.
27
+ export function initPick(pick: (k: string) => void) {
28
+ $("ppick").onclick = () => setOpen($("ppop").hidden);
29
+ $("ppop").onclick = (e) => {
30
+ const k = (e.target as Element).closest<HTMLElement>("[data-pk]")?.dataset.pk;
31
+ if (!k) return;
32
+ setOpen(false);
33
+ pick(k);
34
+ };
35
+ addEventListener("keydown", (e) => {
36
+ if (e.key === "Escape" && !$("ppop").hidden) (setOpen(false), $("ppick").focus());
37
+ });
38
+ addEventListener("pointerdown", (e) => {
39
+ if (!$("ppop").hidden && !(e.target as Element).closest?.(".pwrap")) setOpen(false);
40
+ });
41
+ }