@timqi/pier 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/config-sync.js +124 -92
- package/dist/config-sync-fetch.js +66 -79
- package/dist/db.js +5 -3
- package/dist/main.js +11 -4
- package/dist/service.js +17 -7
- package/dist/tasks/definitions.js +4 -0
- package/dist/tasks/tool.js +70 -13
- package/dist/web/instance.js +3 -3
- package/dist/web/public/assets/activity-Bv8fc5Wj.js +5 -0
- package/dist/web/public/assets/activity-Bv8fc5Wj.js.br +0 -0
- package/dist/web/public/assets/activity-Bv8fc5Wj.js.gz +0 -0
- package/dist/web/public/assets/boards-BRKjgEYX.js +1 -0
- package/dist/web/public/assets/boards-BRKjgEYX.js.br +0 -0
- package/dist/web/public/assets/boards-BRKjgEYX.js.gz +0 -0
- package/dist/web/public/assets/{code-p-Tq1bMK.js → code-BgAXjUH3.js} +1 -1
- package/dist/web/public/assets/{explorer-50no_DrD.js → explorer-Cq_Ertso.js} +3 -3
- package/dist/web/public/assets/explorer-Cq_Ertso.js.br +0 -0
- package/dist/web/public/assets/explorer-Cq_Ertso.js.gz +0 -0
- package/dist/web/public/assets/{ghostty-web-Bvhh3ZFk.js → ghostty-web-CZHJ0YFi.js} +1 -1
- package/dist/web/public/assets/ghostty-web-CZHJ0YFi.js.br +0 -0
- package/dist/web/public/assets/ghostty-web-CZHJ0YFi.js.gz +0 -0
- package/dist/web/public/assets/index-BH7ir5I4.css +2 -0
- package/dist/web/public/assets/index-BH7ir5I4.css.br +0 -0
- package/dist/web/public/assets/index-BH7ir5I4.css.gz +0 -0
- package/dist/web/public/assets/index-BrBNzaid.js +79 -0
- package/dist/web/public/assets/index-BrBNzaid.js.br +0 -0
- package/dist/web/public/assets/index-BrBNzaid.js.gz +0 -0
- package/dist/web/public/assets/runs-CvdNDaw8.js +1 -0
- package/dist/web/public/assets/runs-CvdNDaw8.js.br +0 -0
- package/dist/web/public/assets/runs-CvdNDaw8.js.gz +0 -0
- package/dist/web/public/assets/settings-BaVwkUUD.js +6 -0
- package/dist/web/public/assets/settings-BaVwkUUD.js.br +0 -0
- package/dist/web/public/assets/settings-BaVwkUUD.js.gz +0 -0
- package/dist/web/public/assets/task-runs-B-eoldcU.js +3 -0
- package/dist/web/public/assets/task-runs-B-eoldcU.js.br +0 -0
- package/dist/web/public/assets/task-runs-B-eoldcU.js.gz +0 -0
- package/dist/web/public/assets/tasks-CT4LECPQ.js +4 -0
- package/dist/web/public/assets/tasks-CT4LECPQ.js.br +0 -0
- package/dist/web/public/assets/tasks-CT4LECPQ.js.gz +0 -0
- package/dist/web/public/assets/terminal-C0qFDFou.js +2 -0
- package/dist/web/public/assets/terminal-C0qFDFou.js.br +0 -0
- package/dist/web/public/assets/terminal-C0qFDFou.js.gz +0 -0
- package/dist/web/public/index.html +16 -16
- package/dist/web/public/index.html.br +0 -0
- package/dist/web/public/index.html.gz +0 -0
- package/docs/deploy.md +20 -8
- package/package.json +1 -1
- package/skills/pier-tasks/SKILL.md +20 -11
- package/dist/web/public/assets/activity-DYo7QS7k.js +0 -5
- package/dist/web/public/assets/activity-DYo7QS7k.js.br +0 -0
- package/dist/web/public/assets/activity-DYo7QS7k.js.gz +0 -0
- package/dist/web/public/assets/boards-CwohTbtv.js +0 -1
- package/dist/web/public/assets/boards-CwohTbtv.js.br +0 -0
- package/dist/web/public/assets/boards-CwohTbtv.js.gz +0 -0
- package/dist/web/public/assets/explorer-50no_DrD.js.br +0 -0
- package/dist/web/public/assets/explorer-50no_DrD.js.gz +0 -0
- package/dist/web/public/assets/ghostty-web-Bvhh3ZFk.js.br +0 -0
- package/dist/web/public/assets/ghostty-web-Bvhh3ZFk.js.gz +0 -0
- package/dist/web/public/assets/index-DuZ2vERd.css +0 -2
- package/dist/web/public/assets/index-DuZ2vERd.css.br +0 -0
- package/dist/web/public/assets/index-DuZ2vERd.css.gz +0 -0
- package/dist/web/public/assets/index-WrsNstrb.js +0 -79
- package/dist/web/public/assets/index-WrsNstrb.js.br +0 -0
- package/dist/web/public/assets/index-WrsNstrb.js.gz +0 -0
- package/dist/web/public/assets/runs-BAXZF-6r.js +0 -1
- package/dist/web/public/assets/runs-BAXZF-6r.js.br +0 -0
- package/dist/web/public/assets/runs-BAXZF-6r.js.gz +0 -0
- package/dist/web/public/assets/settings-BmNXgRne.js +0 -6
- package/dist/web/public/assets/settings-BmNXgRne.js.br +0 -0
- package/dist/web/public/assets/settings-BmNXgRne.js.gz +0 -0
- package/dist/web/public/assets/task-runs-CpgHxFLf.js +0 -3
- package/dist/web/public/assets/task-runs-CpgHxFLf.js.br +0 -0
- package/dist/web/public/assets/task-runs-CpgHxFLf.js.gz +0 -0
- package/dist/web/public/assets/tasks-DybtogPF.js +0 -4
- package/dist/web/public/assets/tasks-DybtogPF.js.br +0 -0
- package/dist/web/public/assets/tasks-DybtogPF.js.gz +0 -0
- package/dist/web/public/assets/terminal-m2_WYu5W.js +0 -2
- package/dist/web/public/assets/terminal-m2_WYu5W.js.br +0 -0
- package/dist/web/public/assets/terminal-m2_WYu5W.js.gz +0 -0
package/dist/tasks/tool.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from "node:path";
|
|
1
2
|
import { Type } from "typebox";
|
|
2
3
|
import { TaskDefinitions, record, requiredString } from "./definitions.js";
|
|
3
4
|
import { TaskMessenger } from "./messages.js";
|
|
@@ -57,10 +58,14 @@ const summarizeGroup = (group, members, messages) => defined({
|
|
|
57
58
|
winnerRunId: group.winnerRunId,
|
|
58
59
|
members: members.map((run) => trimResult(summarize(run, messages.openDecisionId(run.id)))),
|
|
59
60
|
});
|
|
61
|
+
const LaunchSchema = Type.Object({
|
|
62
|
+
model: Type.Optional(Type.Object({ provider: Type.String(), id: Type.String() })),
|
|
63
|
+
thinking: Type.Optional(Type.String()),
|
|
64
|
+
});
|
|
60
65
|
// Model-facing draft shape. Guidance only: runtime truth stays in parseDraft,
|
|
61
66
|
// so schema drift can never loosen boundary validation.
|
|
62
67
|
const DraftSchema = Type.Object({
|
|
63
|
-
name: Type.String(),
|
|
68
|
+
name: Type.Optional(Type.String({ description: "Defaults to the prompt's first line." })),
|
|
64
69
|
description: Type.Optional(Type.String()),
|
|
65
70
|
trigger: Type.Optional(Type.Union([
|
|
66
71
|
Type.Object({ type: Type.Literal("manual") }),
|
|
@@ -77,14 +82,11 @@ const DraftSchema = Type.Object({
|
|
|
77
82
|
Type.Object({
|
|
78
83
|
type: Type.Literal("agent"),
|
|
79
84
|
session: Type.Union([
|
|
80
|
-
Type.Object({ mode: Type.Literal("fresh"), cwd: Type.String() }),
|
|
85
|
+
Type.Object({ mode: Type.Literal("fresh"), cwd: Type.Optional(Type.String({ description: "Absolute, or relative to your session's directory; omitted = your directory." })) }),
|
|
81
86
|
Type.Object({ mode: Type.Literal("reuse"), sessionId: Type.String() }),
|
|
82
87
|
]),
|
|
83
88
|
prompt: Type.String(),
|
|
84
|
-
launch: Type.Optional(
|
|
85
|
-
model: Type.Optional(Type.Object({ provider: Type.String(), id: Type.String() })),
|
|
86
|
-
thinking: Type.Optional(Type.String()),
|
|
87
|
-
})),
|
|
89
|
+
launch: Type.Optional(LaunchSchema),
|
|
88
90
|
}),
|
|
89
91
|
Type.Object({ type: Type.Literal("bash"), script: Type.String(), cwd: Type.String() }),
|
|
90
92
|
Type.Object({ type: Type.Literal("task"), taskId: Type.String() }),
|
|
@@ -101,7 +103,7 @@ export function taskToolSpec(execute) {
|
|
|
101
103
|
return {
|
|
102
104
|
name: "task",
|
|
103
105
|
label: "Pier Task",
|
|
104
|
-
description: "Manage durable Pier tasks and subagents. Agent tasks run in a fresh session or a reused one. Run executes a stored task by task_id, a one-shot subagent from
|
|
106
|
+
description: "Manage durable Pier tasks and subagents. Agent tasks run in a fresh session or a reused one. Run executes a stored task by task_id, a one-shot subagent from a prompt (shorthand: prompt + optional cwd/launch/name — cwd defaults to your own directory, relative paths resolve against it, name comes from the prompt) or from a full inline task draft, or a core-joined fan-out via tasks[] with join all|first. Get accepts run_id, group_id, or task_id for that task's recent runs. Every operation returns immediately: results, group joins, and decision replies arrive as callback messages. Use steer/follow_up/resume for child control and contact/reply for supervisor decisions. models lists the deployment's model menu (operator pins with intent notes, else the live catalog).",
|
|
105
107
|
parameters: Type.Object({
|
|
106
108
|
operation: strEnum("list", "create", "update", "run", "get", "cancel", "steer", "follow_up", "resume", "contact", "reply", "models"),
|
|
107
109
|
task_id: Type.Optional(Type.String()),
|
|
@@ -111,13 +113,19 @@ export function taskToolSpec(execute) {
|
|
|
111
113
|
message: Type.Optional(Type.String()),
|
|
112
114
|
reason: Type.Optional(strEnum("progress", "decision")),
|
|
113
115
|
session_mode: Type.Optional(strEnum("fresh")),
|
|
116
|
+
// The one-shot shorthand: a prompt is the whole delegation, and the
|
|
117
|
+
// fresh session in the caller's own directory is what it means.
|
|
118
|
+
prompt: Type.Optional(Type.String()),
|
|
119
|
+
cwd: Type.Optional(Type.String()),
|
|
120
|
+
launch: Type.Optional(LaunchSchema),
|
|
121
|
+
name: Type.Optional(Type.String()),
|
|
114
122
|
task: Type.Optional(DraftSchema),
|
|
115
123
|
// The same draft again, spelled out, cost more tokens in every session
|
|
116
124
|
// than the whole rest of this contract. One copy is the guidance; this
|
|
117
125
|
// one points at it, and `parseDraft` is what actually validates either.
|
|
118
126
|
tasks: Type.Optional(Type.Unsafe({
|
|
119
127
|
type: "array",
|
|
120
|
-
description: "2+ entries, each
|
|
128
|
+
description: "2+ entries, each a prompt string, {prompt, cwd?, launch?, name?}, a task draft shaped exactly like `task`, or {task_id}.",
|
|
121
129
|
items: { type: "object" },
|
|
122
130
|
})),
|
|
123
131
|
join: Type.Optional(strEnum("all", "first")),
|
|
@@ -140,12 +148,12 @@ export async function handleTaskTool(host, definitions, store, messages, raw, ca
|
|
|
140
148
|
if (input.operation === "create") {
|
|
141
149
|
if (active)
|
|
142
150
|
throw new Error("subagents cannot create task definitions");
|
|
143
|
-
return definitions.create(input.task, `session:${callerSessionId}`);
|
|
151
|
+
return definitions.create(await expandDraft(definitions, input.task, callerSessionId), `session:${callerSessionId}`);
|
|
144
152
|
}
|
|
145
153
|
if (input.operation === "update") {
|
|
146
154
|
if (active)
|
|
147
155
|
throw new Error("subagents cannot update task definitions");
|
|
148
|
-
return definitions.update(requiredString(input.task_id, "task_id"), input.task);
|
|
156
|
+
return definitions.update(requiredString(input.task_id, "task_id"), await expandDraft(definitions, input.task, callerSessionId));
|
|
149
157
|
}
|
|
150
158
|
if (input.operation === "run") {
|
|
151
159
|
if (Array.isArray(input.tasks)) {
|
|
@@ -158,7 +166,7 @@ export async function handleTaskTool(host, definitions, store, messages, raw, ca
|
|
|
158
166
|
throw new Error("tasks[] needs at least 2 entries; use task for a single run");
|
|
159
167
|
const resolved = [];
|
|
160
168
|
for (const rawEntry of input.tasks) {
|
|
161
|
-
const entry = record(rawEntry);
|
|
169
|
+
const entry = typeof rawEntry === "string" ? { prompt: rawEntry } : record(rawEntry);
|
|
162
170
|
if (!entry)
|
|
163
171
|
throw new Error("invalid tasks[] entry");
|
|
164
172
|
resolved.push(entry.task_id === undefined
|
|
@@ -168,7 +176,7 @@ export async function handleTaskTool(host, definitions, store, messages, raw, ca
|
|
|
168
176
|
const { group, runs } = host.runGroup(resolved, input.join === "first" ? "first" : "all", callerSessionId, active?.id ?? null, input.callback === "none" ? null : callerSessionId);
|
|
169
177
|
return summarizeGroup(group, runs, messages);
|
|
170
178
|
}
|
|
171
|
-
const draft = input.task_id === undefined ?
|
|
179
|
+
const draft = input.task_id === undefined ? inlineDraft(input) : undefined;
|
|
172
180
|
const task = draft
|
|
173
181
|
? await resolveDraft(definitions, draft, active, callerSessionId)
|
|
174
182
|
: resolveStored(definitions, input.task_id, active);
|
|
@@ -245,9 +253,58 @@ export async function handleTaskTool(host, definitions, store, messages, raw, ca
|
|
|
245
253
|
}
|
|
246
254
|
throw new Error("unknown task operation");
|
|
247
255
|
}
|
|
256
|
+
/** A single run's draft: the top-level shorthand (`prompt` …) or `task`, never both. */
|
|
257
|
+
function inlineDraft(input) {
|
|
258
|
+
const { prompt, cwd, launch, name } = input;
|
|
259
|
+
if (prompt === undefined)
|
|
260
|
+
return record(input.task) ?? undefined;
|
|
261
|
+
if (input.task !== undefined)
|
|
262
|
+
throw new Error("use either prompt or task");
|
|
263
|
+
return { prompt, cwd, launch, name };
|
|
264
|
+
}
|
|
265
|
+
/** The prompt's first line, unmarked and cut short: a label for the Console,
|
|
266
|
+
* not an identifier — the run's id is what anything addresses. */
|
|
267
|
+
function nameFromPrompt(prompt) {
|
|
268
|
+
const line = prompt.split("\n")
|
|
269
|
+
.map((l) => l.replace(/^[\s#>*-]+/, "").replace(/[*_`]/g, "").replace(/\s+/g, " ").trim())
|
|
270
|
+
.find(Boolean) ?? "subagent";
|
|
271
|
+
return line.length > 60 ? `${line.slice(0, 59).trimEnd()}…` : line;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The shape a draft is validated in, from the shapes a caller may write it in.
|
|
275
|
+
* A `prompt` shorthand becomes a fresh Agent action; a fresh session's cwd
|
|
276
|
+
* resolves against the caller's own directory (and is that directory when
|
|
277
|
+
* omitted); a missing name is the prompt's first line. Everything the caller
|
|
278
|
+
* did spell out passes through untouched — parseDraft still judges it.
|
|
279
|
+
*/
|
|
280
|
+
async function expandDraft(definitions, raw, callerSessionId) {
|
|
281
|
+
let draft = record(raw);
|
|
282
|
+
if (!draft)
|
|
283
|
+
return raw;
|
|
284
|
+
if (typeof draft.prompt === "string") {
|
|
285
|
+
if (draft.action !== undefined)
|
|
286
|
+
throw new Error("use either prompt (shorthand) or action");
|
|
287
|
+
const { prompt, cwd, launch, name, ...rest } = draft;
|
|
288
|
+
draft = { ...rest, name, action: { type: "agent", session: { mode: "fresh", cwd }, prompt, launch } };
|
|
289
|
+
}
|
|
290
|
+
const action = record(draft.action);
|
|
291
|
+
const session = record(action?.session);
|
|
292
|
+
if (action?.type === "agent" && session?.mode === "fresh" && (session.cwd === undefined || (typeof session.cwd === "string" && !isAbsolute(session.cwd)))) {
|
|
293
|
+
const base = await definitions.sessionCwd(callerSessionId);
|
|
294
|
+
if (!base)
|
|
295
|
+
throw new Error(`cwd ${session.cwd === undefined ? "omitted" : `"${session.cwd}" is relative`} and the calling session has no working directory; give an absolute path`);
|
|
296
|
+
draft = { ...draft, action: { ...action, session: { ...session, cwd: resolve(base, session.cwd ?? ".") } } };
|
|
297
|
+
}
|
|
298
|
+
if (draft.name === undefined && typeof action?.prompt === "string")
|
|
299
|
+
draft = { ...draft, name: nameFromPrompt(action.prompt) };
|
|
300
|
+
return draft;
|
|
301
|
+
}
|
|
248
302
|
/** Inline one-shot subagent: persisted like any task (kind "subagent",
|
|
249
303
|
* filtered from default lists) so runs stay auditable and resumable. */
|
|
250
|
-
async function resolveDraft(definitions,
|
|
304
|
+
async function resolveDraft(definitions, raw, active, callerSessionId) {
|
|
305
|
+
const draft = record(await expandDraft(definitions, raw, callerSessionId));
|
|
306
|
+
if (!draft)
|
|
307
|
+
throw new Error("task definition required");
|
|
251
308
|
if (draft.trigger !== undefined && record(draft.trigger)?.type !== "manual") {
|
|
252
309
|
throw new Error("inline subagent tasks must use a manual trigger");
|
|
253
310
|
}
|
package/dist/web/instance.js
CHANGED
|
@@ -78,9 +78,9 @@ export function registerInstanceRoutes(app, deps) {
|
|
|
78
78
|
problem: updater?.problem() ?? null,
|
|
79
79
|
}));
|
|
80
80
|
// Applying. Nothing is installed here: the work is handed to the service
|
|
81
|
-
// manager's own oneshot unit, which
|
|
82
|
-
//
|
|
83
|
-
// killed by the very restart it is performing.
|
|
81
|
+
// manager's own oneshot unit, which backs the database up and installs while
|
|
82
|
+
// Pier still runs, then stops it and starts the new version — an npm child of
|
|
83
|
+
// this process would be killed by the very restart it is performing.
|
|
84
84
|
app.post("/api/update", async (c) => {
|
|
85
85
|
if (!updater) {
|
|
86
86
|
return c.json({ error: "no service manager owns this Pier — update it with: pier update" }, 409);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{B as e,C as t,H as n,I as r,L as i,N as a,k as o,m as s,q as c,v as l,z as u}from"./index-BrBNzaid.js";var d=(e,t={})=>{let n=document.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);return n},f=e=>e===null?`-`:r(Date.now()-e),p={light:{edge:`#a3a3a3`,callback:`#0891b2`,message:`#d97706`,scheduler:{fill:`#f5f3ff`,stroke:`#a78bfa`,text:`#5b21b6`},console:{fill:`#eff6ff`,stroke:`#93c5fd`,text:`#1d4ed8`},task:{fill:`#fffbeb`,stroke:`#fbbf24`,text:`#92400e`},process:{fill:`#f5f5f5`,stroke:`#a3a3a3`,text:`#525252`,dash:`4 3`},streaming:{fill:`#ffffff`,stroke:`#10b981`,text:`#262626`},idle:{fill:`#fafafa`,stroke:`#d4d4d4`,text:`#737373`}},dark:{edge:`#7a7a7a`,callback:`#3fc3dd`,message:`#e0a13a`,scheduler:{fill:`#2b2440`,stroke:`#7d63c9`,text:`#c9b8f5`},console:{fill:`#1f2a3d`,stroke:`#4a7fbf`,text:`#a8c8f0`},task:{fill:`#3a2f1c`,stroke:`#b8862a`,text:`#f0d49a`},process:{fill:`#262626`,stroke:`#5c5c5c`,text:`#a3a3a3`,dash:`4 3`},streaming:{fill:`#22302a`,stroke:`#10b981`,text:`#e5e5e5`},idle:{fill:`#212121`,stroke:`#4a4a4a`,text:`#9a9a9a`}}},m=()=>p[document.documentElement.dataset.theme===`dark`?`dark`:`light`];function h(r,p,h){let g=`sessions`,_=`active`,v={sessions:[],runs:[],messages:[]},y=``,b=e(async()=>{let e=_,t=await n(`/api/activity?scope=${e}`,`Failed to load activity`);if(!t.ok){y=``,r.replaceChildren(i(`p`,`p-4 text-[13px] text-red-600`,t.error));return}if(e!==_)return;let a=JSON.stringify(t.value);if(`${e}:${a}`===y)return;y=`${e}:${a}`;let o=t.value;v={...o,sessions:o.sessions.map(e=>({...e,title:c(e.title)}))},x()});function x(){let e=o(t([[`Sessions`,`sessions`],[`Relationships`,`dependencies`]],g,e=>{g=e,x()}),i(`span`,`ml-auto text-[11.5px] text-neutral-400`,`${v.sessions.length} sessions · ${v.runs.length} runs`),t([[`Current`,`active`],[`Last 24h`,`recent`]],_,e=>{_=e,x(),b()})),n=i(`div`,`min-h-0 flex-1 overflow-auto`);g===`sessions`?S(n):w(n),r.replaceChildren(e,n)}function S(e){let t=document.createElement(`table`);t.className=`w-full table-fixed text-left text-[12.5px]`,t.innerHTML=`<thead class="sticky top-0 bg-neutral-50 text-[10.5px] uppercase tracking-wide text-neutral-400 shadow-[inset_0_-1px_0_var(--color-neutral-200)]"><tr>
|
|
2
|
+
<th class="w-[50%] px-4 py-2 font-semibold md:w-[34%]">Session</th>
|
|
3
|
+
<th class="hidden w-[38%] px-2 py-2 font-semibold md:table-cell">Project</th>
|
|
4
|
+
<th class="px-2 py-2 font-semibold md:w-[14%]">State</th>
|
|
5
|
+
<th class="px-2 py-2 font-semibold">In state</th></tr></thead>`;let n=document.createElement(`tbody`);for(let e of v.sessions){let t=document.createElement(`tr`);t.className=`cursor-pointer border-b border-neutral-100 transition-colors hover:bg-neutral-50`,t.onclick=()=>p(e.id);let r=i(`button`,`block w-full cursor-pointer truncate text-left font-medium text-neutral-800`,e.title??u(e.cwd));r.setAttribute(`type`,`button`),r.title=`${e.id}\n${e.cwd}`,r.onclick=t=>{t.stopPropagation(),p(e.id)},t.append(i(`td`,`px-4 py-2.5`,r,i(`div`,`truncate font-mono text-[11px] text-neutral-400 md:hidden`,e.cwd||`-`)),i(`td`,`hidden truncate px-2 py-2.5 font-mono text-[11.5px] text-neutral-500 md:table-cell`,e.cwd||`-`),i(`td`,`px-2 py-2.5`,C(e.state)),i(`td`,`px-2 py-2.5 font-mono text-[11.5px] text-neutral-400`,f(e.stateSince))),n.append(t)}t.append(n),e.append(t),v.sessions.length||e.append(i(`div`,`p-4`,l(_===`active`?`No active sessions.`:`No sessions in the last 24 hours.`)))}function C(e){return e===`streaming`?s(e,`bg-emerald-50 text-emerald-700 ring-emerald-200`,`animate-pulse bg-emerald-500`):s(e,`bg-neutral-100 text-neutral-600 ring-neutral-200`,`bg-neutral-300`)}function w(e){let t=new Map,n=[],r=(e,n,r,i)=>{t.has(e)||t.set(e,{id:e,label:n,kind:r,state:i})};for(let e of v.sessions)r(e.id,e.title??e.id.slice(0,10),`session`,e.state);for(let e of v.runs){let t=e.invokedBySessionId??`scheduler`,i=e.targetSessionId??(e.context.definition.action.type===`bash`?`process:${e.id}`:`task:${e.id}`);r(t,t===`scheduler`?`Scheduler`:t.slice(0,10),t===`scheduler`?`scheduler`:`session`),r(i,e.targetSessionId?e.targetSessionId.slice(0,10):e.context.definition.action.type===`bash`?`Bash process`:`Task`,e.targetSessionId?`session`:e.context.definition.action.type===`bash`?`process`:`task`),n.push({from:t,to:i,run:e,kind:`invocation`}),e.callbackSessionId&&(r(e.callbackSessionId,e.callbackSessionId.slice(0,10),`session`),n.push({from:i,to:e.callbackSessionId,run:e,kind:`callback`}))}for(let e of v.messages){if(!e.fromSessionId||!e.toSessionId||e.fromSessionId===e.toSessionId)continue;let t=v.runs.find(t=>t.id===e.runId);if(t){for(let t of[e.fromSessionId,e.toSessionId])r(t,t===`console`?`Console`:t.slice(0,10),t===`console`?`console`:`session`);n.push({from:e.fromSessionId,to:e.toSessionId,run:t,kind:`message`})}}if(!t.size){e.append(i(`div`,`p-4`,l(_===`active`?`No active dependencies.`:`No dependencies in the last 24 hours.`)));return}let a=[...t.values()],o=new Set(n.map(e=>e.to)),s=new Map,c=a.filter(e=>!o.has(e.id)).map(e=>e.id);c.length||c.push(a[0].id);for(let e of c)s.set(e,0);for(;c.length;){let e=c.shift();for(let t of n)t.from!==e||s.has(t.to)||(s.set(t.to,s.get(e)+1),c.push(t.to))}for(let e of a)s.has(e.id)||s.set(e.id,0);let u=new Map;for(let e of a){let t=s.get(e.id);u.set(t,[...u.get(t)??[],e])}let f=Math.max(...u.keys())+1,g=Math.max(...[...u.values()].map(e=>e.length)),y=n.some(e=>e.from!==e.to&&s.get(e.from)===s.get(e.to))?40:0,b=56+f*180+(f-1)*110+y,x=56+g*46+(g-1)*30,S=new Map;for(let[e,t]of u)t.forEach((t,n)=>S.set(t.id,{x:28+e*290+90,y:28+n*76+23}));let C=d(`svg`,{width:String(b),height:String(x),viewBox:`0 0 ${b} ${x}`,class:`block`}),w=d(`defs`),T=m();for(let[e,t]of[[`activity-arrow`,T.edge],[`activity-arrow-cb`,T.callback],[`activity-arrow-msg`,T.message]]){let n=d(`marker`,{id:e,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`});n.append(d(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,fill:t})),w.append(n)}C.append(w);let E=new Set;for(let e of n){let t=`${e.from}→${e.to}:${e.kind}`;if(E.has(t))continue;E.add(t);let n=S.get(e.from),r=S.get(e.to),i=d(`path`,{d:n.x===r.x?`M ${n.x+90} ${n.y} C ${n.x+90+46} ${n.y}, ${r.x+90+46} ${r.y}, ${r.x+90} ${r.y}`:(()=>{let e=r.x>n.x,t=n.x+(e?90:-90),i=r.x+(e?-90:90),a=Math.max(36,Math.abs(i-t)*.45)*(e?1:-1);return`M ${t} ${n.y} C ${t+a} ${n.y}, ${i-a} ${r.y}, ${i} ${r.y}`})(),fill:`none`,stroke:e.kind===`callback`?T.callback:e.kind===`message`?T.message:T.edge,"stroke-width":`1.5`,"marker-end":e.kind===`callback`?`url(#activity-arrow-cb)`:e.kind===`message`?`url(#activity-arrow-msg)`:`url(#activity-arrow)`});e.kind===`callback`&&i.setAttribute(`stroke-dasharray`,`6 5`),e.kind===`message`&&i.setAttribute(`stroke-dasharray`,`2 5`),i.classList.add(`cursor-pointer`),i.onclick=()=>h(e.run.id),C.append(i)}let D=/[\u1100-\u11FF\u2E80-\uA4CF\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6]/,O=(e,t)=>{let n=0;for(let r=0;r<e.length;r++)if(n+=D.test(e[r])?2:1,n>t)return`${e.slice(0,r)}…`;return e};for(let e of a){let t=S.get(e.id),n=e.kind===`session`?e.state===`streaming`?T.streaming:T.idle:T[e.kind],r=d(`g`,{transform:`translate(${t.x},${t.y})`});e.kind===`session`&&r.classList.add(`cursor-pointer`),r.onclick=()=>{e.kind===`session`&&p(e.id)};let i=d(`rect`,{x:`-90`,y:`-23`,width:`180`,height:`46`,rx:`8`,fill:n.fill,stroke:n.stroke,"stroke-width":e.kind===`session`&&e.state===`streaming`?`1.5`:`1`});n.dash&&i.setAttribute(`stroke-dasharray`,n.dash),r.append(i);let a=-78;if(e.kind===`session`){let t=d(`circle`,{cx:`-75`,cy:`0`,r:`3.5`,fill:n.stroke});if(e.state===`streaming`){let e=d(`animate`,{attributeName:`opacity`,values:`1;0.3;1`,dur:`1.6s`,repeatCount:`indefinite`});t.append(e)}r.append(t),a=-64}let o=d(`text`,{x:String(a),"text-anchor":`start`,"dominant-baseline":`middle`,"font-size":`11.5`,"font-weight":e.kind===`session`?`500`:`400`,fill:n.text});o.textContent=O(e.label,e.kind===`session`?22:25);let s=d(`title`);s.textContent=e.label===e.id?e.id:`${e.label}\n${e.id}`,r.append(o,s),C.append(r)}let k=e=>i(`span`,`inline-block h-2 w-2 rounded-full ${e}`),A=e=>i(`span`,`inline-block h-0 w-6 border-t-2 ${e}`);e.append(i(`div`,`w-max p-4`,C),i(`div`,`flex flex-wrap gap-x-5 gap-y-1.5 border-t border-neutral-200 bg-neutral-50/60 px-4 py-2 text-[11px] text-neutral-500`,i(`span`,`inline-flex items-center gap-2`,A(`border-solid border-neutral-400`),`task invocation`),i(`span`,`inline-flex items-center gap-2 text-cyan-700`,A(`border-dashed border-cyan-500`),`callback`),i(`span`,`inline-flex items-center gap-2 text-amber-700`,A(`border-dotted border-amber-500`),`supervisor / control`),i(`span`,`inline-flex items-center gap-1.5`,k(`bg-emerald-500`),`streaming`),i(`span`,`inline-flex items-center gap-1.5`,k(`bg-neutral-300`),`idle`)))}let T=a(r,e=>{e===`dependencies`?g=`dependencies`:e===`sessions`&&(g=`sessions`),b()},()=>{r.replaceChildren(),v={sessions:[],runs:[],messages:[]},y=``});return window.addEventListener(`pier:theme`,()=>{T.visible&&x()}),Object.assign(T,{refresh(){T.visible&&b()}})}export{h as createActivityView};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{G as e,H as t,K as n,L as r,N as i,O as a,P as o,R as s,V as c,h as l}from"./index-BrBNzaid.js";var u=e=>e.public&&e.token?`/p/${e.slug}-${e.token}/`:`/boards/${e.slug}/`;function d(d,f){let p=[],m=``,h=r(`header`,`sticky top-0 z-30 flex h-10 items-center gap-3 border-b border-neutral-200 bg-white px-4`,r(`span`,`font-medium max-md:hidden`,`Boards`)),g=r(`div`,`px-4 py-5`);d.append(r(`div`,`min-h-0 flex-1 overflow-y-auto`,h,g));async function _(e,t){let r=await n(`/api/boards/${e.slug}`,{public:t},`PATCH`);if(r.ok)return e.token=(await r.json().catch(()=>({}))).token??``,x();m=await c(r,`Could not change ${e.slug}`),await S()}async function v(t){m=await e(`/api/boards/${t}`,`DELETE`,`Could not delete ${t}`)??``,await S()}function y(e){let t=r(`div`,`group flex flex-col gap-1 border-b border-neutral-200/70 px-1 py-2.5 last:border-b-0`),n=document.createElement(`a`);n.className=`truncate font-medium text-neutral-800 hover:text-indigo-700`,n.href=u(e),n.target=`_blank`,n.rel=`noreferrer`,n.textContent=e.title;let i=r(`div`,`flex items-center gap-2`,n,r(`span`,`flex-none font-mono text-[11.5px] text-neutral-400`,e.slug)),c=a(``,``,e.public,t=>{e.public=t,_(e,t)});c.className=`ml-auto flex flex-none cursor-pointer items-center gap-1.5 text-[11.5px] text-neutral-500`,c.append(r(`span`,``,`Public`));let d=l(`Delete`,`flex-none cursor-pointer text-[11.5px] text-neutral-400 opacity-0 transition-opacity hover:text-red-600 group-hover:opacity-100`);d.title=`Renames the folder on disk; nothing is erased`,d.onclick=()=>void v(e.slug);let p=o(`flex-none cursor-pointer text-[11.5px] text-neutral-400 opacity-0 transition-opacity hover:text-indigo-600 group-hover:opacity-100`,()=>`${location.origin}${u(e)}`);p.title=`Copy the board's link`,i.append(c,p,d),t.append(i);let m=r(`div`,`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11.5px] text-neutral-500`);e.description&&m.append(r(`span`,`min-w-0 truncate`,e.description)),m.append(r(`span`,`flex-none text-neutral-400`,s(Date.parse(e.updatedAt))));for(let t of e.sessions){let e=l(t.slice(0,8),`flex-none cursor-pointer font-mono text-indigo-600 hover:underline`);e.title=`Open session ${t}`,e.onclick=()=>f(t),m.append(e)}if(e.public&&e.token){let t=r(`span`,`flex-none font-mono text-neutral-400`,u(e));t.title=`Public URL — anyone holding this link can read the board, no password`,m.append(t)}return t.append(m),t}let b=[{title:`Public`,hint:`Readable at /p/<slug>-<token>/ by anyone holding the link.`,wanted:!0},{title:`Private`,hint:`Reachable from the Console only.`,wanted:!1}];function x(){let e=r(`div`,`mx-auto flex max-w-3xl flex-col`);p.length===0&&e.append(r(`p`,`rounded-xl border border-dashed border-neutral-300 px-4 py-6 text-center text-[12.5px] text-neutral-500`,`No boards yet. Ask an agent to build one — it writes a folder under ~/.pier/boards.`));for(let{title:t,hint:n,wanted:i}of b){let a=p.filter(e=>e.public===i);if(a.length===0)continue;let o=r(`section`,`mb-6`);o.append(r(`h2`,`text-[13px] font-semibold text-neutral-700`,t)),o.append(r(`p`,`mb-1 text-[11.5px] leading-snug text-neutral-500`,n));let s=r(`div`,`rounded-xl border border-neutral-200 bg-white px-3`);s.append(...a.map(y)),o.append(s),e.append(o)}g.replaceChildren(...m?[r(`p`,`mb-3 text-[13px] text-red-600`,m)]:[],e)}async function S(){let e=await t(`/api/boards`,`Could not load boards`);if(!e.ok)return m=e.error,x();p=e.value,x(),m=``}let C=i(d,()=>void S());return window.addEventListener(`focus`,()=>{C.visible&&S()}),C}export{d as createBoardsView};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{L as e,u as t}from"./index-BrBNzaid.js";var n=2e4,r=e=>e.map((e,t)=>({nums:[t+1],text:e,tone:``}));function i(t,r){let i=t.length<=n?r:null,o=Math.max(2,...t.map(e=>e.nums.reduce((e,t)=>Math.max(e,String(t).length),0))),s=e(`div`,`py-2 font-mono text-[12px] leading-[1.5]`);for(let n of t){let t=e(`div`,`flex pl-2 pr-4 ${n.tone===`add`?`bg-emerald-50`:n.tone===`del`?`bg-red-50`:``}`);for(let r of n.nums){let n=e(`span`,`flex-none select-none pr-1.5 text-right text-neutral-300`,r===``?``:String(r));n.style.width=`calc(${o}ch + 0.375rem)`,t.append(n)}t.append(a(n,i)),s.append(t)}return s}function a(n,r){let i=`min-w-0 flex-1 whitespace-pre-wrap [overflow-wrap:anywhere]`;if(!n.mark||n.mark[0]>=n.mark[1]){let e=t(n.text,r);return e.className=i,e}let[a,o]=n.mark,s=t(n.text.slice(a,o),r);return s.className=`rounded-xs ${n.tone===`add`?`bg-emerald-200/80`:`bg-red-200/70`}`,e(`span`,i,t(n.text.slice(0,a),r),s,t(n.text.slice(o),r))}export{r as n,i as t};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{F as e,L as t,M as n,N as r,R as i,U as a,a as o,i as s,l as c,n as l,s as u}from"./index-BrBNzaid.js";import{n as d,t as f}from"./code-BgAXjUH3.js";var p=e=>{let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`},m=e=>[e.subject,e.body,[[e.author,e.email?`<${e.email}>`:``].filter(Boolean).join(` `),e.at?p(e.at):``].filter(Boolean).join(` · `)].filter(Boolean).join(`
|
|
2
2
|
|
|
3
|
-
`),h=null;function g(){h&&(h.remove(),h=null,document.removeEventListener(`pointerdown`,g,!0),window.removeEventListener(`scroll`,g,!0))}function _(e,n){e.onmouseenter=()=>{g();let r=n();if(!r)return;h=t(`div`,`pointer-events-none fixed z-50 max-w-96 whitespace-pre-wrap rounded-lg bg-neutral-800/95 px-3 py-2 font-sans text-[11.5px] leading-snug text-neutral-100 shadow-lg`),h.textContent=r,document.body.append(h),document.addEventListener(`pointerdown`,g,!0),window.addEventListener(`scroll`,g,!0);let i=e.getBoundingClientRect();h.style.left=`${Math.max(8,Math.min(i.left,window.innerWidth-h.offsetWidth-8))}px`,h.style.top=i.bottom+6+h.offsetHeight>window.innerHeight?`${i.top-h.offsetHeight-6}px`:`${i.bottom+6}px`},e.onmouseleave=g}function v(e,r
|
|
3
|
+
`),h=null;function g(){h&&(h.remove(),h=null,document.removeEventListener(`pointerdown`,g,!0),window.removeEventListener(`scroll`,g,!0))}function _(e,n){e.onmouseenter=()=>{g();let r=n();if(!r)return;h=t(`div`,`pointer-events-none fixed z-50 max-w-96 whitespace-pre-wrap rounded-lg bg-neutral-800/95 px-3 py-2 font-sans text-[11.5px] leading-snug text-neutral-100 shadow-lg`),h.textContent=r,document.body.append(h),document.addEventListener(`pointerdown`,g,!0),window.addEventListener(`scroll`,g,!0);let i=e.getBoundingClientRect();h.style.left=`${Math.max(8,Math.min(i.left,window.innerWidth-h.offsetWidth-8))}px`,h.style.top=i.bottom+6+h.offsetHeight>window.innerHeight?`${i.top-h.offsetHeight-6}px`:`${i.bottom+6}px`},e.onmouseleave=g}function v(e,n,r){let a=t(`button`,`flex w-full cursor-pointer items-center gap-1.5 px-2 py-1 text-left hover:bg-neutral-100`,t(`span`,`w-3 flex-none text-indigo-600`,e.value===n?`✓`:``),t(`span`,`flex-none font-mono text-[11.5px] text-neutral-800`,e.label??e.value));return e.subject&&a.append(t(`span`,`min-w-0 truncate text-[11px] text-neutral-400`,e.subject)),e.author&&a.append(t(`span`,`ml-auto flex-none pl-1.5 text-[10.5px] text-neutral-400`,`${e.author} · ${e.at?i(e.at):``}`)),_(a,()=>m(e)),a.onclick=()=>r(e.value),a}function ee(e,n,r,i,a){let{base:c,head:l}=r,u=()=>l&&c===`${l}~1`?l:``,d=u()?`commit`:`compare`,f=n.commits[0],p=e=>[...e?[{value:``,label:`Working tree`,subject:`the files on disk, uncommitted changes included`}]:[],{...f,value:`HEAD`},...n.refs.map(e=>({value:e.name,subject:e.subject})),...n.commits.map(e=>({...e,value:e.hash}))],m=t(`div`,`flex w-[38rem] max-w-full flex-col`);function h(){let e=(e,n)=>{let r=t(`button`,`cursor-pointer rounded-full px-2.5 py-0.5 text-[11.5px] ${d===n?`bg-indigo-50 font-medium text-indigo-700`:`text-neutral-500 hover:bg-neutral-100`}`,e);return r.onclick=()=>{d=n,h()},r},r=(e,n,r,i)=>t(`div`,`flex min-w-0 flex-1 flex-col`,t(`div`,`flex-none px-2 pb-0.5 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),t(`div`,`min-h-0 flex-1 overflow-y-auto`,...n.map(e=>v(e,r,i)))),o=d===`compare`?t(`div`,`flex h-72 min-h-0 divide-x divide-neutral-200 pb-1`,r(`base`,p(!1),c,e=>{c=e,h(),i(c,l)}),r(`to`,p(!0),l,e=>{l=e,h(),i(c,l)})):t(`div`,`flex h-72 min-h-0 flex-col overflow-y-auto pb-1`,...n.commits.map(e=>v({value:e.hash,...e},u(),e=>{c=`${e}~1`,l=e,s(),i(c,l)}))),f=t(`div`,`flex-none border-t border-neutral-200`,v({value:a,label:`↺ ${a} ↔ Working tree`,subject:`back to the default: the main line's tip vs the files on disk`},c===a&&l===``?a:``,()=>{c=a,l=``,h(),i(c,l)}));m.replaceChildren(t(`div`,`flex flex-none items-center gap-1 border-b border-neutral-200 px-2 py-1.5`,e(`Compare two points`,`compare`),e(`One commit`,`commit`)),o,...d===`compare`?[f]:[])}h(),o(e,m)}var te=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,y={A:`text-emerald-600`,M:`text-amber-600`,D:`text-red-600`},ne=30,b=`pier.filesPrefs`,x=50,S=()=>{try{let e=JSON.parse(localStorage.getItem(b)??`{}`);return e&&typeof e==`object`?e:{}}catch{return{}}},re=e=>{let t=e?S()[e]:void 0;return typeof t?.cwd==`string`&&typeof t.base==`string`&&typeof t.head==`string`?{cwd:t.cwd,base:t.base,head:t.head}:null},ie=(e,t)=>{let n=S();delete n[e],n[e]=t;let r=Object.keys(n);for(let e of r.slice(0,Math.max(0,r.length-x)))delete n[e];try{localStorage.setItem(b,JSON.stringify(n))}catch(e){console.warn(`Files: could not remember this folder`,e)}},C=(e,n=`indigo`)=>{let r=t(`button`,`min-w-0 cursor-pointer truncate rounded-md px-2 py-0.5 text-left font-mono text-[11.5px] ${n===`indigo`?`bg-indigo-50 font-medium text-indigo-700 hover:bg-indigo-100`:`bg-neutral-100 text-neutral-600 hover:bg-neutral-200`}`,e);return r.type=`button`,r};function w(i,o,s,p,h){let g=``,v=``,b={branch:null,refs:[],commits:[],worktrees:[]},x=`HEAD`,S=``,w=new Map,T=!0,E=!1,D=[],O=new Set,k=null,A=null,ae=t(`header`,`flex h-10 flex-none items-center gap-2 border-b border-neutral-200 bg-white px-3`),j=t(`div`,`flex-none border-b border-neutral-200`),M=t(`div`,`min-h-0 flex-1 overflow-y-auto py-1`),oe=t(`aside`,`flex w-64 flex-none flex-col border-r border-neutral-200 text-[12.5px] max-md:h-2/5 max-md:w-full max-md:border-b max-md:border-r-0`,j,M),N=t(`div`,`h-full min-w-0 overflow-auto`),P=t(`div`,`pointer-events-none absolute inset-y-0 right-0 z-20 hidden w-2`),se=t(`section`,`relative min-h-0 min-w-0 flex-1`,N,P);i.append(ae,t(`div`,`flex min-h-0 flex-1 max-md:flex-col`,oe,se));let F=(e,t)=>`/api/explorer/${e}?${new URLSearchParams({root:g,...t})}`,I=(e,t)=>`/api/fs/${e}?${new URLSearchParams({root:g,...t})}`,L=(e,n=`text-neutral-400`)=>t(`p`,`px-4 py-3 text-[12.5px] ${n}`,e),R=e=>{let t=0;for(let n of w.keys())n.startsWith(`${e}/`)&&t++;return t};function z(e,t){let n=new Set(t.map(e=>e.name)),r=e?`${e}/`:``;for(let[e,i]of w){if(i.status!==`D`||!e.startsWith(r))continue;let a=e.slice(r.length).split(`/`)[0];n.has(a)||(n.add(a),t.push({name:a,dir:e.slice(r.length).includes(`/`)}))}let i=t;return T&&b.branch&&(i=t.filter(e=>e.dir?R(`${r}${e.name}`)>0:w.has(`${r}${e.name}`))),i.sort((e,t)=>Number(t.dir)-Number(e.dir)||e.name.localeCompare(t.name)),i.map(e=>e.dir?ce(`${r}${e.name}`,e.name):le(`${r}${e.name}`,e.name))}async function B(e,t){try{let{entries:n}=await a(I(`ls`,{path:t}),`could not list this folder`);e.replaceChildren(...z(t,n)),e.childElementCount||e.append(L(T?`No changes.`:`Empty.`))}catch(n){let r=z(t,[]);r.length?e.replaceChildren(...r):e.replaceChildren(L(String(n),`text-red-600`))}}function ce(n,r){let i=R(n),a=[t(`span`,`truncate`,r)];i&&a.push(t(`span`,`ml-auto flex-none rounded bg-amber-100/80 px-1 font-mono text-[10px] text-amber-700`,String(i)));let{el:o,summary:s}=e(``,a);s.className+=` px-2 py-0.5 hover:bg-neutral-100`;let c=t(`div`,`pl-3`);o.append(c);let l=!1,u=()=>{l||(l=!0,c.append(L(`…`)),B(c,n))};return o.ontoggle=()=>{O[o.open?`add`:`delete`](n),o.open&&u()},(T&&b.branch&&!E||O.has(n))&&(o.open=!0,u()),o}function V(e){A?.classList.remove(`bg-indigo-50`,`text-indigo-700`),A=e,e.classList.add(`bg-indigo-50`,`text-indigo-700`)}function le(e,n){let r=w.get(e)?.status,i=t(`button`,`flex w-full cursor-pointer items-center gap-1.5 px-2 py-0.5 pl-6 text-left hover:bg-neutral-100`,t(`span`,`truncate`,n));return r&&i.append(t(`span`,`ml-auto flex-none font-mono text-[10.5px] font-semibold ${y[r]??`text-neutral-500`}`,r)),i.title=e,e===k&&V(i),i.onclick=()=>{V(i),k=e,Y(e)},i}let H=()=>void B(M,``),U=(e,n)=>[...e?[t(`span`,`flex-none font-mono text-[10.5px] font-semibold text-emerald-600`,`+${e}`)]:[],...n?[t(`span`,`flex-none font-mono text-[10.5px] font-semibold text-red-600`,`−${n}`)]:[]];function W(e,r,i){let a=w.get(e),o=t(`div`,`sticky top-0 z-10 flex items-center gap-2 border-b border-neutral-200 bg-white px-4 py-1.5 font-mono text-[11.5px] text-neutral-500`,t(`span`,`truncate`,e));a&&(o.append(t(`span`,`flex-none font-semibold ${y[a.status]??``}`,a.status)),o.append(...U(a.add,a.del)));let s=t(`div`,`ml-auto flex flex-none items-center gap-2`);if(i&&s.append(i),r){let t=document.createElement(`a`);t.className=`flex-none text-neutral-400 hover:text-indigo-700 hover:underline`,t.href=I(`file`,{path:e}),t.download=n(e),t.textContent=`Download`,s.append(t)}return o.append(s),o}function ue(e){let t=0;for(;t<e.length;){if(e[t].tone!==`del`){t++;continue}let n=t;for(;t<e.length&&e[t].tone===`del`;)t++;let r=t;for(;t<e.length&&e[t].tone===`add`;)t++;let i=Math.min(r-n,t-r);for(let t=0;t<i;t++){let i=e[n+t],a=e[r+t],o=Math.min(i.text.length,a.text.length),s=0;for(;s<o&&i.text[s]===a.text[s];)s++;let c=0;for(;c<o-s&&i.text[i.text.length-1-c]===a.text[a.text.length-1-c];)c++;s+c!==0&&(i.mark=[s,i.text.length-c],a.mark=[s,a.text.length-c])}}}let G=_e();function K(){P.classList.add(`hidden`),P.replaceChildren(),G.set([],[])}let q=0,J=e=>e===q;function Y(e){let t=++q;return w.has(e)?ve(e,t):de(e,t)}async function de(e,n){if(!J(n))return;K();let r=I(`file`,{path:e}),i=t(`div`,`min-w-0`);if(N.classList.remove(`flex`,`flex-col`),N.replaceChildren(W(e,!0),i),te.test(e)){let e=t(`img`,`max-w-full p-4`);e.src=r,e.onerror=()=>i.replaceChildren(L(`Could not load image.`,`text-red-600`)),i.append(e);return}if(e.toLowerCase().endsWith(`.pdf`)){let t=document.createElement(`iframe`);t.className=`h-full w-full`,t.src=r,N.replaceChildren(W(e,!0),t),N.classList.add(`flex`,`flex-col`);return}i.append(L(`…`));let a=await fetch(r);if(!J(n))return;if(!a.ok){let{error:e}=await a.json().catch(()=>({}));i.replaceChildren(L(e??`HTTP ${a.status}`,`text-red-600`));return}if(!(a.headers.get(`content-type`)??``).startsWith(`text/plain`)){i.replaceChildren(L(`Binary file — use Download.`));return}let o=(await a.text()).split(`
|
|
4
4
|
`);if(!J(n))return;o.at(-1)===``&&o.pop();let s=await c(e);J(n)&&i.replaceChildren(f(d(o),s))}function fe(e){let t=[],n=0,r=0,i=!1,a=e.split(`
|
|
5
|
-
`);a.at(-1)===``&&a.pop();for(let e of a){let a=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e);if(a){i&&t.push({nums:[``,``],text:`⋯`,tone:``}),[n,r]=[Number(a[1]),Number(a[2])],i=!0;continue}!i||e.startsWith(`\\`)||(e.startsWith(`+`)?t.push({nums:[``,r++],text:e.slice(1),tone:`add`}):e.startsWith(`-`)?t.push({nums:[n++,``],text:e.slice(1),tone:`del`}):t.push({nums:[n++,r++],text:e.slice(1),tone:``}))}return t}function pe(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n].tone;if(!r)continue;let i=t.at(-1);i&&i.end===n-1?(i.end=n,(r===`add`&&i.tone===`del`||r===`del`&&i.tone===`add`)&&(i.tone=`mixed`)):t.push({start:n,end:n,tone:r})}return t}let me={add:`bg-emerald-400`,del:`bg-red-400`,mixed:`bg-amber-400`};function he(e,n,r){P.replaceChildren(...e.map(e=>{let i=t(`button`,`pointer-events-auto absolute w-full cursor-pointer ${me[e.tone]}`);return i.style.top=`${e.start/n*100}%`,i.style.height=`${Math.max(.4,(e.end-e.start+1)/n*100)}%`,i.title=`line ${ge(r,e.start)}`,i.onclick=()=>r[e.start].scrollIntoView({block:`center`}),i})),P.classList.remove(`hidden`)}let ge=(e,t)=>e[t]?.querySelector(`span`)?.textContent?.trim()||String(t+1);function _e(){let e=[],
|
|
5
|
+
`);a.at(-1)===``&&a.pop();for(let e of a){let a=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e);if(a){i&&t.push({nums:[``,``],text:`⋯`,tone:``}),[n,r]=[Number(a[1]),Number(a[2])],i=!0;continue}!i||e.startsWith(`\\`)||(e.startsWith(`+`)?t.push({nums:[``,r++],text:e.slice(1),tone:`add`}):e.startsWith(`-`)?t.push({nums:[n++,``],text:e.slice(1),tone:`del`}):t.push({nums:[n++,r++],text:e.slice(1),tone:``}))}return t}function pe(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n].tone;if(!r)continue;let i=t.at(-1);i&&i.end===n-1?(i.end=n,(r===`add`&&i.tone===`del`||r===`del`&&i.tone===`add`)&&(i.tone=`mixed`)):t.push({start:n,end:n,tone:r})}return t}let me={add:`bg-emerald-400`,del:`bg-red-400`,mixed:`bg-amber-400`};function he(e,n,r){P.replaceChildren(...e.map(e=>{let i=t(`button`,`pointer-events-auto absolute w-full cursor-pointer ${me[e.tone]}`);return i.style.top=`${e.start/n*100}%`,i.style.height=`${Math.max(.4,(e.end-e.start+1)/n*100)}%`,i.title=`line ${ge(r,e.start)}`,i.onclick=()=>r[e.start].scrollIntoView({block:`center`}),i})),P.classList.remove(`hidden`)}let ge=(e,t)=>e[t]?.querySelector(`span`)?.textContent?.trim()||String(t+1);function _e(){let e=[],n=[],r=-1,a=t(`span`,`flex-none text-[10.5px] text-neutral-400`),o=t=>{e.length&&(r=(r+t+e.length)%e.length,n[e[r].start].scrollIntoView({block:`center`}),a.textContent=`${r+1}/${e.length}`)},s=()=>e.length>0&&!i.classList.contains(`hidden`),c=(e,n,r,i)=>{let a=t(`button`,`icon-btn flex-none`,e);return a.onclick=()=>o(n),u(a,i,r,()=>o(n),s),a};return{el:t(`div`,`flex flex-none items-center gap-1`,a,c(`↑`,-1,`Previous change`,[`p`,`k`]),c(`↓`,1,`Next change`,[`n`,`j`])),set(t,i){e=t,n=i,r=-1,a.textContent=`${t.length} change${t.length===1?``:`s`}`}}}async function ve(e,t){K(),N.classList.remove(`flex`,`flex-col`);let n=w.get(e)?.status!==`D`;N.replaceChildren(W(e,n),L(`…`));try{let{diff:r}=await a(F(`diff`,{base:x,head:S,file:e,context:`99999`}),`could not read this diff`);if(!J(t))return;if(!r||/^Binary files /m.test(r))return de(e,t);let i=fe(r);ue(i);let o=await c(e);if(!J(t))return;let s=f(i,o),l=[...s.children],u=pe(i);G.set(u,l),N.replaceChildren(W(e,n,G.el),s),he(u,i.length,l)}catch(n){J(t)&&N.replaceChildren(W(e,!1),L(String(n),`text-red-600`))}}let X=()=>S&&x===`${S}~1`?S:``,ye=()=>b.commits.find(e=>e.hash===X())?.subject??``,be=()=>X()?`${X()} — ${ye()||`commit`}`:`${x} ↔ ${S||`working tree`}`,xe=(e,n,r,i)=>{let a=t(`button`,`flex h-6 w-6 flex-none cursor-pointer items-center justify-center rounded-md ${r?`bg-indigo-50 text-indigo-700`:`text-neutral-400 hover:bg-neutral-100 hover:text-neutral-700`}`);return a.innerHTML=e,a.title=n,a.onclick=i,a};function Z(){let e=xe(`<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5"><path d="M2.5 3h11l-4.25 5v4.5l-2.5 1.25V8L2.5 3z" stroke-linejoin="round"/></svg>`,`Show only files that differ`,T,()=>{T=!T,Z(),H()}),n=xe(`<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" class="h-3.5 w-3.5"><path d="m4.5 2.5 3.5 3 3.5-3M4.5 13.5l3.5-3 3.5 3" stroke-linecap="round" stroke-linejoin="round"/></svg>`,E?`Restore folders`:`Collapse all folders`,E,()=>{if(E=!E,E)D=[...O],O.clear();else for(let e of D)O.add(e);Z(),H()});if(!b.branch){j.replaceChildren(t(`div`,`flex items-center justify-end gap-1 p-1.5`,n));return}let r=C(be());if(X()){let e=b.commits.find(e=>e.hash===X());_(r,()=>e?m(e):``)}else r.title=`Choose what to diff`;r.onclick=async()=>{await Te(),ee(r,b,{base:x,head:S},(e,t)=>{x=e,S=t,Q()},Ee())};let[i,a]=[0,0];for(let e of w.values())i+=e.add,a+=e.del;j.replaceChildren(t(`div`,`flex flex-col gap-1 p-2`,r,t(`div`,`flex items-center gap-1.5 pl-1`,t(`span`,`text-[11px] text-neutral-400`,`${w.size} changed file${w.size===1?``:`s`}`),...U(i,a),t(`span`,`ml-auto`),e,n)))}let Se=()=>{v&&g&&ie(v,{cwd:g,base:x,head:S})},Ce=e=>{let t=e.replace(/~\d+$/,``);return!t||t===`HEAD`||b.refs.some(e=>e.name===t)||b.commits.some(e=>e.hash===t)};async function we(){if(w=new Map,!b.branch)return;let{files:e}=await a(F(`diff`,{base:x,head:S}),`could not read what changed`);for(let t of e)w.set(t.path,{status:t.status,add:t.add,del:t.del});if(w.size<=ne)for(let e of w.keys()){let t=e.split(`/`);for(let e=1;e<t.length;e++)O.add(t.slice(0,e).join(`/`))}}async function Q(){Se();try{await we()}catch(e){Z(),M.replaceChildren(L(String(e),`text-red-600`));return}Z(),H(),k&&Y(k)}function $(){let e=C(g||`Choose a folder…`,`neutral`);e.className+=` max-w-72`,e.title=`Switch folder`,e.onclick=()=>l(e,b.worktrees.map(e=>({path:e.path,...e.branch?{hint:e.branch}:{}})),g||void 0,s);let n=C(`Terminal`,`neutral`);n.title=`Open a shell in this folder`,n.onclick=()=>p(g);let r=t(`button`,`icon-btn`,`✕`);r.type=`button`,r.title=`Close Files`,r.setAttribute(`aria-label`,`Close Files`),r.onclick=h;let i=g?[n,r]:[r];i[0].classList.add(`ml-auto`),ae.replaceChildren(e,t(`span`,`truncate font-mono text-[11.5px] text-neutral-400`,b.branch?`⎇ ${b.branch}`:`no git`),...i)}async function Te(){if(g)try{b=await a(F(`git`,{}),`could not read this repository`),$()}catch(e){N.replaceChildren(L(String(e),`text-red-600`))}}let Ee=()=>b.refs.some(e=>e.name===`main`)?`main`:b.refs.some(e=>e.name===`master`)?`master`:`HEAD`;async function De(){if($(),k=null,A=null,O.clear(),K(),N.classList.remove(`flex`,`flex-col`),N.replaceChildren(L(`Select a file.`)),!g){j.replaceChildren(),M.replaceChildren(),N.replaceChildren(L(`No folder yet — pick one from the chip above.`));return}try{b=await a(F(`git`,{}),`could not read this repository`)}catch(e){b={branch:null,refs:[],commits:[],worktrees:[]},N.replaceChildren(L(String(e),`text-red-600`))}let e=re(v),t=e&&e.cwd===g&&Ce(e.base)&&Ce(e.head)?e:null;x=t?.base??Ee(),S=t?.head??``,$(),await Q()}return r(i,e=>{let t=o(),n=t?.id??``,r=e?.startsWith(`/`)?e:(n===v?g:``)||re(n)?.cwd||t?.cwd||``;if(r===g&&n===v&&M.childElementCount){$(),Te().then(Q);return}v=n,g=r,De()},()=>{K(),N.classList.remove(`flex`,`flex-col`),N.replaceChildren(L(`Select a file.`))})}export{w as createExplorerView};
|
|
Binary file
|
|
Binary file
|