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...@@ -19,7 +19,9 @@ project followed by ` | <workspace id>`, with the same logo. Additional chats
19in that project use the same workspace folder.19in that project use the same workspace folder.
2020
21`ws new` and `ws open` accept `--no-open` to bind the chat without navigating21`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 to22the 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
23standard error. The chat opens in an empty folder before fetching or creating25standard error. The chat opens in an empty folder before fetching or creating
24the JJ workspace; `--background` returns without waiting for preparation.26the JJ workspace; `--background` returns without waiting for preparation.
25Claude and Codex startup and prompt hooks wait for the workspace to be ready.27Claude 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) {...@@ -526,10 +526,10 @@ async function openChat(id, config, client, open = true) {
526 "Add the source repository to T3 Code before creating a workspace chat.",526 "Add the source repository to T3 Code before creating a workspace chat.",
527 );527 );
528 }528 }
529 const previous = [...snapshot.threads, ...snapshot.archivedThreads].find(529 let thread = [...snapshot.threads, ...snapshot.archivedThreads].find(
530 (thread) => thread.id === record.threadId,530 (thread) => thread.id === record.threadId,
531 );531 );
532 if (!previous) {532 if (!thread) {
533 let project = snapshot.projects.find((project) =>533 let project = snapshot.projects.find((project) =>
534 canonical(project.workspaceRoot) === directory534 canonical(project.workspaceRoot) === directory
535 );535 );
...@@ -577,19 +577,20 @@ async function openChat(id, config, client, open = true) {...@@ -577,19 +577,20 @@ async function openChat(id, config, client, open = true) {
577 creationSource: "web",577 creationSource: "web",
578 });578 });
579 const confirmed = await client.snapshot();579 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) {
581 throw new Error(582 throw new Error(
582 "T3 Code has not confirmed the chat yet. Run ws open again.",583 "T3 Code has not confirmed the chat yet. Run ws open again.",
583 );584 );
584 }585 }
585 }586 }
586 if (previous?.archivedAt) {587 if (thread.archivedAt) {
587 await client.dispatch({ type: "thread.unarchive", threadId: previous.id });588 await client.dispatch({ type: "thread.unarchive", threadId: thread.id });
588 }589 }
589 if (previous?.settledOverride === "settled") {590 if (thread.settledOverride === "settled") {
590 await client.dispatch({591 await client.dispatch({
591 type: "thread.unsettle",592 type: "thread.unsettle",
592 threadId: previous.id,593 threadId: thread.id,
593 reason: "user",594 reason: "user",
594 });595 });
595 }596 }
...@@ -602,7 +603,12 @@ async function openChat(id, config, client, open = true) {...@@ -602,7 +603,12 @@ async function openChat(id, config, client, open = true) {
602 `t3code://threads/${environmentId}/${record.threadId}`,603 `t3code://threads/${environmentId}/${record.threadId}`,
603 ]);604 ]);
604 }605 }
605 console.log(directory);606 return {
607 workspacePath: directory,
608 projectId: thread.projectId,
609 threadId: thread.id,
610 environmentId,
611 };
606}612}
607613
608export async function main(args) {614export async function main(args) {
...@@ -647,7 +653,7 @@ export async function main(args) {...@@ -647,7 +653,7 @@ export async function main(args) {
647 }653 }
648 if (!command || command === "--help") {654 if (!command || command === "--help") {
649 console.log(655 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]",
651 );657 );
652 return;658 return;
653 }659 }
...@@ -719,8 +725,10 @@ export async function main(args) {...@@ -719,8 +725,10 @@ export async function main(args) {
719 const client = await t3();725 const client = await t3();
720 const open = ![argument, ...rest].includes("--no-open");726 const open = ![argument, ...rest].includes("--no-open");
721 const background = [argument, ...rest].includes("--background");727 const background = [argument, ...rest].includes("--background");
728 const json = [argument, ...rest].includes("--json");
722 const options = [argument, ...rest].filter((value) =>729 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"
724 );732 );
725 const id = options[0]?.startsWith("-") ? undefined : options.shift();733 const id = options[0]?.startsWith("-") ? undefined : options.shift();
726 const revision = options.length === 0734 const revision = options.length === 0
...@@ -749,7 +757,8 @@ export async function main(args) {...@@ -749,7 +757,8 @@ export async function main(args) {
749 prepared: false,757 prepared: false,
750 revision,758 revision,
751 });759 });
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);
753 const logs = path.join(home, "Library/Logs");762 const logs = path.join(home, "Library/Logs");
754 fs.mkdirSync(logs, { recursive: true });763 fs.mkdirSync(logs, { recursive: true });
755 const output = background764 const output = background
...@@ -785,7 +794,8 @@ export async function main(args) {...@@ -785,7 +794,8 @@ export async function main(args) {
785 if (rest.length > 1 || (rest[0] && rest[0] !== "--no-open")) {794 if (rest.length > 1 || (rest[0] && rest[0] !== "--no-open")) {
786 throw new Error("Run ws open <name> [--no-open].");795 throw new Error("Run ws open <name> [--no-open].");
787 }796 }
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);
789 } else if (command === "gc") {799 } else if (command === "gc") {
790 if (rest.length || (argument && argument !== "--dry-run")) {800 if (rest.length || (argument && argument !== "--dry-run")) {
791 throw new Error("Run ws gc [--dry-run].");801 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);...@@ -225,7 +225,15 @@ process.exit(result.status ?? 1);
225 }), (error) => /working copy is stale/.test(error.stderr.toString()));225 }), (error) => /working copy is stale/.test(error.stderr.toString()));
226 await main(["setup", projectWorkspace]);226 await main(["setup", projectWorkspace]);
227 await main(["setup", source]);227 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();
229 const created = (await client.snapshot()).threads.find((thread) =>237 const created = (await client.snapshot()).threads.find((thread) =>
230 thread.title === "Fixture | second"238 thread.title === "Fixture | second"
231 );239 );
...@@ -234,6 +242,13 @@ process.exit(result.status ?? 1);...@@ -234,6 +242,13 @@ process.exit(result.status ?? 1);
234 "approval-required",242 "approval-required",
235 "new chats retain the source chat's permission mode",243 "new chats retain the source chat's permission mode",
236 );244 );
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 });
237 const first = path.join(directory, "workspaces/first");252 const first = path.join(directory, "workspaces/first");
238 const second = path.join(directory, "workspaces/second");253 const second = path.join(directory, "workspaces/second");
239 const projects = (await client.snapshot()).projects;254 const projects = (await client.snapshot()).projects;
...@@ -337,19 +352,33 @@ exec "$WORKSPACE_TEST_PNPM" "$@"...@@ -337,19 +352,33 @@ exec "$WORKSPACE_TEST_PNPM" "$@"
337 path.join(directory, ".local/state/workspaces/creation-lock"),352 path.join(directory, ".local/state/workspaces/creation-lock"),
338 process.execPath,353 process.execPath,
339 script,354 script,
340 "new", "background", "--no-open", "--background",355 "new", "background", "--no-open", "--background", "--json",
341 ], {356 ], {
342 env: preparationEnv,357 env: preparationEnv,
343 stdio: ["ignore", "pipe", "pipe"],358 stdio: ["ignore", "pipe", "pipe"],
344 });359 });
345 let creatorOutput = "";360 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 });
347 creator.stderr.on("data", (chunk) => { creatorOutput += chunk; });366 creator.stderr.on("data", (chunk) => { creatorOutput += chunk; });
348 const [creatorStatus] = await once(creator, "exit");367 const [creatorStatus] = await once(creator, "exit");
349 assert.equal(creatorStatus, 0, creatorOutput);368 assert.equal(creatorStatus, 0, creatorOutput);
350 const backgroundRecord = path.join(369 const backgroundRecord = path.join(
351 directory, ".local/state/workspaces/workspaces/background.json",370 directory, ".local/state/workspaces/workspaces/background.json",
352 );371 );
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 });
353 assert.equal(JSON.parse(fs.readFileSync(backgroundRecord)).prepared, false);382 assert.equal(JSON.parse(fs.readFileSync(backgroundRecord)).prepared, false);
354 for (let attempt = 0; !fs.existsSync(fetchStarted); attempt++) {383 for (let attempt = 0; !fs.existsSync(fetchStarted); attempt++) {
355 assert.ok(attempt < 200, "background preparation starts fetching main");384 assert.ok(attempt < 200, "background preparation starts fetching main");
...@@ -374,9 +403,13 @@ exec "$WORKSPACE_TEST_PNPM" "$@"...@@ -374,9 +403,13 @@ exec "$WORKSPACE_TEST_PNPM" "$@"
374 process.execPath, script, "new", "queued", "--no-open", "--background",403 process.execPath, script, "new", "queued", "--no-open", "--background",
375 ], { env: preparationEnv, stdio: "pipe" });404 ], { env: preparationEnv, stdio: "pipe" });
376 let queuedOutput = "";405 let queuedOutput = "";
406 let queuedStdout = "";
407 queued.stdout.on("data", (chunk) => { queuedStdout += chunk; });
377 queued.stderr.on("data", (chunk) => { queuedOutput += chunk; });408 queued.stderr.on("data", (chunk) => { queuedOutput += chunk; });
378 const [queuedStatus] = await once(queued, "exit");409 const [queuedStatus] = await once(queued, "exit");
379 assert.equal(queuedStatus, 0, queuedOutput);410 assert.equal(queuedStatus, 0, queuedOutput);
411 assert.equal(queuedStdout.trim(), path.join(directory, "workspaces/queued"),
412 "default creation stdout remains the plain workspace path");
380 const queuedRecord = path.join(directory, ".local/state/workspaces/workspaces/queued.json");413 const queuedRecord = path.join(directory, ".local/state/workspaces/workspaces/queued.json");
381 assert.ok(JSON.parse(fs.readFileSync(queuedRecord)).threadId,414 assert.ok(JSON.parse(fs.readFileSync(queuedRecord)).threadId,
382 "another chat can be created while a preparation worker holds the lock");415 "another chat can be created while a preparation worker holds the lock");