Skip to content

Commit a677edf

Browse files
committed
refactor: consolidate constants, add documentation, and create tests
Config consolidation: - Rename constants for consistency (DirContext, DirArchive, etc.) - Add update type constants (UpdateTypeTask, UpdateTypeDecision, etc.) - Add WatchAutoSaveInterval constant - Use filepath.Join for all path construction Documentation: - Add godoc comments with Parameters/Returns/Fields sections - Add copyright headers to all watch package files - Add package doc comment to watch package Tests: - Add watch_test.go with tests for applyUpdate, complete, stream, session - Add colocated tests for add, agent, compact, complete, drift, hook, initialize, load, loop, session, status, sync, task, validation packages - Slim cli_test.go to only keep TestBinaryIntegration Code improvements: - Use config constants instead of literal strings throughout codebase - Fix block-non-path-ctx.sh regex to not overfit on paths containing "ctx" - Rename init package to initialize (canonical Go naming) Signed-off-by: Jose Alekhinne <alekhinejose@gmail.com>
1 parent db14e02 commit a677edf

127 files changed

Lines changed: 9644 additions & 5291 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/hooks/auto-save-session.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ PROJECT_DIR=$(echo "$HOOK_INPUT" | jq -r '.cwd // "."')
3535

3636
# Only proceed if we have a transcript path
3737
if [ -z "$TRANSCRIPT_PATH" ] || [ ! -f "$TRANSCRIPT_PATH" ]; then
38-
exit 0
38+
exit 0
3939
fi
4040

4141
# Create sessions directory if it doesn't exist

.claude/hooks/block-non-path-ctx.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,38 @@ COMMAND=$(echo "$HOOK_INPUT" | jq -r '.tool_input.command // empty')
2525

2626
# If no command, allow (not a Bash call we care about)
2727
if [ -z "$COMMAND" ]; then
28-
exit 0
28+
exit 0
2929
fi
3030

3131
# Check for forbidden patterns
3232
BLOCKED_REASON=""
3333

3434
# Pattern 1: ./ctx or ./dist/ctx or ./dist/ctx-*
3535
if echo "$COMMAND" | grep -qE '(\./ctx|\./dist/ctx)'; then
36-
BLOCKED_REASON="Use 'ctx' from PATH, not './ctx' or './dist/ctx'. Install with: sudo make install"
36+
BLOCKED_REASON="Use 'ctx' from PATH, not './ctx' or './dist/ctx'. Install with: sudo make install"
3737
fi
3838

3939
# Pattern 2: go run ./cmd/ctx
4040
if echo "$COMMAND" | grep -qE 'go run \./cmd/ctx'; then
41-
BLOCKED_REASON="Use 'ctx' from PATH, not 'go run ./cmd/ctx'. Install with: sudo make install"
41+
BLOCKED_REASON="Use 'ctx' from PATH, not 'go run ./cmd/ctx'. Install with: sudo make install"
4242
fi
4343

4444
# Pattern 3: Absolute paths to ctx binary (but not just 'ctx' or paths in /usr/local/bin, /usr/bin)
45-
# Match things like /home/user/project/ctx or /tmp/ctx-test but allow /usr/local/bin/ctx
46-
if echo "$COMMAND" | grep -qE '(/home/|/tmp/|/var/)[^ ]*ctx[^ ]* '; then
47-
# Exception: allow /tmp/ctx-test for integration tests
48-
if ! echo "$COMMAND" | grep -qE '/tmp/ctx-test'; then
49-
BLOCKED_REASON="Use 'ctx' from PATH, not absolute paths. Install with: sudo make install"
50-
fi
45+
# Match things like /home/user/project/ctx or /tmp/ctx but allow /usr/local/bin/ctx
46+
# Only match when ctx is the binary (end of path), not a directory in the middle of a path
47+
if echo "$COMMAND" | grep -qE '(/home/|/tmp/|/var/)[^ ]*/ctx( |$)'; then
48+
# Exception: allow /tmp/ctx-test for integration tests
49+
if ! echo "$COMMAND" | grep -qE '/tmp/ctx-test'; then
50+
BLOCKED_REASON="Use 'ctx' from PATH, not absolute paths. Install with: sudo make install"
51+
fi
5152
fi
5253

5354
# If blocked, output JSON that tells Claude Code to reject
5455
if [ -n "$BLOCKED_REASON" ]; then
55-
cat << EOF
56+
cat << EOF
5657
{"decision": "block", "reason": "$BLOCKED_REASON\n\nSee CONSTITUTION.md: ctx Invocation Invariants"}
5758
EOF
58-
exit 0
59+
exit 0
5960
fi
6061

