Skip to content

Commit 9abbc33

Browse files
committed
feat: add workspace initialization and agent instructions
- Implemented initWorkspace function to set up a new workspace. - Created renderInitSummary function to summarize initialization results. - Added agent instructions in markdown format to guide usage of Contextful. - Included next steps for users after workspace initialization.
1 parent e749249 commit 9abbc33

6 files changed

Lines changed: 138 additions & 14 deletions

File tree

README.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
![contextful cover image](docs/cover.svg)
22

3-
# contextful
3+
# *Contextful*
44

5-
**Most-efficient Context Management Layer for Agentic AI.**
5+
**Context Management + Search Engine for Agentic AI.**
6+
7+
Contextful is a runtime contextual layer & local search engine for agents that gives them one fast way to find, compress, cite, and remember project context.
8+
9+
Available as a `cli` + MCP & Skill, it integrates seemlessly with Codex, Claude Code, Cursor, Windsurf, GitHub Copilot, VS Code, Cline, Roo Code, Continue, and Zed.
10+
11+
<img src="docs/supported.png" alt="Contextful screenshot" width="450px" style="border-radius: 20px;" />
612

7-
Contextful is a runtime contextual layer agents need for real projects. Available as an MCP, it integrates with Codex, Claude Code, Cursor, Windsurf, GitHub Copilot, VS Code, Cline, Roo Code, Continue, and Zed, then gives agents one fast way to find, compress, cite, and remember project context.
813

914
Instead of making an agent read 40 files every session, Contextful indexes the project once and returns a ranked, cited, token-budgeted **context pack**.
1015

11-
## Why Agents Need This
16+
## Why?
17+
18+
Context has always been a bottleneck for agentic AI. Large context window models (eg. 1m tokens) are :
19+
1. Expensive and require significantly more compute & processing time.
20+
2. Halucinate & loose key information as context window fills up.
21+
3. Most projects have millions of lines of code, but agents can only fit in limited tokens per context window.
22+
23+
The current solution is to make the agent guess which files to read, then pay the token cost to read them every session. This is slow, expensive, and lossy.
1224

25+
Apart from this, agents have no way to store or share learnings across sessions. Every time they start, they forget everything and have to re-read the same context again.
26+
27+
<img src="docs/context-window.png" alt="Contextful screenshot" width="450px" style="border-radius: 20px;" />
28+
29+
I started developing Contextful to keep context window smaller by enabling efficient knowledge retrieval. We can index the project and return a ranked, cited, token-budgeted context pack, we can:
1330
- **100x more efficient token usage:** stop paying tokens to re-read the same files.
1431
- **Fewer tool calls:** one context pack can replace dozens of grep, glob, and read-file calls.
1532
- **No lost context between sessions:** agents can store session learnings in an evidence-backed memory ledger.
1633
- **Shareable project knowledge:** lessons and context packs survive context compaction and future sessions.
1734

18-
## Core
35+
## Key Features
1936

20-
### Search Engine
21-
22-
Contextful analyzes the query, classifies intent, and combines lexical search, symbols, docs, graph relationships, and memory hits to retrieve the right evidence. The goal is Google-level project search for agents: vague queries like "resources for auth onboarding" should still land on the right code, docs, and prior lessons.
23-
24-
### Efficient Context Storage
37+
### 1. Context Management
2538

2639
The default local store is SQLite with FTS-backed search and typed graph tables. V1 ships with:
2740

@@ -33,11 +46,20 @@ The default local store is SQLite with FTS-backed search and typed graph tables.
3346

3447
The next storage upgrades are optional semantic vectors through sqlite-vec, LanceDB, or local HNSW, and compressed adjacency lists with Roaring bitmaps or CSR arrays for larger repositories.
3548

36-
### Memory Ledger
49+
50+
### 2. Search Engine
51+
52+
<img src="docs/grep-vs-vector.png" alt="Contextful screenshot" width="450px" style="border-radius: 20px;" />
53+
54+
Contextful analyzes the query, classifies intent, and combines lexical search, symbols, docs, graph relationships, and memory hits to retrieve the right evidence. The goal is Google-level project search for agents: vague queries like "resources for auth onboarding" should still land on the right code, docs, and prior lessons.
55+
56+
57+
58+
### 3. Memory Ledger
3759

3860
Agents can store lessons, decisions, and useful project facts, but not as loose "remember this" notes. Every memory requires evidence refs from files, symbols, commits, or prior context packs. When the evidence changes, Contextful marks the memory stale.
3961

