| author | |
| committer | |
| log | e2e73d63e934d5f61454e9f1d6e4d1649af89edc |
| tree | b7e043797977dea0091258b192a857f245226545 |
| parent | d42c02bf0f8c0e77c11a68135eee6926251c0c15 |
| signature | Signed by SSH key SHA256:cOKiuRFOeSRxne6EWgHtdQQSlBxjOXm2hOCFnCdLQbQ |
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-sol3 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 | 19 | in that project use the same workspace folder. |
| 20 | 20 | |
| 21 | 21 | `ws new` and `ws open` accept `--no-open` to bind the chat without navigating |
| 22 | the desktop app. Standard output is the workspace path; setup progress goes to | |
| 22 | the desktop app. `ws new --json` returns `{workspacePath, projectId, threadId, | |
| 23 | environmentId}` for callers that navigate the resulting chat themselves. By | |
| 24 | default, standard output is the workspace path; setup progress goes to | |
| 23 | 25 | standard error. The chat opens in an empty folder before fetching or creating |
| 24 | 26 | the JJ workspace; `--background` returns without waiting for preparation. |
| 25 | 27 | Claude 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 | 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 | 530 | (thread) => thread.id === record.threadId, |
| 531 | 531 | ); |
| 532 | if (!previous) { | |
| 532 | if (!thread) { | |
| 533 | 533 | let project = snapshot.projects.find((project) => |
| 534 | 534 | canonical(project.workspaceRoot) === directory |
| 535 | 535 | ); |
| ... | ... | @@ -577,19 +577,20 @@ async function openChat(id, config, client, open = true) { |
| 577 | 577 | creationSource: "web", |
| 578 | 578 | }); |
| 579 | 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 | 582 | throw new Error( |
| 582 | 583 | "T3 Code has not confirmed the chat yet. Run ws open again.", |
| 583 | 584 | ); |
| 584 | 585 | } |
| 585 | 586 | } |
| 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 }); | |
| 588 | 589 | } |
| 589 | if (previous?.settledOverride === "settled") { | |
| 590 | if (thread.settledOverride === "settled") { | |
| 590 | 591 | await client.dispatch({ |
| 591 | 592 | type: "thread.unsettle", |
| 592 | threadId: previous.id, | |
| 593 | threadId: thread.id, | |
| 593 | 594 | reason: "user", |
| 594 | 595 | }); |
| 595 | 596 | } |
| ... | ... | @@ -602,7 +603,12 @@ async function openChat(id, config, client, open = true) { |
| 602 | 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 | } |
| 607 | 613 | |
| 608 | 614 | export async function main(args) { |
| ... | ... | @@ -647,7 +653,7 @@ export async function main(args) { |
| 647 | 653 | } |
| 648 | 654 | if (!command || command === "--help") { |
| 649 | 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 | 658 | return; |
| 653 | 659 | } |
| ... | ... | @@ -719,8 +725,10 @@ export async function main(args) { |
| 719 | 725 | const client = await t3(); |
| 720 | 726 | const open = ![argument, ...rest].includes("--no-open"); |
| 721 | 727 | const background = [argument, ...rest].includes("--background"); |
| 728 | const json = [argument, ...rest].includes("--json"); | |
| 722 | 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 | 733 | const id = options[0]?.startsWith("-") ? undefined : options.shift(); |
| 726 | 734 | const revision = options.length === 0 |
| ... | ... | @@ -749,7 +757,8 @@ export async function main(args) { |
| 749 | 757 | prepared: false, |
| 750 | 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 | 762 | const logs = path.join(home, "Library/Logs"); |
| 754 | 763 | fs.mkdirSync(logs, { recursive: true }); |
| 755 | 764 | const output = background |
| ... | ... | @@ -785,7 +794,8 @@ export async function main(args) { |
| 785 | 794 | if (rest.length > 1 || (rest[0] && rest[0] !== "--no-open")) { |
| 786 | 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 | 799 | } else if (command === "gc") { |
| 790 | 800 | if (rest.length || (argument && argument !== "--dry-run")) { |
| 791 | 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 | 225 | }), (error) => /working copy is stale/.test(error.stderr.toString())); |
| 226 | 226 | await main(["setup", projectWorkspace]); |
| 227 | 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 | 237 | const created = (await client.snapshot()).threads.find((thread) => |
| 230 | 238 | thread.title === "Fixture | second" |
| 231 | 239 | ); |
| ... | ... | @@ -234,6 +242,13 @@ process.exit(result.status ?? 1); |
| 234 | 242 | "approval-required", |
| 235 | 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 | 252 | const first = path.join(directory, "workspaces/first"); |
| 238 | 253 | const second = path.join(directory, "workspaces/second"); |
| 239 | 254 | const projects = (await client.snapshot()).projects; |
| ... | ... | @@ -337,19 +352,33 @@ exec "$WORKSPACE_TEST_PNPM" "$@" |
| 337 | 352 | path.join(directory, ".local/state/workspaces/creation-lock"), |
| 338 | 353 | process.execPath, |
| 339 | 354 | script, |
| 340 | "new", "background", "--no-open", "--background", | |
| 355 | "new", "background", "--no-open", "--background", "--json", | |
| 341 | 356 | ], { |
| 342 | 357 | env: preparationEnv, |
| 343 | 358 | stdio: ["ignore", "pipe", "pipe"], |
| 344 | 359 | }); |
| 345 | 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 | 366 | creator.stderr.on("data", (chunk) => { creatorOutput += chunk; }); |
| 348 | 367 | const [creatorStatus] = await once(creator, "exit"); |
| 349 | 368 | assert.equal(creatorStatus, 0, creatorOutput); |
| 350 | 369 | const backgroundRecord = path.join( |
| 351 | 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 | 382 | assert.equal(JSON.parse(fs.readFileSync(backgroundRecord)).prepared, false); |
| 354 | 383 | for (let attempt = 0; !fs.existsSync(fetchStarted); attempt++) { |
| 355 | 384 | assert.ok(attempt < 200, "background preparation starts fetching main"); |
| ... | ... | @@ -374,9 +403,13 @@ exec "$WORKSPACE_TEST_PNPM" "$@" |
| 374 | 403 | process.execPath, script, "new", "queued", "--no-open", "--background", |
| 375 | 404 | ], { env: preparationEnv, stdio: "pipe" }); |
| 376 | 405 | let queuedOutput = ""; |
| 406 | let queuedStdout = ""; | |
| 407 | queued.stdout.on("data", (chunk) => { queuedStdout += chunk; }); | |
| 377 | 408 | queued.stderr.on("data", (chunk) => { queuedOutput += chunk; }); |
| 378 | 409 | const [queuedStatus] = await once(queued, "exit"); |
| 379 | 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 | 413 | const queuedRecord = path.join(directory, ".local/state/workspaces/workspaces/queued.json"); |
| 381 | 414 | assert.ok(JSON.parse(fs.readFileSync(queuedRecord)).threadId, |
| 382 | 415 | "another chat can be created while a preparation worker holds the lock"); |