6162
# Allow the command

.context/TASKS.md

Lines changed: 115 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,128 @@
11
# Tasks — Context CLI
22

3-
## In Progress
3+
# Tasks
44

5-
## Phase 1
5+
### Phase 1: Parser
66

7-
- [ ] Verify all Markdown files by "actually reading them"; take notes for
8-
follow-up actions.
9-
- [ ] All go code should have godoc and testing.
10-
- [ ] GitHub CI linter is giving errors that need fixing.
11-
- [ ] Manual code review. take notes.
12-
- [ ] Add tests per file.
13-
- [ ] validate everything in the docs with a skeptical eye.
14-
- [ ] consider the case where `ctx` is not called from within AI prompt:
15-
- does the command still make sense?
16-
- does it create the expected output?
17-
- [ ] Cut the first release.
7+
- [ ] T1.1.1: Define data structures in `internal/recall/parser/types.go`
8+
- `SessionMessage`, `Session`, `ContentBlock` interface
9+
- `TextBlock`, `ThinkingBlock`, `ToolUseBlock`, `ToolResultBlock`
10+
- `TokenUsage` struct
11+
- Must match `specs/recall/v0.1.0/01-session-schema.md`
12+
13+
- [ ] T1.1.2: Implement line parser in `internal/recall/parser/parser.go`
14+
- `ParseLine(line []byte) (*SessionMessage, error)`
15+
- Handle malformed JSON (return error, don't panic)
16+
- Handle missing optional fields with defaults
17+
18+
- [ ] T1.1.3: Implement session grouper
19+
- `ParseFile(path string) (map[string]*Session, error)`
20+
- Stream lines, don't load entire file into memory
21+
- Sort messages by timestamp within each session
22+
- Calculate: TurnCount, TotalTokensIn, TotalTokensOut, Duration
23+
24+
- [ ] T1.1.4: Implement directory scanner
25+
- `ScanDirectory(path string) ([]*Session, error)`
26+
- Recurse into subdirectories
27+
- Skip non-JSONL files
28+
- Aggregate sessions across files
29+
30+
### Phase 2: Renderer
31+
32+
- [ ] T1.2.1: Set up template system in `internal/recall/renderer/`
33+
- Use `//go:embed` for templates
34+
- Create `templates/layout.html` with dark mode CSS
35+
- Create `templates/index.html`
36+
- Create `templates/session.html`
37+
38+
- [ ] T1.2.2: Implement markdown renderer
39+
- Add goldmark + chroma dependencies
40+
- `RenderMarkdown(text string) template.HTML`
41+
- Enable GFM extensions
42+
- Syntax highlighting with monokai theme
43+
44+
- [ ] T1.2.3: Implement session renderer
45+
- `RenderSession(session *Session) (*RenderedSession, error)`
46+
- Wrap thinking blocks in `<details>` (collapsed by default)
47+
- Format tool calls with syntax-highlighted input/output
1848

49+
- [ ] T1.2.4: Implement index renderer
50+
- `RenderIndex(sessions []*Session, filters Filters) (*RenderedIndex, error)`
51+
- Sort by date (newest first)
52+
- Include preview (first 100 chars of first user message)
53+
- Show aggregate stats
1954

20-
## Next Up
55+
### Phase 3: Server
2156

22-
- [ ] Enforce test coverage targets in CI/Makefile #priority:medium #area:quality
23-
- internal/cli: 60% (currently 62.8%)
24-
- internal/context: 80% (currently 86.8%)
25-
- internal/drift: 80% (currently 88.0%)
26-
- internal/claude: 80% (currently 87.5%)
27-
- internal/templates: 80% (currently 88.9%)
57+
- [ ] T1.3.1: Set up HTTP server in `internal/recall/server/`
58+
- Standard library `net/http`
59+
- Graceful shutdown on SIGINT/SIGTERM
60+
- Embed static assets with `//go:embed`
2861

29-
## Completed (Recent)
62+
- [ ] T1.3.2: Implement index route
63+
- `GET /` — render index page
64+
- `GET /?project=X` — filter by project
65+
- `GET /?after=DATE&before=DATE` — filter by date
66+
- `GET /?q=QUERY` — search sessions
3067

31-
## Blocked
68+
- [ ] T1.3.3: Implement session detail route
69+
- `GET /session/:id` — render session detail
70+
- 404 if not found
71+
- Include back link to index
3272

33-
## Reference
73+
- [ ] T1.3.4: Implement API routes
74+
- `GET /api/sessions` — JSON session list
75+
- `GET /api/session/:id` — JSON session detail
3476

35-
**Specs** (in `specs/` directory):
36-
- `core-architecture.md` — Overall design philosophy
37-
- `go-cli-implementation.md` — Go project structure and patterns
38-
- `cli.md` — All CLI commands and their behavior
39-
- `context-file-formats.md` — File format specifications
40-
- `context-loader.md` — Loading and parsing logic
41-
- `context-updater.md` — Update command handling
77+
### Phase 4: Search
4278

43-
**Task Status Labels**:
44-
- `[ ]` — pending
45-
- `[x]` — completed
46-
- `[-]` — skipped (with reason)
47-
- `#in-progress` — currently being worked on (add inline, don't move task)
79+
- [ ] T1.4.1: Implement search index in `internal/recall/search/`
80+
- Inverted index: term → sessionIds
81+
- `Build(sessions []*Session)`
82+
- Tokenize: lowercase, split whitespace, remove punctuation
83+
84+
- [ ] T1.4.2: Implement search query
85+
- `Search(query string, limit int) []string`
86+
- AND semantics (all terms must match)
87+
- Sort by term frequency score
88+
89+
### Phase 5: CLI
90+
91+
- [ ] T1.5.1: Add recall subcommand
92+
- Create `cmd/ctx/recall.go`
93+
- `ctx recall serve <path>` — start server
94+
- `--port` flag (default: 8080)
95+
- `--open` flag to open browser
96+
97+
- [ ] T1.5.2: Add help and validation
98+
- Validate path exists and has JSONL files
99+
- Print URL when server starts
100+
- Print stats (sessions loaded, time taken)
101+
102+
## Backlog
103+
104+
- [x] Rename vars in the config package.
105+
- [x] Why is agent runbook lowest in reading priority order?
106+
- follow-up: is it enforced?
107+
- [x] Create a list of what CLI options (if any) are not implemented yet.
108+
- [ ] Verify all Markdown files by "actually reading them"; take notes for
109+
follow-up actions.
110+
- [x] All go code should have godoc and testing.
111+
- [ ] GitHub CI linter is giving errors that need fixing.
112+
- [x] Manual code review. take notes.
113+
- [x] Add tests per file.
114+
- [ ] validate everything in the docs with a skeptical eye.
115+
- [x] consider the case where `ctx` is not called from within AI prompt:
116+
- does the command still make sense?
117+
- does it create the expected output?
118+
- [ ] Cut the first release.
119+
- Versioning strategy.
120+
- Always have a `latest` tag pointing to the latest release.
121+
- Or, maybe just use the `latest` tag at all times?
122+
- [ ] have a proper email for security vulnerability reports.
123+
- [ ] compare versions of recent change and the last AI-assisted version and
124+
ask AI what we have learned about this.
125+
- [ ] CREATE SHORTS and VODS
126+
- [ ] Trace the entire git history and sessions, create an extensive document
127+
of what we did and how it progressed, and then create a blog post about it.
48128

49-
**Archives**: See `.context/archive/` for completed tasks from previous phases.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## In Progress
2+
3+
## Phase 1
4+
5+
- [ ] Add a `--no-integrations` or `--skip-integrations` or `--skip-hooks` or
6+
`--no-hooks` flag to `ctx init` so standalone
7+
users can skip the Claude Code (and other possible future)
8+
integration setup.
9+
10+
## Phase 2
11+
12+
- [ ] Enforce test coverage targets in CI/Makefile #priority:medium #area:quality
13+
- internal/cli: 60% (currently 62.8%)
14+
- internal/context: 80% (currently 86.8%)
15+
- internal/drift: 80% (currently 88.0%)
16+
- internal/claude: 80% (currently 87.5%)
17+
- internal/templates: 80% (currently 88.9%)
18+
19+
## Completed (Recent)
20+
21+
## Blocked
22+
23+
## Reference
24+
25+
**Specs** (in `specs/` directory):
26+
- `core-architecture.md` — Overall design philosophy
27+
- `go-cli-implementation.md` — Go project structure and patterns
28+
- `cli.md` — All CLI commands and their behavior
29+
- `context-file-formats.md` — File format specifications
30+
- `context-loader.md` — Loading and parsing logic
31+
- `context-updater.md` — Update command handling
32+
33+
**Task Status Labels**:
34+
- `[ ]` — pending
35+
- `[x]` — completed
36+
- `[-]` — skipped (with reason)
37+
- `#in-progress` — currently being worked on (add inline, don't move task)
38+
39+
**Archives**: See `.context/archive/` for completed tasks from previous phases.

0 commit comments

Comments
 (0)