Repository navigation
feat: add project-local cmux Artifacts #8610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
austinywang
wants to merge
250
commits into
main
Choose a base branch
from
feat-cmux-artifacts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+29,758
−1,145
Open
Changes from 3 commits
Commits
Show all changes
250 commits
Select commit
Hold shift + click to select a range
9c903a5
feat(artifacts): add project-local artifact store
austinywang 4837f70
feat(artifacts): capture and browse agent artifacts
austinywang fef3f38
fix(artifacts): harden capture lifecycle
austinywang 4ba8b67
fix(artifacts): bound batch capture work
austinywang 6294f28
test(artifacts): cover review safety regressions
austinywang ebb60f1
fix(artifacts): close review lifecycle gaps
austinywang d2cd193
test(artifacts): cover corrupt provenance rollback
austinywang 9cb670c
fix(artifacts): fail closed on corrupt provenance
austinywang 0e4d238
test(artifacts): cover out-of-order capture completion
austinywang 3939d8d
fix(artifacts): keep capture generations monotonic
austinywang 6247250
test(artifacts): cover dedupe beyond sidebar budget
austinywang b00cfa6
fix(artifacts): scan moved files beyond sidebar budget
austinywang 990cf56
test(artifacts): cover review lifecycle regressions
austinywang 3e4c494
fix(artifacts): harden capture ordering and lifecycle
austinywang d95a898
test(artifacts): cover bounded capture and search safety
austinywang f9caef0
fix(artifacts): bound filesystem recovery and search
austinywang f2d13ad
fix(artifacts): coalesce bounded transcript capture
austinywang a7d72ed
fix(artifacts): satisfy pre-merge architecture checks
austinywang 6740d15
test: cover artifact review regressions
austinywang b22fe7c
fix: bound and beta-gate artifact capture
austinywang 79ff63b
test: cover artifact lifecycle safety
austinywang 0fe11cc
fix: harden artifact lifecycle safety
austinywang 601d357
test: cover artifact capture authorization boundaries
austinywang c2829af
fix: enforce artifact capture authorization boundaries
austinywang e1b9f18
fix: make artifact deduplication traversal iterative
austinywang 70cbdb4
test: cover artifact capture authorization gaps
austinywang 11dbca7
fix: harden automatic artifact capture authorization
austinywang 6b14d65
test: cover remaining artifact capture safety gaps
austinywang 5b2e564
fix: close artifact automatic capture safety gaps
austinywang 7d5b66e
fix: bound artifact Git tracked checks
austinywang f021277
test: cover artifact capture review regressions
austinywang 3d52d86
fix: address artifact capture review findings
austinywang 7c9a15b
test: cover reserved artifact marker filenames
austinywang b7efcbb
fix: reserve artifact marker destinations
austinywang 6991411
test: cover case-insensitive artifact markers
austinywang effb891
fix: honor artifact marker volume semantics
austinywang 4aa5f32
test: cover artifact import ownership races
austinywang 8b5b16a
refactor: isolate resolved artifact save phase
austinywang bc4b356
test: cover artifact save authorization snapshots
austinywang dc1e4c8
fix: preserve artifact capture ownership invariants
austinywang efb0b48
test: cover canceled artifact staging copies
austinywang 6456161
fix: cancel artifact staging copies promptly
austinywang fa36c0f
test: cover artifact batch and mutation boundaries
austinywang 1325316
fix: enforce artifact mutation boundaries
austinywang 75cb5ce
test: cover artifact Git safety boundaries
austinywang 5316585
fix: harden artifact Git safety checks
austinywang a82332d
test: cover remaining artifact review boundaries
austinywang 7964928
fix: close artifact scan and attribution boundaries
austinywang 1e9fe37
test: cover artifact resource boundaries
austinywang 8e4f8e6
fix: bound artifact discovery resources
austinywang 4c43dab
test: define session-rooted cmux filesystem
austinywang 9e75db8
feat: unify project files by agent session
austinywang 0f84f15
docs: add cmux project files agent skill
austinywang 7d7ead9
test: split artifact capture coordinator fixture
austinywang 9033ec1
test: cover artifact authorization resets
austinywang d70c5ce
fix: preserve project file authorization boundaries
austinywang aaaa123
test: cover project file privacy edge cases
austinywang d14421b
fix: fail closed on project file privacy
austinywang 54cf9eb
test: require unresolved Git markers to fail closed
austinywang 4dde794
test: cover exact note mutations and turn completion
austinywang 1299a45
fix: require exact project file mutations
austinywang b9d0e90
test: cover artifact identity and preview isolation
austinywang 558d8d0
test: require artifact preview navigation confinement
austinywang caffc95
fix: isolate artifact sessions and HTML previews
austinywang e596205
Merge remote-tracking branch 'origin/main' into feat-cmux-artifacts
austinywang 83d71e6
fix: propagate artifact open failures
austinywang aa3ec2e
test: cover short identities and preview restoration
austinywang 20faa67
fix: harden artifact session identity and preview lifecycle
austinywang 7f2565f
test: cover artifact preview and note safety
austinywang 182762a
fix: keep artifact previews and notes private
austinywang 6abe865
fix: inject the agent chat session registry
austinywang b5fc7d4
test: cover reorganized privacy and read-write redirection
austinywang de059fe
fix: close artifact privacy gaps
austinywang aff8d88
test: cover artifact import safety bounds
austinywang 1d82761
fix: enforce artifact import safety bounds
austinywang 26f024d
test: cover native sessions and FIFO capture
austinywang de3b52b
fix: preserve session identity without blocking
austinywang 1ee3d93
fix: import artifact app dependencies
austinywang 43fc5de
test: cover artifact session and ignore races
austinywang 7a78df2
fix: isolate artifact identity and Git privacy
austinywang be5cddb
Merge remote-tracking branch 'origin/main' into feat-cmux-artifacts
austinywang 3ab57ab
test: cover conflicting agent identity values
austinywang bf21423
fix: reject conflicting agent session values
austinywang 19b20be
test: isolate artifact provider identities
austinywang 45127e0
fix: key artifact sessions by provider identity
austinywang 9d4f795
test: reject ambiguous cmux filesystem identities
austinywang 49b17fd
fix: enforce cmux session filesystem identity
austinywang ee6640d
test: protect artifact append and workspace boundaries
austinywang d869c7d
fix: isolate artifact mutation scopes
austinywang c74fb5c
test: bound artifact lock and thumbnail revisions
austinywang 88e63a6
fix: bound artifact locks and refresh thumbnails
austinywang 58d6dc4
test: close artifact review gaps
austinywang 7b92c33
fix: enforce artifact capture boundaries
austinywang 1c18bec
test: cover artifact runtime ownership gaps
austinywang c3faa37
fix: reconcile artifact runtime ownership
austinywang dfc4f29
test: bound artifact capture enable resolution
austinywang 0004f00
fix: bound artifact capture enable resolution
austinywang e9f06c5
test: cover artifact capture review findings
austinywang 5841012
fix: bound capture batches and focus artifact search
austinywang e2d81b7
test: cover artifact continuation and note control paths
austinywang 56280ab
fix: validate note paths and continue bounded captures
austinywang 39d0951
test: bound artifact-only hook resolution
austinywang 377147c
fix: bound artifact-only hook resolution
austinywang 89566f2
test: cover artifact capture safety gaps
austinywang d6d1bd6
fix: harden artifact persistence and retries
austinywang b296f68
test: cover off-main artifact model release
austinywang 1b9e2d4
fix: make artifact sidebar teardown executor-safe
austinywang 7a639d2
test: cover artifact review regressions
austinywang 790022e
fix: keep artifact reads side-effect-free
austinywang 06d58cf
test: cover final artifact review findings
austinywang b6fd1e3
fix: harden artifact capture revisions
austinywang ae43111
fix: use safe stdout for note reads
austinywang 9d8b2d6
test: preserve artifact authorization across capture batches
austinywang d753652
fix: preserve artifact authority across batches
austinywang 918252d
test: cover artifact rewrite and sidechain capture
austinywang 989304f
fix: revoke unverified artifact authority
austinywang a9d1f6c
test: cover final artifact capture review findings
austinywang 87c59e9
fix: bound and authorize artifact capture inputs
austinywang 61261da
test: cover transcript artifact ownership boundaries
austinywang 4798e58
fix: centralize artifact transcript resolution
austinywang 99251d3
Merge remote-tracking branch 'origin/main' into feat-cmux-artifacts
austinywang 4df89e9
test: cover artifact capture completion bounds
austinywang e1280e9
fix: share coding agent definitions with CLI
austinywang 610be93
fix: handle artifact batch size errors in CLI
austinywang eafde52
test: cover note CLI input source validation
austinywang 7cdda29
fix: remove stale prose streamer project references
austinywang bdcdccb
fix: import agent launch types in artifact tests
austinywang 711d669
fix: import agent chat models in artifact tests
austinywang 917043e
fix: import artifact capture types in index tests
austinywang 239818f
fix: validate note input source exclusivity
austinywang fa52ecf
fix: capture completed turns with bounded transcript reads
austinywang 3be681d
refactor: keep artifact helpers on owning types
austinywang e251e14
Merge remote-tracking branch 'origin/main' into feat-cmux-artifacts
austinywang 6d86a31
refactor: align artifact ownership and tests
austinywang 90e7e10
fix: preserve sendability for injected filesystem helpers
austinywang 08b27e0
test: cover referenced ephemeral prefix policy
austinywang c609195
fix: qualify artifact staging lease constants
austinywang 80746d8
test: reject symlinked ephemeral prefixes
austinywang 4c0934e
fix: enforce trusted ephemeral capture prefixes
austinywang 93814ec
Merge origin/main into feat-cmux-artifacts
austinywang cc02bdb
fix: align merged submodule pointers
austinywang 60ba465
fix: close review safety gaps
austinywang 7a41b78
test: cover transcript mutation and tailer bounds
austinywang c16f59a
fix: bound artifact transcript tailers and authorization
austinywang 3d87d57
Merge remote-tracking branch 'origin/main' into feat-cmux-artifacts
austinywang 0a5b598
fix: close artifact review findings
austinywang 2654a26
test: cover artifact capture coalescing and source races
austinywang 396c3d1
fix: coalesce artifact capture and close source TOCTOU
austinywang 3b0b55a
test: cover artifact mutation and preview policy races
austinywang 8381ce4
fix: close artifact mutation and preview races
austinywang c836446
fix: preserve trusted preview and canonical note paths
austinywang 887dcb4
test: cover shell, preview, and exclude safety
austinywang 4975d8f
fix: close remaining artifact safety gaps
austinywang 1f5f764
Merge remote-tracking branch 'origin/main' into feat-cmux-artifacts
austinywang 2ffac5b
test: preserve resolved artifact project roots
austinywang 6c1aa68
fix: bound historical captures and reuse project roots
austinywang 80477e3
fix: close final artifact CLI review gaps
austinywang ef82057
test: cover mobile artifact gates and row revalidation
austinywang 2a136cc
fix: gate and revalidate mobile artifact opens
austinywang c2760c0
test: cover artifact capture bounds and teardown
austinywang 5369fbd
fix: bound pending artifact mutations and teardown capture
austinywang 07d4509
test: fix tailer ownership fixture identities
austinywang 7069c76
fix: close artifact preview and mutation races
austinywang 067fd9f
fix: confine gallery and provenance artifact paths
austinywang 006f37d
fix: bound transcript capture and tailer ownership
austinywang a0a4d70
fix: preserve mobile save authorization and git fallback
austinywang c309575
test: cover transcript rewrite and save safety
austinywang e1fa783
fix: close remaining artifact bounds and privacy gaps
austinywang d9627e6
test: cover staging and capture workload bounds
austinywang 1c27545
fix: confine staging cleanup and cap capture workloads
austinywang 684d676
test: cover capture retry and lease confinement
austinywang dacd130
fix: pin artifact leases and preserve capture retries
austinywang f66488d
fix: close final capture and descriptor safety gaps
austinywang 7607444
test: cover staging symlink recovery
austinywang b1a2e52
fix: confine staging recovery and artifact previews
austinywang 8864fdc
test: cover read-only capture and stale staging cleanup
austinywang 49b8a6f
fix: confine note opens and avoid read-only capture scans
austinywang a1ca5cc
test: cover unknown Claude tool results
austinywang 8061a38
fix: bound references and secure auxiliary artifact reads
austinywang 3fd0a3c
test: cover fragment preview and missing-artifact progress
austinywang 112352c
fix: stabilize artifact previews and capture progress
austinywang a970bab
fix: preserve confined artifact handoffs and markdown resources
austinywang d736876
fix: pin marker writes and bound external artifact handoffs
austinywang a182c9e
fix: harden artifact roots and temporary open files
austinywang b86e3d3
fix: bound mobile tailers and pin preview consumers
austinywang 8405cbf
fix: preserve tool status and coalesce artifact refreshes
austinywang 3b8274d
test: cover artifact cache, watcher, and CLI bounds
austinywang 8e84316
fix: close artifact cache, watcher, and CLI review gaps
austinywang 220f07e
test: cover artifact recency and destructive CLI guards
austinywang 2ca7c41
fix: harden artifact recency and destructive CLI paths
austinywang 2f36a8e
fix: fence artifact lifecycle and preview paths
austinywang aff1da5
fix: bound artifact resolution and preview concurrency
austinywang 8ed03d4
fix: secure artifact handoffs and save affordances
austinywang 51abb60
fix: move markdown artifact image staging off main actor
austinywang d336ab9
fix: protect active artifact handoffs
austinywang 296697e
fix: fence project identity and save eligibility
austinywang a341928
fix: tighten transcript status and preview refresh fences
austinywang f3325d1
refactor: separate artifact recency heap entry
austinywang a8d7c75
fix: bound stale artifact scans and previews
austinywang c8f4cb8
fix: close transcript and artifact refresh races
austinywang 6092f69
fix: close artifact sidebar safety gaps
austinywang ad440e4
fix: make artifact preview handoffs race-safe
austinywang db8f9ec
fix: pin artifact drag descriptors
austinywang 1cc69c0
fix: retain artifact drag names and leases
austinywang dc3e5ca
fix: finish artifact drag progress
austinywang 91edf4f
Merge origin/main into feat-cmux-artifacts
austinywang 3b564dc
fix: bound artifact refresh and save work
austinywang cfc3ffc
fix: coalesce watcher events during scans
austinywang 93b700b
fix: cancel artifact watcher children with rebinds
austinywang a29a147
fix: reset watcher state on artifact rebind
austinywang ba412dd
fix: close remaining artifact review gaps
austinywang 2712552
fix: harden artifact save and transcript status
austinywang 3cda164
fix: keep artifact retries and status evidence safe
austinywang 30693ee
fix: parse transcript failure envelopes safely
austinywang c0d957c
fix: keep transcript status evidence provider-scoped
austinywang 528080b
fix: retain exact transcript failure markers
austinywang 0b6b71b
fix: retain multiline transcript failure prefixes
austinywang fb21398
Merge origin/main into feat-cmux-artifacts
austinywang 288472d
fix: authorize mobile chat artifact tickets
austinywang 2ca1a0d
fix: bound structured artifact path extraction
austinywang f24033f
fix: honor explicit transcript success status
austinywang bb6062e
fix: wire artifact sidebar file into app target
austinywang 7a12ff4
fix: scope mobile artifact saves to Mac-wide tickets
austinywang f8cad67
fix: bound transcript artifact path retention
austinywang 26f0db6
fix: prefer native agent identity for project files
austinywang 27a9c8a
fix: reserve zero-byte project-file handoff slots
austinywang 1401867
fix: move artifact markdown image validation off main
austinywang cd9d949
docs: require confirmation for note removal
austinywang 54e3745
fix(artifacts): adapt POSIX path checks to Xcode 26
austinywang 529858f
fix(artifacts): repair Swift 6 watcher and lease initialization
austinywang a42c0c8
fix(artifacts): own watcher tasks without task-group sends
austinywang b255996
fix(remote): release upload heartbeat lock after watchdog
austinywang 4be37c6
fix(artifacts): select safe fcntl overload in app targets
austinywang f8e6a2b
fix: repair artifact integration call sites
austinywang 8087525
fix(artifacts): repair preview and path helper calls
austinywang f4c0311
fix: expose remaining artifact integration seams
austinywang 66edb9a
fix: update artifact integration test call sites
austinywang 7e83bb8
Merge remote-tracking branch 'origin/main' into feat-cmux-artifacts
austinywang 592b6d1
fix: repair artifact tests and warning budget
austinywang df89792
Merge remote-tracking branch 'origin/main' into feat-cmux-artifacts
austinywang 5fcc99f
fix: close artifact CI integration gaps
austinywang 080ea26
fix: address final artifact review findings
austinywang 7a24277
fix: close artifact review regressions
austinywang aecf70e
fix: bound artifact staging and sidebar identity work
austinywang c3311c2
test: cover Iroh artifact ancestor swaps
austinywang dd6c4bc
test: cover artifact identity and empty-folder regressions
austinywang f29410b
fix: bind artifact reads to authorized filesystem identities
austinywang acd1f0d
merge: reconcile artifact branch with origin/main
austinywang 0213b1b
merge: sync latest origin/main
austinywang 6c4bbbc
fix: make artifact CI deterministic
austinywang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| struct ArtifactCLIArguments { | ||
| let subcommand: String | ||
| let operands: [String] | ||
| let projectPath: String? | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,286 @@ | ||
| import CmuxArtifacts | ||
| import Foundation | ||
|
|
||
| extension CMUXCLI { | ||
| func runArtifactCommand( | ||
| commandArgs: [String], | ||
| jsonOutput: Bool, | ||
| processEnvironment: [String: String] | ||
| ) async throws { | ||
| let parsed = try artifactArguments(commandArgs) | ||
| let projectRoot = artifactProjectRoot(explicitPath: parsed.projectPath) | ||
| let repository = LocalArtifactRepository() | ||
|
|
||
| do { | ||
| switch parsed.subcommand { | ||
| case "list": | ||
| guard parsed.operands.isEmpty else { | ||
| throw CLIError(message: artifactUsage(), exitCode: 2) | ||
| } | ||
| let snapshot = try await repository.snapshot(projectRoot: projectRoot) | ||
| let files = artifactFiles(in: snapshot.nodes) | ||
| if jsonOutput { | ||
| print(jsonString([ | ||
| "project_root": projectRoot.path, | ||
| "artifacts_root": snapshot.artifactsRoot.path, | ||
| "artifacts": files.map(artifactPayload), | ||
| ])) | ||
| } else if files.isEmpty { | ||
| print(String( | ||
| localized: "cli.artifact.output.empty", | ||
| defaultValue: "No artifacts found." | ||
| )) | ||
| } else { | ||
| files.forEach { print($0.relativePath) } | ||
| } | ||
|
|
||
| case "path": | ||
| let name = try artifactRequiredOperand(parsed.operands, subcommand: "path") | ||
| let node = try await repository.resolve(projectRoot: projectRoot, name: name) | ||
| if jsonOutput { | ||
| print(jsonString(artifactPayload(node))) | ||
| } else { | ||
| print(node.absolutePath) | ||
| } | ||
|
|
||
| case "open": | ||
| let name = try artifactRequiredOperand(parsed.operands, subcommand: "open") | ||
| let node = try await repository.resolve(projectRoot: projectRoot, name: name) | ||
| try openArtifact(node) | ||
| if jsonOutput { print(jsonString(artifactPayload(node))) } | ||
|
|
||
| case "add": | ||
| let rawPath = try artifactRequiredOperand(parsed.operands, subcommand: "add") | ||
| let sourceURL = artifactFileURL(rawPath) | ||
| let context = artifactCaptureContext( | ||
| projectRoot: projectRoot, | ||
| environment: processEnvironment | ||
| ) | ||
| let outcome = try await ArtifactCaptureService(store: repository).add( | ||
| sourceURL: sourceURL, | ||
| context: context | ||
| ) | ||
| guard let record = outcome.record else { | ||
| throw CLIError(message: String( | ||
| localized: "cli.artifact.error.addRejected", | ||
| defaultValue: "The artifact was not added." | ||
| )) | ||
| } | ||
| let absolutePath = ArtifactStorePaths(projectRoot: projectRoot).artifactsRoot | ||
| .appendingPathComponent(record.relativePath, isDirectory: false).path | ||
|
austinywang marked this conversation as resolved.
Resolved
|
||
| if jsonOutput { | ||
| print(jsonString([ | ||
| "path": absolutePath, | ||
| "relative_path": record.relativePath, | ||
| "digest": record.digest, | ||
| "result": artifactOutcomeName(outcome), | ||
| ])) | ||
| } else { | ||
| print(absolutePath) | ||
| } | ||
|
|
||
| case "search": | ||
| let query = try artifactRequiredOperand(parsed.operands, subcommand: "search") | ||
| let results = try await repository.search(projectRoot: projectRoot, query: query) | ||
| if jsonOutput { | ||
| print(jsonString([ | ||
| "query": query, | ||
| "results": results.map { result in | ||
| var payload = artifactPayload(result.node) | ||
| payload["matched_content"] = result.matchedContent | ||
| payload["snippet"] = result.snippet ?? NSNull() | ||
| return payload | ||
| }, | ||
| ])) | ||
| } else if results.isEmpty { | ||
| print(String( | ||
| localized: "cli.artifact.output.noMatches", | ||
| defaultValue: "No artifacts matched." | ||
| )) | ||
| } else { | ||
| for result in results { | ||
| if let snippet = result.snippet { | ||
| print("\(result.node.relativePath): \(snippet)") | ||
| } else { | ||
| print(result.node.relativePath) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| default: | ||
| throw CLIError(message: artifactUsage(), exitCode: 2) | ||
| } | ||
| } catch let error as ArtifactStoreError { | ||
| throw CLIError(message: artifactErrorMessage(error), exitCode: 2) | ||
| } | ||
| } | ||
|
|
||
| func artifactUsage() -> String { | ||
| String(localized: "cli.artifact.usage", defaultValue: """ | ||
| Usage: cmux artifact list [--project <path>] | ||
| cmux artifact path <name-or-relative-path> [--project <path>] | ||
| cmux artifact open <name-or-relative-path> [--project <path>] | ||
| cmux artifact add <path> [--project <path>] | ||
| cmux artifact search <query> [--project <path>] | ||
|
|
||
| Browse and add ordinary files under <project>/.cmux/artifacts. | ||
| Commands work without a running cmux app or socket. The project defaults | ||
| to the nearest ancestor containing .cmux or .git. | ||
| """) | ||
| } | ||
|
|
||
| private func artifactArguments(_ arguments: [String]) throws -> ArtifactCLIArguments { | ||
| var projectPath: String? | ||
| var remaining: [String] = [] | ||
| var index = 0 | ||
| var pastTerminator = false | ||
| while index < arguments.count { | ||
| let argument = arguments[index] | ||
| if pastTerminator { | ||
| remaining.append(argument) | ||
| index += 1 | ||
| continue | ||
| } | ||
| if argument == "--" { | ||
| pastTerminator = true | ||
| index += 1 | ||
| continue | ||
| } | ||
| if argument == "--project" { | ||
| guard index + 1 < arguments.count else { | ||
| throw CLIError(message: String( | ||
| localized: "cli.artifact.error.projectValue", | ||
| defaultValue: "artifact: --project requires a path" | ||
| ), exitCode: 2) | ||
| } | ||
| projectPath = arguments[index + 1] | ||
| index += 2 | ||
| } else if argument.hasPrefix("--project=") { | ||
| projectPath = String(argument.dropFirst("--project=".count)) | ||
| index += 1 | ||
| } else if argument.hasPrefix("-") { | ||
| throw CLIError(message: artifactUsage(), exitCode: 2) | ||
| } else { | ||
| remaining.append(argument) | ||
| index += 1 | ||
| } | ||
| } | ||
| if let projectPath, | ||
| projectPath.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | ||
| throw CLIError(message: String( | ||
| localized: "cli.artifact.error.projectValue", | ||
| defaultValue: "artifact: --project requires a path" | ||
| ), exitCode: 2) | ||
| } | ||
| return ArtifactCLIArguments( | ||
| subcommand: remaining.first?.lowercased() ?? "list", | ||
| operands: Array(remaining.dropFirst()), | ||
| projectPath: projectPath | ||
| ) | ||
| } | ||
|
|
||
| private func artifactProjectRoot(explicitPath: String?) -> URL { | ||
| let start = explicitPath.map(artifactFileURL) | ||
| ?? URL(fileURLWithPath: FileManager.default.currentDirectoryPath, isDirectory: true) | ||
| return ArtifactProjectLocator().projectRoot(startingAt: start, fileManager: .default) | ||
| } | ||
|
|
||
| private func artifactFileURL(_ rawPath: String) -> URL { | ||
| let expanded = NSString(string: rawPath).expandingTildeInPath | ||
| if expanded.hasPrefix("/") { | ||
| return URL(fileURLWithPath: expanded).standardizedFileURL | ||
| } | ||
| return URL( | ||
| fileURLWithPath: expanded, | ||
| relativeTo: URL(fileURLWithPath: FileManager.default.currentDirectoryPath, isDirectory: true) | ||
| ).standardizedFileURL | ||
| } | ||
|
|
||
| private func artifactRequiredOperand(_ operands: [String], subcommand: String) throws -> String { | ||
| let value = operands.joined(separator: " ").trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard !value.isEmpty else { | ||
| throw CLIError(message: String( | ||
| format: String( | ||
| localized: "cli.artifact.error.missingOperand", | ||
| defaultValue: "artifact %@ requires a value" | ||
| ), | ||
| subcommand | ||
| ), exitCode: 2) | ||
| } | ||
| return value | ||
| } | ||
|
|
||
| private func artifactCaptureContext( | ||
| projectRoot: URL, | ||
| environment: [String: String] | ||
| ) -> ArtifactCaptureContext { | ||
| let codexSession = environment["CMUX_CODEX_SESSION_ID"] | ||
| let claudeSession = environment["CMUX_CLAUDE_SESSION_ID"] | ||
| return ArtifactCaptureContext( | ||
| projectRoot: projectRoot, | ||
| workspaceID: environment["CMUX_WORKSPACE_ID"], | ||
| workspaceTitle: environment["CMUX_WORKSPACE_TITLE"], | ||
| sessionID: codexSession ?? claudeSession ?? environment["CMUX_AGENT_SESSION_ID"], | ||
| agentName: codexSession == nil ? (claudeSession == nil ? environment["CMUX_AGENT_NAME"] : "claude") : "codex" | ||
| ) | ||
| } | ||
|
|
||
| private func artifactFiles(in nodes: [ArtifactNode]) -> [ArtifactNode] { | ||
| nodes.flatMap { node in | ||
| node.isDirectory ? artifactFiles(in: node.children) : [node] | ||
| } | ||
| } | ||
|
|
||
| private func artifactPayload(_ node: ArtifactNode) -> [String: Any] { | ||
| [ | ||
| "name": node.name, | ||
| "relative_path": node.relativePath, | ||
| "path": node.absolutePath, | ||
| "kind": node.fileKind?.rawValue ?? "other", | ||
| "size": node.size ?? 0, | ||
| ] | ||
| } | ||
|
|
||
| private func artifactOutcomeName(_ outcome: ArtifactImportOutcome) -> String { | ||
| switch outcome { | ||
| case .copied: return "copied" | ||
| case .deduplicated: return "deduplicated" | ||
| case .alreadyStored: return "already_stored" | ||
| case .skipped: return "skipped" | ||
| } | ||
| } | ||
|
|
||
| private func openArtifact(_ node: ArtifactNode) throws { | ||
| let process = Process() | ||
| process.executableURL = URL(fileURLWithPath: "/usr/bin/open") | ||
| process.arguments = [node.absolutePath] | ||
| try process.run() | ||
| process.waitUntilExit() | ||
| guard process.terminationStatus == 0 else { | ||
| throw CLIError(message: String( | ||
| format: String( | ||
| localized: "cli.artifact.error.openFailed", | ||
| defaultValue: "Could not open artifact at %@" | ||
| ), | ||
| node.absolutePath | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| private func artifactErrorMessage(_ error: ArtifactStoreError) -> String { | ||
| switch error { | ||
| case .sourceNotRegularFile(let path): | ||
| return String(format: String(localized: "cli.artifact.error.notFile", defaultValue: "Not a regular file: %@"), path) | ||
| case .unsupportedExtension(let pathExtension): | ||
| return String(format: String(localized: "cli.artifact.error.unsupported", defaultValue: "Unsupported artifact extension: %@"), pathExtension) | ||
| case .fileTooLarge(let actual, let limit): | ||
| return String(format: String(localized: "cli.artifact.error.tooLarge", defaultValue: "Artifact is too large (%lld bytes; limit %lld)."), actual, limit) | ||
| case .artifactNotFound(let name): | ||
| return String(format: String(localized: "cli.artifact.error.notFound", defaultValue: "Artifact not found: %@"), name) | ||
| case .ambiguousArtifactName(let name, let matches): | ||
| return String(format: String(localized: "cli.artifact.error.ambiguous", defaultValue: "Artifact name '%@' is ambiguous: %@"), name, matches.joined(separator: ", ")) | ||
| case .pathOutsideStore(let path): | ||
| return String(format: String(localized: "cli.artifact.error.outsideStore", defaultValue: "Artifact path escaped the store: %@"), path) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Packages/Shared/CmuxAgentChat/Sources/CmuxAgentChat/Artifacts/ChatArtifactSaveResult.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import Foundation | ||
|
|
||
| /// Stable project-local location returned after saving a chat artifact. | ||
| public struct ChatArtifactSaveResult: Codable, Equatable, Sendable { | ||
| /// Absolute path to the persisted artifact on the Mac. | ||
| public let path: String | ||
| /// Path relative to the project's `.cmux/artifacts` directory. | ||
| public let relativePath: String | ||
| /// Prompt-ready project-relative reference. | ||
| public let reference: String | ||
|
|
||
| /// Creates the location returned for a persisted chat artifact. | ||
| /// | ||
| /// - Parameters: | ||
| /// - path: Absolute path to the persisted file on the Mac. | ||
| /// - relativePath: Path relative to the project's artifact root. | ||
| /// - reference: Prompt-ready project-relative reference. | ||
| public init(path: String, relativePath: String, reference: String) { | ||
| self.path = path | ||
| self.relativePath = relativePath | ||
| self.reference = reference | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.