-
Notifications
You must be signed in to change notification settings - Fork 0
fix(observe,skills): gitignore the local state the CLI writes; make the Codex hook portable #178
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
671a9c7
fix(observe,skills): gitignore the local state the CLI writes; make t…
tonychang04 3dd7ea9
fix(observe): shell-neutral Codex hook that climbs to the insta root;…
tonychang04 38743c3
fix(observe): the hook records at the linked project root, derived fr…
tonychang04 8090064
fix(observe): report/sync anchor on the same root the hook writes to
tonychang04 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
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,43 @@ | ||
| // Shared `.gitignore` maintenance for files the CLI writes into a project that are not the | ||
| // developer's source (installed skills, observe-hook state). The rule: whatever writes a | ||
| // regenerable or machine-local file adds its ignore entry in the same step, so `git status` never | ||
| // surfaces it as a surprise — the same convention as `insta secrets` for .env. | ||
| import { spawnSync } from 'node:child_process' | ||
| import { existsSync, readFileSync, writeFileSync } from 'node:fs' | ||
| import { join } from 'node:path' | ||
|
|
||
| // Append any missing entries to the project's ./.gitignore (creating it if absent). Idempotent: | ||
| // entries already present (exact line match) are left alone; a block gets one `comment` header | ||
| // the first time it contributes. Returns the entries it added. | ||
| export function ensureGitignore(cwd: string, entries: string[], comment?: string): string[] { | ||
| const p = join(cwd, '.gitignore') | ||
| const existing = existsSync(p) ? readFileSync(p, 'utf8') : '' | ||
| const have = new Set(existing.split('\n').map((l) => l.trim())) | ||
| const missing = entries.filter((e) => !have.has(e)) | ||
| if (missing.length === 0) return [] | ||
| const prefix = existing && !existing.endsWith('\n') ? '\n' : '' | ||
| const header = comment && !have.has(comment) ? `${comment}\n` : '' | ||
| writeFileSync(p, existing + `${prefix}\n${header}${missing.join('\n')}\n`) | ||
| return missing | ||
| } | ||
|
|
||
| // An ignore entry does nothing for a path git already tracks — and the repos that most need these | ||
| // entries are the ones where the files were committed before the CLI ignored them. Returns the | ||
| // entries (as given) that have tracked files under them, so the caller can print the one hint | ||
| // that fixes it (`git rm -r --cached …`). Empty when git is absent or cwd is not a repo. | ||
| export function alreadyTracked(cwd: string, entries: string[]): string[] { | ||
| if (entries.length === 0) return [] | ||
| try { | ||
| const r = spawnSync('git', ['ls-files', '-z', '--', ...entries], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }) | ||
| if (r.status !== 0 || !r.stdout) return [] | ||
| const tracked = r.stdout.split('\0').filter(Boolean) | ||
| return entries.filter((e) => tracked.some((t) => t === e || t.startsWith(e.endsWith('/') ? e : `${e}/`))) | ||
| } catch { | ||
| return [] | ||
| } | ||
| } | ||
|
|
||
| /** The one-line hint for `alreadyTracked` hits, or null when there are none. */ | ||
| export function untrackHint(tracked: string[]): string | null { | ||
| return tracked.length ? ` already tracked by git — to stop committing: git rm -r --cached ${tracked.join(' ')}` : null | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: When a new file is created, the template adds a leading newline due to the computed prefix. The unconditional newline should be dropped so a fresh file starts at its comment line.
Proposed fix: remove the unconditional leading newline logic and only add a leading newline when there is existing content that requires separation.
Suggested change:
Example fix (conceptual):
Prompt for AI agents
const leading = existing ? '\n' : ''
const separator = existing && !existing.endsWith('\n') ? '\n' : ''
writeFileSync(p, existing +
${leading}${separator}${header}${missing.join('\n')}\n)