Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def run_git(repo, args, capture=False, check=False):
result = subprocess.run(
["git", "-C", repo] + args,
text=True,
encoding='utf-8',
capture_output=capture,
check=check
)
Expand Down Expand Up @@ -134,7 +135,7 @@ def main():
# -------------------------------
# CONFIG FILE
# -------------------------------
with open(tracy_dir / "config", "w") as f:
with open(tracy_dir / "config", "w", encoding='utf-8') as f:
f.write(f"TRACY_SNAPSHOT_SCRIPT={script_source.as_posix()}\n")

# -------------------------------
Expand Down
22 changes: 15 additions & 7 deletions opencode-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const MyPlugin: Plugin = async (input: PluginInput) => {
async function getRepoRoot(): Promise<string | null> {
try {
const result = await $`git rev-parse --show-toplevel`.cwd(directory).quiet()
return String(result.stdout).trim() as string
return Buffer.from(result.stdout).toString('utf8').trim() as string
} catch {
return null
}
Expand All @@ -42,7 +42,15 @@ export const MyPlugin: Plugin = async (input: PluginInput) => {
if (!(await configFile.exists())) return

// cannot use dotenv, so enjoy this handrolled env parsing
const text = await configFile.text();
// Try UTF-8 first; fall back to windows-1252 for config files written
// before the utf-8 fix was applied to init.py (Windows default encoding).
const bytes = await configFile.bytes()
let text: string
try {
text = new TextDecoder('utf-8', { fatal: true }).decode(bytes)
} catch {
text = new TextDecoder('windows-1252').decode(bytes)
}
// Remove UTF-8 BOM (safeguard for cross-platform edge cases)
const cleanedText = text.replace(/^\uFEFF/, '');

Expand Down Expand Up @@ -78,11 +86,11 @@ export const MyPlugin: Plugin = async (input: PluginInput) => {
await L.info("Plugin initialized", { repoRoot, tracyPath })

let pythonCmd;
if ((await $`python3 --version`.quiet()).exitCode === 0) {
if ((await $`python3 --version`.quiet().nothrow()).exitCode === 0) {
pythonCmd = 'python3'
await L.info("Detected python command: python3")
} else {
if ((await $`python --version`.quiet()).exitCode === 0) {
if ((await $`python --version`.quiet().nothrow()).exitCode === 0) {
pythonCmd = 'python'
await L.info("Detected python command: python")
} else {
Expand Down Expand Up @@ -279,15 +287,15 @@ export const MyPlugin: Plugin = async (input: PluginInput) => {

if (result.exitCode !== 0) {
await L.error("Python failed", {
stdout: result.stdout.toString(),
stderr: result.stderr.toString(),
stdout: Buffer.from(result.stdout).toString('utf8'),
stderr: Buffer.from(result.stderr).toString('utf8'),
exitCode: result.exitCode
})
return
}

await L.info(
`created user snapshot for ${path}. tracy.py: ${result.stdout.toString().trim()}`
`created user snapshot for ${path}. tracy.py: ${Buffer.from(result.stdout).toString('utf8').trim()}`
)
})()

Expand Down
3 changes: 2 additions & 1 deletion tracking/hooks/post-commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def run_git(args, capture=False, check=False, env=None):
result = subprocess.run(
["git"] + args,
text=True,
encoding='utf-8',
stdout=subprocess.PIPE if capture else None,
stderr=subprocess.DEVNULL,
check=check,
Expand Down Expand Up @@ -138,7 +139,7 @@ def build_filtered_chain(local_ref, origin_commit, files_in_commit):
if commit_desc:
cmd += ["-m", commit_desc]

result = subprocess.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=commit_env)
result = subprocess.run(cmd, text=True, encoding='utf-8', stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=commit_env)
new_commit = result.stdout.strip()

if not new_commit:
Expand Down
1 change: 1 addition & 0 deletions tracking/hooks/post-fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def run_git(args, capture=False, check=False):
result = subprocess.run(
["git"] + args,
text=True,
encoding='utf-8',
stdout=subprocess.PIPE if capture else None,
stderr=subprocess.DEVNULL,
check=check
Expand Down
1 change: 1 addition & 0 deletions tracking/hooks/post-merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def run_git(args, capture=False):
result = subprocess.run(
["git"] + args,
text=True,
encoding='utf-8',
stdout=subprocess.PIPE if capture else None,
stderr=subprocess.DEVNULL,
)
Expand Down
3 changes: 2 additions & 1 deletion tracking/hooks/post-rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def run_git(args, capture=False, check=False, env=None):
result = subprocess.run(
["git"] + args,
text=True,
encoding='utf-8',
stdout=subprocess.PIPE if capture else None,
stderr=subprocess.DEVNULL,
check=check,
Expand Down Expand Up @@ -134,7 +135,7 @@ def build_chain_from_commits(commits_list, origin_commit):
cmd.extend(["-p", parent])
cmd.extend(["-m", msg])

result = subprocess.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=env)
result = subprocess.run(cmd, text=True, encoding='utf-8', stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=env)
new_commit = (result.stdout or "").strip()

if new_commit:
Expand Down
1 change: 1 addition & 0 deletions tracking/hooks/pre-push.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def run_git(args, capture=False, check=False):
result = subprocess.run(
["git"] + args,
text=True,
encoding='utf-8',
stdout=subprocess.PIPE if capture else None,
stderr=subprocess.DEVNULL,
check=check
Expand Down
1 change: 1 addition & 0 deletions tracking/hooks/reference-transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def run_git(args, capture=False):
result = subprocess.run(
["git"] + args,
text=True,
encoding='utf-8',
stdout=subprocess.PIPE if capture else None,
stderr=subprocess.DEVNULL,
)
Expand Down
3 changes: 2 additions & 1 deletion tracking/tracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def run_git(args, capture_output=False, check=False, cwd=None):
result = subprocess.run(
["git"] + args,
text=True,
encoding='utf-8',
stdout=subprocess.PIPE if capture_output else None,
stderr=subprocess.DEVNULL,
check=check,
Expand Down Expand Up @@ -206,7 +207,7 @@ def run_git(args, capture_output=False, check=False, cwd=None):
if DESCRIPTION:
commit_cmd += ["-m", DESCRIPTION]

result = subprocess.run(commit_cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=env)
result = subprocess.run(commit_cmd, text=True, encoding='utf-8', stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=env)
COMMIT = result.stdout.strip()

if not COMMIT:
Expand Down
Loading