Repository navigation
Update built-in Pi hook integration #7008
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
Merged
austinywang
merged 19 commits into
main
from
issue-5555-update-built-in-pi-hook-integration-for-curre
Jun 29, 2026
Merged
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9ab6126
test: cover current Pi hook extension parity
ed3ae25
fix: update Pi hook extension parity
d98b75d
Merge remote-tracking branch 'origin/main' into issue-5555-update-bui…
86cdb55
fix: address Pi hook review findings
d46aeaa
fix: tighten Pi hook review fixes
d3b1d7f
fix: harden Pi hook environment allowlist
075626c
fix: address Pi hook review followups
de059cf
refactor: split Pi extension source
509ddec
fix: honor Pi hook disable flag
7156420
test: tighten Pi resume binding harness
3d5b7c1
Merge remote-tracking branch 'origin/main' into issue-5555-update-bui…
01f1d09
Merge remote-tracking branch 'origin/main' into issue-5555-update-bui…
8645846
chore: retrigger external checks
a3e46c3
Merge remote-tracking branch 'origin/main' into issue-5555-update-bui…
545e4f0
test: stabilize generic hook CLI expectations
4a2bbd7
fix: preserve Pi notification fallback
029659c
test: stabilize CLI socket harness
560fda2
Merge remote-tracking branch 'origin/main' into issue-5555-update-bui…
303f8c6
Merge remote-tracking branch 'origin/main' into issue-5555-update-bui…
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
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,114 @@ | ||
| import Foundation | ||
|
|
||
| extension CMUXCLI { | ||
| private static let piExtensionMarker = "cmux-pi-session-extension-marker" | ||
| private static let piExtensionFilename = "cmux-session.ts" | ||
|
|
||
| private func piExtensionURL(for def: AgentHookDef) -> URL { | ||
| URL(fileURLWithPath: def.resolvedConfigDir(), isDirectory: true) | ||
| .appendingPathComponent("extensions", isDirectory: true) | ||
| .appendingPathComponent(Self.piExtensionFilename, isDirectory: false) | ||
| } | ||
|
|
||
| private func existingPiExtensionContents(at url: URL, fileManager: FileManager = .default) throws -> String { | ||
| guard fileManager.fileExists(atPath: url.path) else { return "" } | ||
| do { | ||
| return try String(contentsOf: url, encoding: .utf8) | ||
| } catch { | ||
| let message = String.localizedStringWithFormat( | ||
| String( | ||
| localized: "cli.hooks.pi.error.readFailed", | ||
| defaultValue: "Failed to read %@" | ||
| ), | ||
| url.path | ||
| ) | ||
| throw CLIError(message: message) | ||
| } | ||
| } | ||
|
|
||
| func installPiExtensionHooks(_ def: AgentHookDef) throws { | ||
| let extensionURL = piExtensionURL(for: def) | ||
| let fileManager = FileManager.default | ||
|
austinywang marked this conversation as resolved.
Resolved
|
||
| let skipConfirm = ProcessInfo.processInfo.arguments.contains("--yes") | ||
| || ProcessInfo.processInfo.arguments.contains("-y") | ||
| let existing = try existingPiExtensionContents(at: extensionURL, fileManager: fileManager) | ||
| if existing == Self.piExtensionSource { | ||
| print(String.localizedStringWithFormat( | ||
| String( | ||
| localized: "cli.hooks.pi.alreadyUpToDate", | ||
| defaultValue: "Pi hooks already up to date at %@" | ||
| ), | ||
| extensionURL.path | ||
| )) | ||
| return | ||
| } | ||
| if !existing.isEmpty, !existing.contains(Self.piExtensionMarker) { | ||
| throw CLIError(message: String.localizedStringWithFormat( | ||
| String( | ||
| localized: "cli.hooks.pi.error.notCmuxExtension", | ||
| defaultValue: "%@ exists and is not a cmux extension; leaving it alone" | ||
| ), | ||
| extensionURL.path | ||
| )) | ||
|
austinywang marked this conversation as resolved.
Resolved
|
||
| } | ||
| if !skipConfirm { | ||
| Self.printInstallPreview( | ||
| path: extensionURL.path, | ||
| oldContent: existing, | ||
| newContent: Self.piExtensionSource, | ||
| fallbackContent: Self.piExtensionSource | ||
| ) | ||
| print(String(localized: "cli.hooks.pi.confirmProceed", defaultValue: "\nProceed? [y/N] "), terminator: "") | ||
| guard readLine()?.lowercased().hasPrefix("y") == true else { | ||
| print(String(localized: "cli.hooks.pi.aborted", defaultValue: "Aborted.")) | ||
| return | ||
| } | ||
| } | ||
| try fileManager.createDirectory( | ||
| at: extensionURL.deletingLastPathComponent(), | ||
| withIntermediateDirectories: true | ||
| ) | ||
| try Self.piExtensionSource.write(to: extensionURL, atomically: true, encoding: .utf8) | ||
| print(String.localizedStringWithFormat( | ||
| String( | ||
| localized: "cli.hooks.pi.installed", | ||
| defaultValue: "Pi hooks installed at %@" | ||
| ), | ||
| extensionURL.path | ||
| )) | ||
| } | ||
|
|
||
| func uninstallPiExtensionHooks(_ def: AgentHookDef) throws { | ||
| let extensionURL = piExtensionURL(for: def) | ||
| let fm = FileManager.default | ||
| guard fm.fileExists(atPath: extensionURL.path) else { | ||
| print(String.localizedStringWithFormat( | ||
| String( | ||
| localized: "cli.hooks.pi.noneFound", | ||
| defaultValue: "No Pi cmux extension found at %@" | ||
| ), | ||
| extensionURL.path | ||
| )) | ||
| return | ||
| } | ||
| let existing = try existingPiExtensionContents(at: extensionURL, fileManager: fm) | ||
| guard existing.contains(Self.piExtensionMarker) else { | ||
| print(String.localizedStringWithFormat( | ||
| String( | ||
| localized: "cli.hooks.pi.refuseRemoveMissingMarker", | ||
| defaultValue: "Refusing to remove %@: missing cmux marker" | ||
| ), | ||
| extensionURL.path | ||
| )) | ||
| return | ||
| } | ||
| try fm.removeItem(at: extensionURL) | ||
| print(String.localizedStringWithFormat( | ||
| String( | ||
| localized: "cli.hooks.pi.removed", | ||
| defaultValue: "Removed Pi cmux extension from %@" | ||
| ), | ||
| extensionURL.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| extension CMUXCLI { | ||
| static let piExtensionSource = piExtensionSourcePart1 + "\n" + piExtensionSourcePart2 | ||
| } |
Oops, something went wrong.
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.