authoravatarclover caruso<git@paperclover.net>2026-10-13 16:08:34-07:00
committeravatarclover caruso<git@paperclover.net>2026-11-13 16:28:31-08:00
loge2e73d63e934d5f61454e9f1d6e4d1649af89edc
treeb7e043797977dea0091258b192a857f245226545
parentd42c02bf0f8c0e77c11a68135eee6926251c0c15
signature Signed by SSH key SHA256:cOKiuRFOeSRxne6EWgHtdQQSlBxjOXm2hOCFnCdLQbQ

feat(workspaces): return structured workspace creation results

T3 Code needs identities from the existing Raycast workspace creation flow so it can navigate the resulting chat itself. ws new --json returns workspacePath, projectId, threadId, and environmentId; ordinary Raycast stdout remains the path. --no-open keeps desktop launch under the caller’s control, and --background returns before fetching or dependency preparation. Verified real synchronous and background JSON creation against the isolated V2 CLI with JJ/APFS/pnpm; confirmed plain background stdout and guarded --no-open against launching the desktop app. Assisted-by: gpt-6.1-sol

3 files changed, 61 insertions(+), 16 deletions(-)

users/clover/packages/workspaces/README.md+3-1
......@@ -19,7 +19,9 @@ project followed by ` | <workspace id>`, with the same logo. Additional chats
1919in that project use the same workspace folder.
2020
2121`ws new` and `ws open` accept `--no-open` to bind the chat without navigating
22the desktop app. Standard output is the workspace path; setup progress goes to
22the desktop app. `ws new --json` returns `{workspacePath, projectId, threadId,
23environmentId}` for callers that navigate the resulting chat themselves. By
24default, standard output is the workspace path; setup progress goes to
2325standard error. The chat opens in an empty folder before fetching or creating
2426the JJ workspace; `--background` returns without waiting for preparation.
2527Claude and Codex startup and prompt hooks wait for the workspace to be ready.
users/clover/packages/workspaces/workspaces.mjs+22-12
......@@ -526,10 +526,10 @@ async function openChat(id, config, client, open = true) {
526526 "Add the source repository to T3 Code before creating a workspace chat.",
527527 );
528528 }
529 const previous = [...snapshot.threads, ...snapshot.archivedThreads].find(
529 let thread = [...snapshot.threads, ...snapshot.archivedThreads].find(
530530 (thread) => thread.id === record.threadId,
531531 );
532 if (!previous) {
532 if (!thread) {
533533 let project = snapshot.projects.find((project) =>
534534 canonical(project.workspaceRoot) === directory
535535 );
......@@ -577,19 +577,20 @@ async function openChat(id, config, client, open = true) {
577577 creationSource: "web",
578578 });
579579 const confirmed = await client.snapshot();
580 if (!confirmed.threads.some((thread) => thread.id === threadId)) {
580 thread = confirmed.threads.find((thread) => thread.id === threadId);
581 if (!thread) {
581582 throw new Error(
582583 "T3 Code has not confirmed the chat yet. Run ws open again.",
583584 );
584585 }
585586 }
586 if (previous?.archivedAt) {
587 await client.dispatch({ type: "thread.unarchive", threadId: previous.id });
587 if (thread.archivedAt) {
588 await client.dispatch({ type: "thread.unarchive", threadId: thread.id });
588589 }
589 if (previous?.settledOverride === "settled") {
590 if (thread.settledOverride === "settled") {
590591 await client.dispatch({
591592 type: "thread.unsettle",
592 threadId: previous.id,
593 threadId: thread.id,
593594 reason: "user",
594595 });
595596 }
......@@ -602,7 +603,12 @@ async function openChat(id, config, client, open = true) {
602603 `t3code://threads/${environmentId}/${record.threadId}`,
603604 ]);
604605 }
605 console.log(directory);
606 return {
607 workspacePath: directory,
608 projectId: thread.projectId,
609 threadId: thread.id,
610 environmentId,
611 };
606612}
607613
608614export async function main(args) {
......@@ -647,7 +653,7 @@ export async function main(args) {
647653 }
648654 if (!command || command === "--help") {
649655 console.log(
650 "ws setup <repository>\nws new [name] [-r revision] [--no-open] [--background]\nws open <name> [--no-open]\nws deps <name>\nws gc [--dry-run]",
656 "ws setup <repository>\nws new [name] [-r revision] [--no-open] [--background] [--json]\nws open <name> [--no-open]\nws deps <name>\nws gc [--dry-run]",
651657 );
652658 return;
653659 }
......@@ -719,8 +725,10 @@ export async function main(args) {
719725 const client = await t3();
720726 const open = ![argument, ...rest].includes("--no-open");
721727 const background = [argument, ...rest].includes("--background");
728 const json = [argument, ...rest].includes("--json");
722729 const options = [argument, ...rest].filter((value) =>
723 value !== undefined && value !== "--no-open" && value !== "--background"
730 value !== undefined && value !== "--no-open" && value !== "--background" &&
731 value !== "--json"
724732 );
725733 const id = options[0]?.startsWith("-") ? undefined : options.shift();
726734 const revision = options.length === 0
......@@ -749,7 +757,8 @@ export async function main(args) {
749757 prepared: false,
750758 revision,
751759 });
752 await openChat(name, config, client, open);
760 const created = await openChat(name, config, client, open);
761 console.log(json ? JSON.stringify(created) : created.workspacePath);
753762 const logs = path.join(home, "Library/Logs");
754763 fs.mkdirSync(logs, { recursive: true });
755764 const output = background
......@@ -785,7 +794,8 @@ export async function main(args) {
785794 if (rest.length > 1 || (rest[0] && rest[0] !== "--no-open")) {
786795 throw new Error("Run ws open <name> [--no-open].");
787796 }
788 await openChat(argument, config, await t3(), rest[0] !== "--no-open");
797 const opened = await openChat(argument, config, await t3(), rest[0] !== "--no-open");
798 console.log(opened.workspacePath);
789799 } else if (command === "gc") {
790800 if (rest.length || (argument && argument !== "--dry-run")) {
791801 throw new Error("Run ws gc [--dry-run].");
users/clover/packages/workspaces/workspaces.test.mjs+36-3
......@@ -225,7 +225,15 @@ process.exit(result.status ?? 1);
225225 }), (error) => /working copy is stale/.test(error.stderr.toString()));
226226 await main(["setup", projectWorkspace]);
227227 await main(["setup", source]);
228 await main(["new", "second", "--no-open"]);
228 const creationOutput = [];
229 const creationLog = mock.method(console, "log", (value) => creationOutput.push(value));
230 const noOpen = mock.method(childProcess, "execFileSync", (command, args, options) => {
231 assert.notEqual(command, "/usr/bin/open", "--no-open never launches the desktop app");
232 return run(command, args, options);
233 });
234 await main(["new", "second", "--no-open", "--json"]);
235 noOpen.mock.restore();
236 creationLog.mock.restore();
229237 const created = (await client.snapshot()).threads.find((thread) =>
230238 thread.title === "Fixture | second"
231239 );
......@@ -234,6 +242,13 @@ process.exit(result.status ?? 1);
234242 "approval-required",
235243 "new chats retain the source chat's permission mode",
236244 );
245 assert.equal(creationOutput.length, 1, "JSON creation writes one structured result");
246 assert.deepEqual(JSON.parse(creationOutput[0]), {
247 workspacePath: path.join(directory, "workspaces/second"),
248 projectId: created.projectId,
249 threadId: created.id,
250 environmentId: client.environment.environmentId,
251 });
237252 const first = path.join(directory, "workspaces/first");
238253 const second = path.join(directory, "workspaces/second");
239254 const projects = (await client.snapshot()).projects;
......@@ -337,19 +352,33 @@ exec "$WORKSPACE_TEST_PNPM" "$@"
337352 path.join(directory, ".local/state/workspaces/creation-lock"),
338353 process.execPath,
339354 script,
340 "new", "background", "--no-open", "--background",
355 "new", "background", "--no-open", "--background", "--json",
341356 ], {
342357 env: preparationEnv,
343358 stdio: ["ignore", "pipe", "pipe"],
344359 });
345360 let creatorOutput = "";
346 creator.stdout.on("data", (chunk) => { creatorOutput += chunk; });
361 let creatorStdout = "";
362 creator.stdout.on("data", (chunk) => {
363 creatorOutput += chunk;
364 creatorStdout += chunk;
365 });
347366 creator.stderr.on("data", (chunk) => { creatorOutput += chunk; });
348367 const [creatorStatus] = await once(creator, "exit");
349368 assert.equal(creatorStatus, 0, creatorOutput);
350369 const backgroundRecord = path.join(
351370 directory, ".local/state/workspaces/workspaces/background.json",
352371 );
372 const backgroundCreation = JSON.parse(creatorStdout);
373 const backgroundThread = (await client.snapshot()).threads.find(
374 (thread) => thread.id === backgroundCreation.threadId,
375 );
376 assert.deepEqual(backgroundCreation, {
377 workspacePath: background,
378 projectId: backgroundThread.projectId,
379 threadId: backgroundThread.id,
380 environmentId: client.environment.environmentId,
381 });
353382 assert.equal(JSON.parse(fs.readFileSync(backgroundRecord)).prepared, false);
354383 for (let attempt = 0; !fs.existsSync(fetchStarted); attempt++) {
355384 assert.ok(attempt < 200, "background preparation starts fetching main");
......@@ -374,9 +403,13 @@ exec "$WORKSPACE_TEST_PNPM" "$@"
374403 process.execPath, script, "new", "queued", "--no-open", "--background",
375404 ], { env: preparationEnv, stdio: "pipe" });
376405 let queuedOutput = "";
406 let queuedStdout = "";
407 queued.stdout.on("data", (chunk) => { queuedStdout += chunk; });
377408 queued.stderr.on("data", (chunk) => { queuedOutput += chunk; });
378409 const [queuedStatus] = await once(queued, "exit");
379410 assert.equal(queuedStatus, 0, queuedOutput);
411 assert.equal(queuedStdout.trim(), path.join(directory, "workspaces/queued"),
412 "default creation stdout remains the plain workspace path");
380413 const queuedRecord = path.join(directory, ".local/state/workspaces/workspaces/queued.json");
381414 assert.ok(JSON.parse(fs.readFileSync(queuedRecord)).threadId,
382415 "another chat can be created while a preparation worker holds the lock");