context-eng 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +272 -0
- package/dist/categories.d.ts +27 -0
- package/dist/categories.js +71 -0
- package/dist/categories.js.map +1 -0
- package/dist/cli-entry.d.ts +2 -0
- package/dist/cli-entry.js +7 -0
- package/dist/cli-entry.js.map +1 -0
- package/dist/cli.d.ts +30 -0
- package/dist/cli.js +327 -0
- package/dist/cli.js.map +1 -0
- package/dist/db.d.ts +40 -0
- package/dist/db.js +158 -0
- package/dist/db.js.map +1 -0
- package/dist/engine.d.ts +149 -0
- package/dist/engine.js +589 -0
- package/dist/engine.js.map +1 -0
- package/dist/harness.d.ts +56 -0
- package/dist/harness.js +358 -0
- package/dist/harness.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/inspect-cli.d.ts +2 -0
- package/dist/inspect-cli.js +96 -0
- package/dist/inspect-cli.js.map +1 -0
- package/dist/inspect.d.ts +33 -0
- package/dist/inspect.js +149 -0
- package/dist/inspect.js.map +1 -0
- package/dist/map.d.ts +39 -0
- package/dist/map.js +106 -0
- package/dist/map.js.map +1 -0
- package/dist/mcp.d.ts +5 -0
- package/dist/mcp.js +348 -0
- package/dist/mcp.js.map +1 -0
- package/dist/migrate.d.ts +7 -0
- package/dist/migrate.js +107 -0
- package/dist/migrate.js.map +1 -0
- package/dist/paths.d.ts +29 -0
- package/dist/paths.js +69 -0
- package/dist/paths.js.map +1 -0
- package/dist/search.d.ts +144 -0
- package/dist/search.js +449 -0
- package/dist/search.js.map +1 -0
- package/dist/secrets.d.ts +28 -0
- package/dist/secrets.js +135 -0
- package/dist/secrets.js.map +1 -0
- package/dist/text.d.ts +22 -0
- package/dist/text.js +153 -0
- package/dist/text.js.map +1 -0
- package/dist/tokens.d.ts +6 -0
- package/dist/tokens.js +15 -0
- package/dist/tokens.js.map +1 -0
- package/dist/typesafe.d.ts +40 -0
- package/dist/typesafe.js +170 -0
- package/dist/typesafe.js.map +1 -0
- package/package.json +51 -0
- package/system_prompts/AGENTS.md +14 -0
- package/system_prompts/CLAUDE.md +14 -0
- package/system_prompts/rules.md +157 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!-- context-eng:start -->
|
|
2
|
+
Memory keeps mistakes, decisions, preferences and habits so you do not relearn them every chat. Search when that past could help this task. `memory_search` retrieves it. Narrow with `categories` and `filters.scope`. Optional `hints` (topics, tags, links, categories) boost ranking. Search returns promoted memory. Staging stays hidden unless `includeStaging: true`. New writes may wait in staging until `memory_promote`. If search returns `no matching memory` nothing matched. Continue without writing. `memory_create` after work, for one new claim that is not already stored. `memory_edit` when a hit is close but stale. `memory_list_categories` when you need names. Prefer this project over global. Prefer newer hits; an older one can be stale depending on when it was updated. Full contract: `system_prompts/rules.md`.
|
|
3
|
+
| Tool | One word | When |
|
|
4
|
+
|------|----------|------|
|
|
5
|
+
| `memory_search` | retrieve | Past memory for this task. `query`, optional `categories` and `hints` (boost only). `project` or `both` needs `projectPath`, `--project`, or `memory_bind`; else `PROJECT_NOT_BOUND`, then retry with `projectPath`. `global` needs none. |
|
|
6
|
+
| `memory_create` | save | Memory worth keeping. One sentence, one claim |
|
|
7
|
+
| `memory_edit` | patch | Memory is close but stale. Sharpen `content`, labels, or category. `currentCategory` and `id` |
|
|
8
|
+
| `memory_bind` | attach | Project memory is unbound, or you switched repos and the binding is wrong |
|
|
9
|
+
| `memory_list_categories` | inspect | You need category names before a named search or write |
|
|
10
|
+
| `memory_map` | index | it contains list of categories and all memory lines and use when you have the text but not the id . |
|
|
11
|
+
| `memory_promote` | graduate | A staging memory proved useful and should be searchable. `category` and `id` |
|
|
12
|
+
| `memory_demote` | waitlist | A searchable memory should leave default search |
|
|
13
|
+
| `memory_delete` | discard | User rejects a staging memory. Demote first if it is already live |
|
|
14
|
+
<!-- context-eng:end -->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!-- context-eng:start -->
|
|
2
|
+
Memory keeps mistakes, decisions, preferences and habits so you do not relearn them every chat. Search when that past could help this task. `memory_search` retrieves it. Pass the user's request as `query`. Narrow with `categories` and `filters.scope`. Optional `hints` (topics, tags, links, categories) boost ranking. Search returns promoted memory. Staging stays hidden unless `includeStaging: true`. New writes may wait in staging until `memory_promote`. If search returns `no matching memory` nothing matched. Continue without writing. `memory_create` after work, for one new claim that is not already stored. `memory_edit` when a hit is close but stale. `memory_list_categories` when you need names. Prefer this project over global. Prefer newer hits; an older one can be stale depending on when it was updated. Full contract: `system_prompts/rules.md`.
|
|
3
|
+
| Tool | One word | When |
|
|
4
|
+
|------|----------|------|
|
|
5
|
+
| `memory_search` | retrieve | Past memory may help this task. `query` + `categories` + `filters.scope`. Optional `hints` boost only. `project` or `both` needs `--project`, `projectPath`, or `memory_bind`; otherwise `PROJECT_NOT_BOUND`, then retry with `projectPath`. `global` works with no project bound. |
|
|
6
|
+
| `memory_create` | save | Something worth keeping for FUTURE. One sentence, one claim |
|
|
7
|
+
| `memory_edit` | patch | Memory is close but stale. Sharpen `content`, labels, or category. `currentCategory` and `id` |
|
|
8
|
+
| `memory_bind` | attach | Project memory is unbound, or you switched repos and the binding is wrong |
|
|
9
|
+
| `memory_list_categories` | inspect | You need category names before a named search or write |
|
|
10
|
+
| `memory_map` | index | it contains list of categories and all memory lines and use when you have the text but not the id . |
|
|
11
|
+
| `memory_promote` | graduate | A staging memory proved useful and should be searchable. `category` and `id` |
|
|
12
|
+
| `memory_demote` | waitlist | A searchable memory should leave default search |
|
|
13
|
+
| `memory_delete` | discard | User rejects a staging memory. Demote first if it is already live |
|
|
14
|
+
<!-- context-eng:end -->
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Memory tool rules
|
|
2
|
+
|
|
3
|
+
Contract for the context-eng MCP tools. Confirm in source before changing behavior.
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
bind → map → search
|
|
7
|
+
create → edit → promote | demote → delete (staging only)
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Agent usage
|
|
11
|
+
|
|
12
|
+
1. MCP start with `--project`, `projectPath` on a call, or `memory_bind` explicitly binds a project DB. Without one, global-only operations work and project/both operations return `PROJECT_NOT_BOUND`. Retry that call with `projectPath`.
|
|
13
|
+
2. Call `memory_search` with the user's request. Use the returned text as context.
|
|
14
|
+
3. If the reply starts with `no matching memory.`, continue without stored hits.
|
|
15
|
+
4. Write only a durable claim, one sentence, into the right scope and category.
|
|
16
|
+
|
|
17
|
+
Prefer `memory_list_categories` or `memory_map` over inventing category names. Named search requires the category to already exist in that scope.
|
|
18
|
+
|
|
19
|
+
When you need an id, call `memory_map`. `lines_ids[i]` is the id for `lines[i]`. For a staging row, `lines_categories[i]` is the category.
|
|
20
|
+
|
|
21
|
+
Search returns relevant memory text with each hit's last-updated date, category, and project. Write tools return JSON. Engine rejects return `{ "error": "<CODE>", "message": "..." }` except `memory_search`, which returns the message string.
|
|
22
|
+
|
|
23
|
+
## Tools
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
| Tool | Role |
|
|
27
|
+
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `memory_bind` | Bind an unbound server or switch the active project. Creates `~/.context/projects/<key>/` if missing. Normal project startup binds via `--project`. Does not write `AGENTS.md`. |
|
|
29
|
+
| `memory_map` | JSON index for `global`, `project`, or `both` (default). `lines_ids` align with `lines`. Staging also aligns `lines_categories`. A project map needs `projectPath` or a bound project. |
|
|
30
|
+
| `memory_search` | Retrieve relevant memory text with staleness and provenance metadata. |
|
|
31
|
+
| `memory_create` | Insert one claim. Missing custom categories are created. |
|
|
32
|
+
| `memory_edit` | Patch by id. Moving category auto-promotes or demotes. |
|
|
33
|
+
| `memory_promote` | Staging → searchable. |
|
|
34
|
+
| `memory_demote` | Searchable → staging. |
|
|
35
|
+
| `memory_delete` | Delete **staging** rows only. |
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Bind vs scope
|
|
41
|
+
|
|
42
|
+
`projectPath` chooses **which project's files** to open. `filters.scope` chooses **which of those catalogs** to read after bind.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
| | `projectPath` / bind | `filters.scope` |
|
|
46
|
+
| ------ | ---------------------------------------- | -------------------------------------------- |
|
|
47
|
+
| Values | existing directory, or `.` | `both` (default), `global`, `project` |
|
|
48
|
+
| Effect | sets `layout.projectPath` / `projectKey` | which catalogs search reads |
|
|
49
|
+
| Writes | later `scope=project` create goes here | create still takes `scope: global | project` |
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Bind requires an existing directory. Same key: no remount. Different key: close project DBs, open the new layout, refresh maps.
|
|
53
|
+
|
|
54
|
+
`filters.scope = global` is valid before project binding. `project` or `both` requires a bound project; the engine never substitutes its process working directory.
|
|
55
|
+
|
|
56
|
+
Before binding, default `memory_map` and `memory_list_categories` return their global portions only; explicit project scope returns `PROJECT_NOT_BOUND`. Id-based edit/promote/demote/delete tools do not accept `projectPath`, so their unbound error instructs the caller to use `memory_bind` first.
|
|
57
|
+
|
|
58
|
+
## Map
|
|
59
|
+
|
|
60
|
+
`memory_map` takes an optional `scope` of `global`, `project`, or `both`. Omitted scope defaults to `both`. The `maps` object includes only the scopes returned.
|
|
61
|
+
|
|
62
|
+
Each collection lists promoted rows only, newest `created_at` first, at most 12. `lines_ids[i]` is the id of `lines[i]`.
|
|
63
|
+
|
|
64
|
+
`staging.lines`, `staging.lines_ids`, and `staging.lines_categories` share that same index. Those rows are the newest staging notes by `created_at`, at most 12, not every staging note. `staging.searched` is false. Use `lines_categories[i]` with `lines_ids[i]` for edit, promote, demote, or delete.
|
|
65
|
+
|
|
66
|
+
`map.md` is the text index and has no ids.
|
|
67
|
+
|
|
68
|
+
`scope: "global"` works with no project bound. An omitted map scope returns every available portion, which is global-only while unbound. Explicit project scope needs `projectPath` on the call or an already bound project; otherwise it returns `PROJECT_NOT_BOUND`.
|
|
69
|
+
|
|
70
|
+
## Categories
|
|
71
|
+
|
|
72
|
+
Built-in names: `instruction`, `mistake`, `preference`, `decision`, `constraint`, `workflow`.
|
|
73
|
+
|
|
74
|
+
Auto-promote on create (leave staging immediately): `instruction`, `decision`, `constraint`, `mistake`.
|
|
75
|
+
|
|
76
|
+
Stay in staging on create: `preference`, and every custom category.
|
|
77
|
+
|
|
78
|
+
Names: 1–64 characters after NFKC trim, no control characters. Canonical form is lowercased. Search category lists must be unique after that lowercase.
|
|
79
|
+
|
|
80
|
+
A category exists **per scope**. `decision` in project does not create a global `decision`. Named search that cannot find the name in any selected scope → `INVALID_CATEGORY` / `unknown category: <name>`.
|
|
81
|
+
|
|
82
|
+
Create and category-changing edit may register a missing custom category. If a new name has at least 80% character similarity to a built-in or same-scope registered category after separators are removed, the first call returns `NEAR_CATEGORY` without writing. Separator-only variants such as `batch-probe` and `batch_probe` also trigger it. Use the suggested existing category, or retry the same tool with `confirmNewCategory: true` to explicitly create the new one. Search and locate may not register categories. Delete of the last row does **not** unregister the category; the catalog can keep a count-0 entry.
|
|
83
|
+
|
|
84
|
+
## Search
|
|
85
|
+
|
|
86
|
+
Omit `categories` → every category in the selected scopes. That is the only “search all”.
|
|
87
|
+
|
|
88
|
+
When `categories` is sent: 1–4 unique names. `[]` is invalid (`-32602`, min 1). Five or more is invalid (`-32602`, max 4). Duplicates after normalize → `INVALID_CATEGORIES`.
|
|
89
|
+
|
|
90
|
+
Default filters:
|
|
91
|
+
|
|
92
|
+
- `scope`: `both`
|
|
93
|
+
- staging excluded unless `includeStaging: true`
|
|
94
|
+
- `active = 1` only
|
|
95
|
+
- `sort.by`: `relevance`, `sort.order`: `desc`
|
|
96
|
+
- `limit`: 50, hard cap 50
|
|
97
|
+
|
|
98
|
+
Other filters: `minImportance` 0–1, `subject` ≤64 chars, `topics` / `tags` / `links` up to 10 values each (each ≤64), match `any` (default) or `all`. Time: `field` `created`|`updated`, preset `this_week`|`this_month`, or `from`/`to` ISO-8601 — not preset plus from/to.
|
|
99
|
+
|
|
100
|
+
Optional `hints.topics`, `hints.tags`, and `hints.links` contain 1–10 unique exact label values. `hints.categories` contains 1–4 unique category boosts. Hints influence candidate order and may change which rows reach the 90-candidate Jev boundary, but never hard-filter eligibility. There is no `hints.terms` field.
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
eligible rows
|
|
104
|
+
rows ≤60 AND tokens ≤12000 → every eligible row to Jev
|
|
105
|
+
otherwise → FTS + exact hint labels + one typo retry when FTS is empty
|
|
106
|
+
+ project/category/importance/freshness fill up to 90
|
|
107
|
+
>90 candidates → first 90 ordered candidates to Jev
|
|
108
|
+
Jev missing, timeout, or fail → local FTS + exact hint-label fallback
|
|
109
|
+
keep Noul > 0.5
|
|
110
|
+
then cap 50 hits / 4000 tokens
|
|
111
|
+
zero kept → "no matching memory. after work, memory_create if something happened and you need to save it for later."
|
|
112
|
+
hits kept and candidates > 90 → append "Memory is too large to evaluate."
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Successful search text starts with a concise `retrieval: small|large` mode/count line, followed by memory blocks and any final status message.
|
|
116
|
+
|
|
117
|
+
Jev answers **Noul** (0–1 yes-probability), not a nuance score. Gate is strict: keep only `noul > 0.5`.
|
|
118
|
+
|
|
119
|
+
## Write
|
|
120
|
+
|
|
121
|
+
Content: one sentence / one claim. Whitespace collapsed. Empty → `EMPTY_CONTENT`. Two sentences (`.!?` then a new capital letter) → `NOT_ONE_SENTENCE`. Over ~800 tokens → `TOO_LONG`.
|
|
122
|
+
|
|
123
|
+
Labels: `subject` one value; `topics` / `tags` / `links` ≤10, each ≤64. `importance` 0–1, default 0.5.
|
|
124
|
+
|
|
125
|
+
Create `scope` is `global` or `project` only (not `both`).
|
|
126
|
+
|
|
127
|
+
Edit can move to another category in the same scope. Destination auto-promote set → promoted; otherwise staging.
|
|
128
|
+
|
|
129
|
+
Promote, demote, and delete locate by category plus `id`, the exact `line` text, or both. If both are sent and they are not the same note → `LINE_ID_MISMATCH`. If the line matches more than one note in that category → `AMBIGUOUS_LINE`. Missing → `NOT_FOUND`. Edit still locates by category + id.
|
|
130
|
+
|
|
131
|
+
Delete requires `chat_id === staging`. Promoted → `NOT_STAGING` (“use memory_demote first”).
|
|
132
|
+
|
|
133
|
+
## Error codes
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
| Code | When |
|
|
137
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
138
|
+
| `INVALID_PROJECT_PATH` | bind path is not an existing directory |
|
|
139
|
+
| `PROJECT_NOT_BOUND` | project access before binding. Retry tools that accept `projectPath`; call `memory_bind` first for id-based tools |
|
|
140
|
+
| `INVALID_SCOPE` | create scope not `global`/`project`; search filter scope not `both`/`global`/`project` |
|
|
141
|
+
| `INVALID_CATEGORY` | bad name, or named search/locate cannot find it in selected scopes |
|
|
142
|
+
| `INVALID_CATEGORIES` | provided list not 1–4, or not unique after normalize |
|
|
143
|
+
| `NEAR_CATEGORY` | create or category-changing edit needs `confirmNewCategory: true` before making a near-duplicate category |
|
|
144
|
+
| `INVALID_FILTER` | subject/labels too long or too many; match not `any`/`all` |
|
|
145
|
+
| `INVALID_TIME` | bad field/preset, preset mixed with from/to, from after to, not ISO-8601 |
|
|
146
|
+
| `INVALID_SORT` | `by` or `order` not in the allowed set |
|
|
147
|
+
| `INVALID_IMPORTANCE` | not a number in 0–1 |
|
|
148
|
+
| `EMPTY_CONTENT` | content empty after trim |
|
|
149
|
+
| `NOT_ONE_SENTENCE` | more than one claim |
|
|
150
|
+
| `TOO_LONG` | content over 800 tokens |
|
|
151
|
+
| `NOT_FOUND` | id or line missing in that category |
|
|
152
|
+
| `AMBIGUOUS_LINE` | line text matches more than one memory in that category |
|
|
153
|
+
| `LINE_ID_MISMATCH` | id and line were both sent and are not the same memory |
|
|
154
|
+
| `NOT_STAGING` | delete on a promoted row |
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
MCP schema can reject before the engine (`-32602`), e.g. empty or 5-item `categories`, or an unknown `memory_map` scope.
|