GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(web): add metadata-led task navigation and relink controls (#43) · tomcorke/t3code@b4d6358

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps
    • server/src/tasks
      • TaskDocuments.test.ts
      • TaskDocuments.ts
    • web/src
      • components/tasks
        • TaskDocumentPane.tsx
        • TaskPropertiesDialog.tsx
        • TaskRelinkDialog.tsx
        • TasksSidebarSection.tsx
        • useTaskDocuments.browser.test.tsx
        • useTaskDocuments.ts
      • routes
        • _chat.task.$environmentId.$taskDocumentId.tsx
  • docs/user
    • tasks.md
  • packages
    • client-runtime/src/state
      • taskDocuments.ts
    • contracts/src
      • taskDocuments.ts
    • shared/src
      • markdownFrontmatter.test.ts
      • markdownFrontmatter.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/tasks/TaskDocuments.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/tasks/TaskDocuments.test.ts
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,65 @@ describe("TaskDocuments", () => {
253253
}).pipe(Effect.scoped, Effect.provide(layer)),
254254
);
255255

256+
it.effect("reconciles a changed file ID only when explicitly requested", () =>
257+
Effect.gen(function* () {
258+
const { fs, path, directory, target, service } = yield* setup;
259+
const original = yield* service.register({ path: target });
260+
const duplicateId = "b8cf0bb8-531f-4d13-9aa3-3219ee85e623";
261+
const replacementId = "c9df1cc9-642f-4e24-8bb4-432a0ff96f34";
262+
const duplicate = path.join(directory, "other.md");
263+
const replacement = path.join(directory, "replacement.md");
264+
yield* fs.writeFileString(duplicate, fixture.replace(fileId, duplicateId));
265+
yield* service.register({ path: duplicate });
266+
yield* fs.writeFileString(replacement, fixture.replace(fileId, replacementId));
267+
268+
expect(
269+
yield* service.relink({ ...original.summary, path: replacement }).pipe(Effect.flip),
270+
).toMatchObject({ reason: "identity-changed" });
271+
yield* fs.writeFileString(replacement, fixture.replace(fileId, duplicateId));
272+
expect(
273+
yield* service
274+
.relink({ ...original.summary, path: replacement, reconcileIdentity: true })
275+
.pipe(Effect.flip),
276+
).toMatchObject({ reason: "duplicate-id" });
277+
278+
yield* fs.writeFileString(replacement, fixture.replace(fileId, replacementId));
279+
const relinked = yield* service.relink({
280+
...original.summary,
281+
path: replacement,
282+
reconcileIdentity: true,
283+
});
284+
expect(relinked.summary).toMatchObject({
285+
taskDocumentId: original.summary.taskDocumentId,
286+
canonicalPath: replacement,
287+
locatorVersion: original.summary.locatorVersion + 1,
288+
observedFileId: replacementId,
289+
availability: "available",
290+
});
291+
}).pipe(Effect.scoped, Effect.provide(layer)),
292+
);
293+
294+
it.effect("reads task metadata from bare-CR frontmatter closed with ...", () =>
295+
Effect.gen(function* () {
296+
const { fs, path, directory, service } = yield* setup;
297+
const id = "d0ae6d1e-5375-4e9a-817d-721cb4fdb91d";
298+
const target = path.join(directory, "bare-cr.md");
299+
yield* fs.writeFileString(
300+
target,
301+
`---\rid: ${id}\rtitle: "CR task"\rstate: "Ready"\rpinned: true\r...\r# Body\r`,
302+
);
303+
304+
const opened = yield* service.register({ path: target });
305+
expect(opened.summary).toMatchObject({
306+
observedFileId: id,
307+
title: "CR task",
308+
state: "Ready",
309+
pinned: true,
310+
availability: "available",
311+
});
312+
}).pipe(Effect.scoped, Effect.provide(layer)),
313+
);
314+
256315
it.effect(
257316
"relinks a missing file without recreating its old locator, and unregisters without deletion",
258317
() =>
Collapse file

‎apps/server/src/tasks/TaskDocuments.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/tasks/TaskDocuments.ts
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ const decodeRecovery = Schema.decodeUnknownEffect(Schema.fromJsonString(TaskDocu
9494
const encodeRecovery = Schema.encodeEffect(Schema.fromJsonString(TaskDocumentRecovery));
9595

9696
function metadata(contents: string) {
97-
const frontmatter = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(contents)?.[1];
98-
const document = parseDocument(frontmatter ?? "", { uniqueKeys: true });
97+
const frontmatter =
98+
/^\uFEFF?---[ \t]*(?:\r\n|\r|\n)([\s\S]*?)(?:\r\n|\r|\n)(?:---|\.\.\.)[ \t]*(?:\r\n|\r|\n|$)/.exec(
99+
contents,
100+
)?.[1];
101+
const document = parseDocument((frontmatter ?? "").replace(/\r(?!\n)/g, "\n"), {
102+
uniqueKeys: true,
103+
});
99104
const get = (key: string): unknown =>
100105
document.errors.length === 0 ? document.get(key) : undefined;
101106
const id = decodeUuid(get("id"));
@@ -563,10 +568,10 @@ const make = Effect.gen(function* () {
563568
return yield* new TaskDocumentError({ reason: "unsupported" });
564569
const file = yield* read(input.path);
565570
yield* unique(file, row.taskDocumentId);
566-
if (file.metadata.fileId !== row.observedFileId)
571+
if (file.metadata.fileId !== row.observedFileId && input.reconcileIdentity !== true)
567572
return yield* new TaskDocumentError({ reason: "identity-changed" });
568573
yield* mapIo(
569-
sql`UPDATE task_documents SET canonical_path = ${file.canonicalPath}, locator_version = locator_version + 1 WHERE task_document_id = ${row.taskDocumentId}`,
574+
sql`UPDATE task_documents SET canonical_path = ${file.canonicalPath}, file_id = ${file.metadata.fileId}, locator_version = locator_version + 1 WHERE task_document_id = ${row.taskDocumentId}`,
570575
);
571576
yield* notify(row.taskDocumentId);
572577
yield* syncWatches();
Collapse file

‎apps/web/src/components/tasks/TaskDocumentPane.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/tasks/TaskDocumentPane.tsx
+91-8Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "@t3tools/contracts";
1313
import { maskMarkdownFrontmatter } from "@t3tools/shared/markdownFrontmatter";
1414
import { Link, useNavigate } from "@tanstack/react-router";
15-
import { CodeIcon, EyeIcon, MaximizeIcon, PlusIcon, SaveIcon } from "lucide-react";
15+
import { CodeIcon, EyeIcon, MaximizeIcon, PencilIcon, PlusIcon, SaveIcon } from "lucide-react";
1616
import { useLayoutEffect, useRef, useState, type ReactNode } from "react";
1717

1818
import ChatMarkdown from "~/components/ChatMarkdown";
@@ -37,6 +37,8 @@ import { useProjects } from "~/state/entities";
3737
import { readTaskUpdateInstructionsPath, taskDocumentEnvironment } from "~/state/taskDocuments";
3838
import { useAtomCommand } from "~/state/use-atom-command";
3939

40+
import { TaskPropertiesDialog } from "./TaskPropertiesDialog";
41+
import { TaskRelinkDialog } from "./TaskRelinkDialog";
4042
import { type TaskSession, useTaskCatalogue, useTaskDocument } from "./useTaskDocuments";
4143

4244
const splitDocumentPath = (path: string) => {
@@ -273,14 +275,18 @@ export default function TaskDocumentPane(props: {
273275
environmentId,
274276
taskDocumentId,
275277
);
276-
const { tasks } = useTaskCatalogue(environmentId);
278+
const { tasks, canRelink } = useTaskCatalogue(environmentId);
277279
const navigate = useNavigate();
278280
const projects = useProjects();
279281
const { openScratchProject } = useScratchProject();
280282
const handleNewThread = useNewThreadHandler();
281283
const [showDisk, setShowDisk] = useState(false);
284+
const [showProperties, setShowProperties] = useState(false);
285+
const [showRelink, setShowRelink] = useState(false);
282286
const { base, draft, disk, recovery, error, saving, view } = state;
283287
const summary = base?.summary ?? null;
288+
const catalogueTask = tasks.find((candidate) => candidate.taskDocumentId === taskDocumentId);
289+
const relinkTask = summary ?? catalogueTask;
284290
const { directory, name } = splitDocumentPath(summary?.canonicalPath ?? "");
285291
const dirty = base !== null && draft !== base.contents;
286292

@@ -328,10 +334,42 @@ export default function TaskDocumentPane(props: {
328334
);
329335
}
330336
if (base === null) {
337+
const canRelinkMissing =
338+
relinkTask != null &&
339+
(relinkTask.availability === "missing" || relinkTask.availability === "identity-changed");
331340
return error ? (
332-
<p role="alert" className="m-auto p-6 text-center text-muted-foreground text-sm">
333-
{error}
334-
</p>
341+
<section className="m-auto flex max-w-xl flex-col items-center gap-3 p-6 text-center">
342+
<h2 className="font-medium text-base">{relinkTask?.title ?? "Task file unavailable"}</h2>
343+
<p role="alert" className="text-muted-foreground text-sm">
344+
{relinkTask?.availability === "missing"
345+
? "This task file is missing from its saved path."
346+
: error}
347+
</p>
348+
{relinkTask ? (
349+
<code className="max-w-full break-all text-muted-foreground text-xs">
350+
{relinkTask.canonicalPath}
351+
</code>
352+
) : null}
353+
{canRelinkMissing ? (
354+
canRelink ? (
355+
<Button size="sm" variant="outline" onClick={() => setShowRelink(true)}>
356+
Relink task file
357+
</Button>
358+
) : (
359+
<p className="text-muted-foreground text-xs">
360+
You do not have permission to relink task files on this environment.
361+
</p>
362+
)
363+
) : null}
364+
{showRelink && relinkTask ? (
365+
<TaskRelinkDialog
366+
environmentId={environmentId}
367+
task={relinkTask}
368+
onRelink={(document) => session.acceptRead(session.beginRead(), document)}
369+
onClose={() => setShowRelink(false)}
370+
/>
371+
) : null}
372+
</section>
335373
) : (
336374
<div className="m-auto p-6">
337375
<Spinner />
@@ -346,7 +384,7 @@ export default function TaskDocumentPane(props: {
346384
onKeyDown={(event) => {
347385
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "s") {
348386
event.preventDefault();
349-
void save();
387+
if (summary?.availability === "available") void save();
350388
}
351389
}}
352390
>
@@ -378,11 +416,23 @@ export default function TaskDocumentPane(props: {
378416
variant="ghost"
379417
aria-label="Save task document"
380418
title="Save task document"
381-
disabled={!canSave || !dirty || disk !== null || saving}
419+
disabled={
420+
!canSave || summary?.availability !== "available" || !dirty || disk !== null || saving
421+
}
382422
onClick={() => void save()}
383423
>
384424
{saving ? <Spinner /> : <SaveIcon />}
385425
</Button>
426+
<Button
427+
size="icon-xs"
428+
variant="ghost"
429+
aria-label="Edit task properties"
430+
title="Edit task properties"
431+
disabled={!canSave || summary?.availability !== "available" || disk !== null}
432+
onClick={() => setShowProperties(true)}
433+
>
434+
<PencilIcon />
435+
</Button>
386436
<Button
387437
size="icon-xs"
388438
variant="ghost"
@@ -416,6 +466,21 @@ export default function TaskDocumentPane(props: {
416466
thread={thread}
417467
/>
418468
) : null}
469+
{summary?.availability === "identity-changed" ? (
470+
<Notice
471+
actions={
472+
canRelink ? (
473+
<Button size="xs" variant="outline" onClick={() => setShowRelink(true)}>
474+
Relink task file
475+
</Button>
476+
) : null
477+
}
478+
>
479+
This file has a different task ID. Relink it to keep this task's threads attached before
480+
editing.
481+
{!canRelink ? " You do not have permission to relink task files here." : ""}
482+
</Notice>
483+
) : null}
419484
{error ? <Notice>{error} Your draft is kept.</Notice> : null}
420485
{!canSave ? <Notice>You can read this task but not edit it here.</Notice> : null}
421486
{disk !== null ? (
@@ -477,11 +542,29 @@ export default function TaskDocumentPane(props: {
477542
taskDocumentId={taskDocumentId}
478543
name={name}
479544
contents={draft}
480-
editable={canSave && disk === null}
545+
editable={canSave && summary?.availability === "available" && disk === null}
481546
session={session}
482547
/>
483548
</DiffWorkerPoolProvider>
484549
)}
550+
{showProperties && summary ? (
551+
<TaskPropertiesDialog
552+
contents={draft}
553+
title={summary.title}
554+
state={summary.state}
555+
pinned={summary.pinned}
556+
onApply={(contents) => session.edit(contents)}
557+
onClose={() => setShowProperties(false)}
558+
/>
559+
) : null}
560+
{showRelink && relinkTask ? (
561+
<TaskRelinkDialog
562+
environmentId={environmentId}
563+
task={relinkTask}
564+
onRelink={(document) => session.acceptRead(session.beginRead(), document)}
565+
onClose={() => setShowRelink(false)}
566+
/>
567+
) : null}
485568
</section>
486569
);
487570
}
Collapse file

‎apps/web/src/components/tasks/TaskPropertiesDialog.tsx‎

Copy file name to clipboard
+103Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { useState } from "react";
2+
3+
import { Button } from "~/components/ui/button";
4+
import { Checkbox } from "~/components/ui/checkbox";
5+
import {
6+
Dialog,
7+
DialogDescription,
8+
DialogFooter,
9+
DialogHeader,
10+
DialogPanel,
11+
DialogPopup,
12+
DialogTitle,
13+
} from "~/components/ui/dialog";
14+
import { Input } from "~/components/ui/input";
15+
import { patchTaskFrontmatter, readTaskFrontmatter } from "@t3tools/shared/markdownFrontmatter";
16+
17+
export function TaskPropertiesDialog(props: {
18+
readonly contents: string;
19+
readonly title: string;
20+
readonly state: string | null;
21+
readonly pinned: boolean;
22+
readonly onApply: (contents: string) => void;
23+
readonly onClose: () => void;
24+
}) {
25+
const metadata = readTaskFrontmatter(props.contents);
26+
const [title, setTitle] = useState(metadata?.title ?? props.title);
27+
const [state, setState] = useState(metadata?.state ?? props.state ?? "");
28+
const [pinned, setPinned] = useState(metadata?.pinned ?? props.pinned);
29+
const [error, setError] = useState(false);
30+
31+
const apply = () => {
32+
const contents = patchTaskFrontmatter(props.contents, { title, state, pinned });
33+
if (contents === null) {
34+
setError(true);
35+
return;
36+
}
37+
props.onApply(contents);
38+
props.onClose();
39+
};
40+
41+
return (
42+
<Dialog open onOpenChange={(open) => !open && props.onClose()}>
43+
<DialogPopup className="max-w-lg">
44+
<form
45+
className="flex min-h-0 flex-col"
46+
onSubmit={(event) => {
47+
event.preventDefault();
48+
apply();
49+
}}
50+
>
51+
<DialogHeader>
52+
<DialogTitle>Task properties</DialogTitle>
53+
<DialogDescription>
54+
Changes stay in your draft until you save the task file.
55+
</DialogDescription>
56+
</DialogHeader>
57+
<DialogPanel>
58+
<div className="flex flex-col gap-3">
59+
<label className="flex flex-col gap-1 text-sm">
60+
Title
61+
<Input
62+
autoFocus
63+
maxLength={512}
64+
value={title}
65+
onChange={(event) => setTitle(event.target.value)}
66+
/>
67+
</label>
68+
<label className="flex flex-col gap-1 text-sm">
69+
State
70+
<Input
71+
maxLength={512}
72+
placeholder="No state"
73+
value={state}
74+
onChange={(event) => setState(event.target.value)}
75+
/>
76+
</label>
77+
<label className="flex items-center gap-2 text-sm">
78+
<Checkbox
79+
checked={pinned}
80+
onCheckedChange={(checked) => setPinned(checked === true)}
81+
/>
82+
Pin this task
83+
</label>
84+
{error ? (
85+
<p role="alert" className="text-destructive-foreground text-sm">
86+
The frontmatter could not be patched safely. Edit it in the source and try again.
87+
</p>
88+
) : null}
89+
</div>
90+
</DialogPanel>
91+
<DialogFooter>
92+
<Button type="button" variant="ghost" onClick={props.onClose}>
93+
Cancel
94+
</Button>
95+
<Button type="submit" disabled={title.trim() === ""}>
96+
Apply changes
97+
</Button>
98+
</DialogFooter>
99+
</form>
100+
</DialogPopup>
101+
</Dialog>
102+
);
103+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.