40-
### Runtime Architecture
62+
### 4. Contextful Execution
4163

4264
Contextful is an MCP server, local indexer, and small CLI:
4365

docs/context-window.png

101 KB
Loading

docs/cover.svg

Lines changed: 1 addition & 2 deletions
Loading

docs/grep-vs-vector.png

1.37 MB
Loading

docs/supported.png

937 KB
Loading

src/init.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import { indexWorkspace } from "./indexer.js";
4+
import { type IndexResult } from "./types.js";
5+
import { relativePath, resolveWorkspace, stateDirFor } from "./util.js";
6+
7+
export interface InitResult {
8+
workspace: string;
9+
stateDir: string;
10+
instructionsPath: string;
11+
index: IndexResult;
12+
nextSteps: string[];
13+
}
14+
15+
export async function initWorkspace(options: { workspace?: string }): Promise<InitResult> {
16+
const workspace = resolveWorkspace(options.workspace);
17+
const index = await indexWorkspace({ workspace });
18+
const stateDir = stateDirFor(workspace);
19+
const instructionsPath = path.join(stateDir, "AGENT_INSTRUCTIONS.md");
20+
fs.writeFileSync(instructionsPath, renderAgentInstructions(workspace), "utf8");
21+
22+
return {
23+
workspace,
24+
stateDir,
25+
instructionsPath,
26+
index,
27+
nextSteps: [
28+
'Run `cxf search "where is auth handled?" --workspace .` to test retrieval.',
29+
"Add `npx -y @inferensys/contextful server` to your MCP client config.",
30+
"Tell the agent to call `context_pack` before broad file reads."
31+
]
32+
};
33+
}
34+
35+
export function renderInitSummary(result: InitResult): string {
36+
const instructions = relativePath(result.workspace, result.instructionsPath);
37+
return [
38+
"Contextful initialized",
39+
"",
40+
`Workspace: ${result.workspace}`,
41+
`State: ${relativePath(result.workspace, result.stateDir)}`,
42+
`Agent instructions: ${instructions}`,
43+
`Indexed files: ${result.index.indexedFiles}`,
44+
`Chunks: ${result.index.chunks}`,
45+
`Symbols: ${result.index.symbols}`,
46+
`Graph edges: ${result.index.edges}`,
47+
"",
48+
"Next steps:",
49+
...result.nextSteps.map((step) => `- ${step}`),
50+
""
51+
].join("\n");
52+
}
53+
54+
function renderAgentInstructions(workspace: string): string {
55+
return `# Contextful Agent Instructions
56+
57+
Workspace: ${workspace}
58+
59+
Use Contextful as the first retrieval layer for this project. The goal is to avoid broad file-reading loops and return cited, token-budgeted evidence before making code changes.
60+
61+
## Default Rule
62+
63+
Before running broad grep/glob/read-file exploration, call:
64+
65+
\`\`\`text
66+
context_pack(query, budget, scope)
67+
\`\`\`
68+
69+
Use a budget between 800 and 3000 tokens for normal tasks. Use a higher budget only when the user asks for a deep architecture pass.
70+
71+
## When To Use Contextful
72+
73+
- Vague project questions: "where is auth handled", "resources for billing webhooks", "how does onboarding state work".
74+
- Architecture questions: flows, dependencies, config paths, module relationships, or tests.
75+
- Impact questions before editing shared code.
76+
- Memory questions where prior session learnings might matter.
77+
- Any task where you are about to read more than 3 files to gather context.
78+
79+
## Tool Preference
80+
81+
1. \`context_pack\` for most questions.
82+
2. \`search_code\` for narrow exact lookup after the pack.
83+
3. \`trace_path\` or \`impact_analysis\` when relationships matter.
84+
4. \`recall_memory\` before repeating known project work.
85+
5. \`write_lesson\` only when the lesson has valid evidence refs.
86+
87+
## Evidence Rules
88+
89+
- Treat citations from Contextful as the source of truth for follow-up reads.
90+
- If a claim will affect code, verify it against the cited files before editing.
91+
- Do not write memory without evidence refs from files, symbols, commits, or prior context packs.
92+
- If evidence changes or appears stale, prefer fresh search over old memory.
93+
94+
## Local CLI For Humans
95+
96+
\`\`\`bash
97+
cxf index --workspace .
98+
cxf search "where is auth handled" --workspace . --budget 2000
99+
cxf memory add --workspace . --claim "..." --evidence file:src/example.ts:1-20
100+
cxf server
101+
\`\`\`
102+
`;
103+
}

0 commit comments

Comments
 (0)