Skip to content

Commit bcedc4e

Browse files
committed
"Initial release: code-hq v1.0.0
0 parents  commit bcedc4e

200 files changed

Lines changed: 178146 additions & 0 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.

.\out\windows-style.json

Lines changed: 602 additions & 0 deletions
Large diffs are not rendered by default.

.github/copilot-instructions.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copilot Instructions — TQL / EAV • Datalog • EQL-S • Graph
2+
3+
**What this is.** Schema-agnostic querying over JSON via an **EAV store**, a **Datalog evaluator**, and the **EQL-S** DSL. Exposed through a **TQL CLI**, optional **NL orchestrator**, and a **graph engine** for agentic workflows.
4+
5+
## Files you should know first
6+
- Store: `src/eav-engine.ts` — JSON → `attr(e,a,v)` facts, indexes (**EAV/AEV/AVE**), optional `link(e1,rel,e2)`.
7+
- Evaluator: `src/query/datalog-evaluator.ts` — semi-naive Datalog; attr/link/string/regex/numeric/date ops.
8+
- DSL/Compiler: `src/query/**` — parses EQL-S to evaluator IR.
9+
- CLI: `src/cli/tql.ts` — loads files/URLs → builds one store → runs EQL-S → prints table/json/csv.
10+
- Orchestrator: `src/ai/orchestrator.ts` — NL → EQL-S (used by `--nl`).
11+
- Agent graph runtime: `src/graph/**` — deterministic node/edge engine, budgets/timeouts, per-step traces, pluggable executors & tools.
12+
13+
## Conventions (don't fight these)
14+
- **Entity IDs:** `type:id` (e.g., `post:123`). Namespaces are distinct (`user:1``post:1`).
15+
- **Attributes:** JSON dot paths (`"address.city"`, `"reactions.likes"`). Arrays → multiple facts.
16+
- **Imports:** TypeScript bundler mode → always use **`.js`** in relative imports:
17+
```ts
18+
import { EAVStore } from '../eav-engine.js'
19+
import data from './seed.json' assert { type: 'json' }
20+
```
21+
- **Planner intent:** push filters before joins; prefer **AVE/link** indexes over scans/regex.
22+
23+
## Daily workflows
24+
- Type check: `bun run typecheck`
25+
- Demos: `bun run examples/eav-demo.ts` · `bun run examples/tql-demo.ts`
26+
- CLI help: `bun run tql --help`
27+
28+
## EQL-S quick patterns (copy/paste)
29+
```eql
30+
-- Basic
31+
FIND post AS ?p RETURN ?p
32+
33+
-- Project attributes (compiler injects attr goals)
34+
FIND post AS ?p RETURN ?p.id, ?p.title
35+
36+
-- Filtered
37+
FIND post AS ?p WHERE ?p.views > 1000 RETURN ?p.id, ?p.title ORDER BY ?p.views DESC LIMIT 10
38+
39+
-- Attribute join
40+
FIND post AS ?p, user AS ?u WHERE ?p.userId = ?u.id RETURN ?u.name, ?p.title
41+
42+
-- With links (if ingested)
43+
FIND post AS ?p, user AS ?u WHERE LINK(?p,"BY",?u) RETURN ?u.name, ?p.title
44+
45+
-- Anti-join
46+
FIND user AS ?u WHERE NOT EXISTS LINK(?p,"BY",?u) RETURN ?u.id, ?u.name
47+
```
48+
49+
## CLI examples
50+
```bash
51+
# Local file
52+
bun run tql -d data/posts.json -q "FIND post AS ?p WHERE ?p.title CONTAINS \"dolor\" RETURN ?p.id, ?p.title"
53+
54+
# Remote URL
55+
bun run tql -d https://jsonplaceholder.typicode.com/users -q "FIND user AS ?u RETURN ?u.id, ?u.email"
56+
57+
# Natural language (routes through orchestrator)
58+
bun run tql -d data/posts.json -q "show posts with >1000 views" --nl
59+
```
60+
61+
## Agent graph runtime (for LLM workflows)
62+
- Engine: `src/graph/engine.ts` yields **per-step traces** (async generator) and enforces **maxSteps/perNodeMs**.
63+
- Node kinds: `Agent` (LLM), `Tool` (function), `Router`, `Guard`, `MemoryRead/Write`, `End`.
64+
- Deterministic routing: edge labels unique per source node; validated in `validators.ts`.
65+
- Streaming/logging: subscribe to step events; emit structured traces for UIs/logs.
66+
- Handy tool: `tql_query` to run EQL-S against an in-memory store inside a graph flow.
67+
68+
## Project-specific gotchas
69+
- **Case matters for data**, not for keywords: keep `type`/attribute strings exactly as in the data (e.g., `post`, not `POST`).
70+
- Returning `?x.path` can **fan out** if multi-valued; the runner's projection policy controls this.
71+
- Always add `.js` in local TS imports; missing suffix breaks Bun/ts-bundler.
72+
- Arrays are not single entities: create one entity per element on ingest.
73+
74+
## When extending
75+
- New data → use `jsonEntityFacts(...)`, keep `type:id`, then query.
76+
- New predicate → register in evaluator (arity + handler) and keep recursion monotone.
77+
- Cross-entity joins → either `?a.fk = ?b.id` or synthesize `LINK` edges at ingest (faster and cleaner).

.github/prompts/plan.prompt.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
description: Execute the implementation planning workflow for TQL EAV Datalog Engine features using the plan template.
3+
---
4+
5+
Given the TQL feature implementation details provided as an argument, do this:
6+
7+
1. Run `.specify/scripts/bash/setup-plan.sh --json` from the repo root and parse JSON for FEATURE_SPEC, IMPL_PLAN, SPECS_DIR, BRANCH. All future file paths must be absolute.
8+
2. Read and analyze the feature specification to understand:
9+
- EAV engine requirements and query patterns
10+
- AI orchestration and natural language processing needs
11+
- Datalog evaluation and external predicate requirements
12+
- CLI integration and data ingestion patterns
13+
- Cross-domain compatibility and schema-agnostic features
14+
15+
3. Read the TQL constitution at `.specify/memory/constitution.md` to understand TQL-specific architectural principles.
16+
17+
4. Execute the TQL implementation plan template:
18+
- Load `.specify/templates/plan-template.md` (already copied to IMPL_PLAN path)
19+
- Set Input path to FEATURE_SPEC
20+
- Run the Execution Flow (main) function steps 1-9
21+
- Focus on TQL-specific patterns:
22+
* EAV fact generation and ingestion workflows
23+
* Query engine integration (Datalog + external predicates)
24+
* AI orchestrator integration for natural language processing
25+
* CLI tool extension patterns
26+
* Cross-component data flow validation
27+
- The template is self-contained and executable
28+
- Follow error handling and gate checks as specified
29+
- Let the template guide artifact generation in $SPECS_DIR:
30+
* Phase 0 generates research.md (focusing on EAV patterns and Datalog requirements)
31+
* Phase 1 generates data-model.md, contracts/, quickstart.md
32+
* Phase 2 generates tasks.md (with TQL development workflow)
33+
- Incorporate user-provided details from arguments into Technical Context: $ARGUMENTS
34+
- Update Progress Tracking as you complete each phase
35+
36+
5. Verify execution completed:
37+
- Check Progress Tracking shows all phases complete
38+
- Ensure all required artifacts were generated
39+
- Confirm no ERROR states in execution
40+
41+
6. Report results with branch name, file paths, and generated artifacts.
42+
43+
Use absolute paths with the repository root for all file operations to avoid path issues.

.github/prompts/specify.prompt.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
description: Create or update the TQL feature specification from a natural language feature description, focusing on EAV engine capabilities.
3+
---
4+
5+
Given the TQL feature description provided as an argument, do this:
6+
7+
1. Run the script `.specify/scripts/bash/create-new-feature.sh --json "$ARGUMENTS"` from repo root and parse its JSON output for BRANCH_NAME and SPEC_FILE. All file paths must be absolute.
8+
2. Load `.specify/templates/spec-template.md` to understand required sections for TQL features.
9+
3. Write the specification to SPEC_FILE using the template structure, focusing on TQL-specific aspects:
10+
- EAV data ingestion patterns and entity modeling
11+
- Query requirements (Datalog patterns, external predicates)
12+
- AI orchestration needs (natural language processing, intent analysis)
13+
- CLI integration and cross-domain compatibility
14+
- Performance considerations for in-memory triple store operations
15+
Replace placeholders with concrete details derived from the feature description while preserving section order and headings.
16+
4. Report completion with branch name, spec file path, and readiness for the TQL planning phase.
17+
18+
Note: The script creates and checks out the new branch and initializes the spec file before writing.

.github/prompts/tasks.prompt.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
description: Generate actionable, dependency-ordered tasks.md for TQL features based on EAV engine architecture and AI orchestration patterns.
3+
---
4+
5+
Given the TQL feature context provided as an argument, do this:
6+
7+
1. Run `.specify/scripts/bash/check-task-prerequisites.sh --json` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute.
8+
2. Load and analyze available design documents with TQL context:
9+
- Always read plan.md for EAV patterns, query engine integration, and AI orchestrator usage
10+
- IF EXISTS: Read data-model.md for entity schemas and fact generation patterns
11+
- IF EXISTS: Read contracts/ for API endpoints and external predicate definitions
12+
- IF EXISTS: Read research.md for Datalog evaluation and performance decisions
13+
- IF EXISTS: Read quickstart.md for cross-domain query scenarios
14+
15+
Note: TQL features may focus on different components:
16+
- EAV engine features might not need contracts/
17+
- Query engine features focus on datalog-evaluator.ts patterns
18+
- AI features emphasize orchestrator.ts integration
19+
- CLI features extend src/cli/tql.ts patterns
20+
21+
3. Generate TQL-specific tasks following the template:
22+
- Use `.specify/templates/tasks-template.md` as the base
23+
- Replace example tasks with TQL-appropriate tasks:
24+
* **Setup tasks**: Bun dependencies, TypeScript configuration, TQL build setup
25+
* **Test tasks [P]**: EAV fact ingestion tests, query evaluation tests, orchestrator tests
26+
* **Core tasks**: Entity fact generation, query pattern implementation, external predicates
27+
* **Integration tasks**: AI model integration, CLI command integration, cross-component data flow
28+
* **Polish tasks [P]**: Demo creation (examples/), performance benchmarks, documentation
29+
30+
4. TQL task generation rules:
31+
- Each EAV ingestion pattern → fact generation test task marked [P]
32+
- Each query pattern in data-model → query implementation task marked [P]
33+
- Each external predicate → predicate test and implementation (not parallel if shared evaluator)
34+
- Each AI orchestration scenario → integration test marked [P]
35+
- Each CLI command → command test and implementation
36+
- Different TQL components = can be parallel [P] (eav-engine.ts, query/, ai/)
37+
- Same file = sequential (no [P])
38+
39+
5. Order tasks by TQL architecture dependencies:
40+
- Setup before everything (Bun, TypeScript, dependencies)
41+
- EAV engine tests before query engine (fact generation foundation)
42+
- Query engine tests before AI orchestrator (query patterns foundation)
43+
- Core implementation before CLI integration
44+
- Component tests before cross-component integration
45+
- Everything before demos and polish
46+
47+
6. Include TQL-specific parallel execution examples:
48+
- Group [P] tasks for independent TQL components
49+
- Show examples using TQL demo patterns (bun run demo:eav, etc.)
50+
- Reference TQL CLI workflows (bun run tql commands)
51+
52+
7. Create FEATURE_DIR/tasks.md with:
53+
- Correct TQL feature name from implementation plan
54+
- TQL-specific task patterns and dependencies
55+
- Integration with existing TQL architecture (src/eav-engine.ts, src/query/, src/ai/, src/cli/)
56+
- Numbered tasks (T001, T002, etc.)
57+
- Clear file paths for each task
58+
- Dependency notes
59+
- Parallel execution guidance
60+
61+
Context for task generation: $ARGUMENTS
62+
63+
The tasks.md should be immediately executable - each task must be specific enough that an LLM can complete it without additional context.

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Bun
16+
uses: oven-sh/setup-bun@v2
17+
with:
18+
bun-version: stable
19+
20+
- name: Install deps
21+
run: bun install
22+
23+
- name: Typecheck
24+
run: bun run typecheck
25+
26+
- name: Run tests
27+
run: bun run test

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store
35+
.tql-cache

0 commit comments

Comments
 (0)