@dosx/agent-memory 0.0.13
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 +142 -0
- package/bin/agent-memory.js +496 -0
- package/hooks/README.md +292 -0
- package/hooks/agent-memory-hooks/agent-memory-common.sh +1020 -0
- package/hooks/agent-memory-hooks/agent-memory-session.sh +98 -0
- package/hooks/agent-memory-hooks/agent-memory-sync.sh +147 -0
- package/hooks/claude-code/settings.json +51 -0
- package/hooks/codex/config.toml.snippet +38 -0
- package/hooks/codex/hooks.json +51 -0
- package/hooks/copilot/agent-memory.json +34 -0
- package/hooks/cursor/hooks.json +36 -0
- package/hooks/gemini/settings.json +50 -0
- package/hooks/git/pre-commit +45 -0
- package/hooks/install-hooks.sh +358 -0
- package/hooks/opencode/agent-memory.ts +320 -0
- package/package.json +22 -0
- package/skills/agent-memory/SKILL.md +185 -0
- package/skills/agent-memory/references/agent-block.md +115 -0
- package/skills/agent-memory/references/bootstrap.md +84 -0
- package/skills/agent-memory/references/init.md +211 -0
- package/skills/agent-memory/references/install-hooks.md +113 -0
- package/skills/agent-memory/references/lint.md +113 -0
- package/skills/agent-memory/references/sync.md +120 -0
- package/skills/agent-memory/references/update.md +145 -0
- package/skills/agent-memory/vendor/README.md +132 -0
- package/skills/agent-memory/vendor/UPDATE.md +369 -0
- package/skills/agent-memory/vendor/memory/active-work/TEMPLATE.md +33 -0
- package/skills/agent-memory/vendor/memory/current.md +34 -0
- package/skills/agent-memory/vendor/memory/decisions.md +30 -0
- package/skills/agent-memory/vendor/memory/index.md +55 -0
- package/skills/agent-memory/vendor/memory/instructions.md +340 -0
- package/skills/agent-memory/vendor/memory/log.md +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Diego Oliveira
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Agent Memory
|
|
2
|
+
|
|
3
|
+
**Agent Memory** is a project-local **Workspace Memory** for AI coding agents.
|
|
4
|
+
It is a small set of versioned Markdown files in `.agents/memory/` — the shared
|
|
5
|
+
source of truth between humans and agents — so work continues across sessions,
|
|
6
|
+
tools, and teammates **without chat history** and **without external
|
|
7
|
+
infrastructure** (no server, vector DB, or embeddings).
|
|
8
|
+
|
|
9
|
+
Agents **read and write** that memory. A manual skill (`/agent-memory`)
|
|
10
|
+
bootstraps and maintains it; optional lifecycle hooks add deterministic git
|
|
11
|
+
checkpoints while you work.
|
|
12
|
+
|
|
13
|
+
Supported harnesses: Cursor, Claude Code, Codex, OpenCode, Copilot, Gemini CLI.
|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
- **Project memory, not chat memory.** Files in Git beat paste-from-yesterday
|
|
18
|
+
chats. Anyone (human or agent) can pick up from `.agents/memory/` alone.
|
|
19
|
+
- **Plain Markdown.** Searchable with `grep`, reviewable in PRs, no new runtime.
|
|
20
|
+
- **Progressive disclosure.** Always-load files stay short; detail lives in
|
|
21
|
+
on-demand files (`architecture.md`, `domains/*`, …).
|
|
22
|
+
- **Inspired by Karpathy's [llm-wiki][llm-wiki]** (index, log, lint, small
|
|
23
|
+
cross-linked files), adapted from source ingestion to _project_ memory.
|
|
24
|
+
|
|
25
|
+
## How it works
|
|
26
|
+
|
|
27
|
+
Memory lives at `.agents/memory/` and separates **durable knowledge** from
|
|
28
|
+
**operational state**:
|
|
29
|
+
|
|
30
|
+
| File | Role |
|
|
31
|
+
| ------------------------- | -------------------------------------------------------------- |
|
|
32
|
+
| `instructions.md` | Method: how agents read and maintain the memory. |
|
|
33
|
+
| `index.md` | Map + loading policy (always-load vs on-demand). |
|
|
34
|
+
| `current.md` | Shared project state (done / in progress / next). |
|
|
35
|
+
| `active-work/<branch>.md` | Per-branch scratchpad (no merge conflicts across branches). |
|
|
36
|
+
| `decisions.md` | Decisions and **why**. |
|
|
37
|
+
| `log.md` | Chronological activity log (append at the bottom). |
|
|
38
|
+
|
|
39
|
+
Lazy files (`vision.md`, `architecture.md`, `patterns.md`, `mistakes.md`,
|
|
40
|
+
`known-issues.md`, `domains/*`, `features/*`) appear only when there is real
|
|
41
|
+
content.
|
|
42
|
+
|
|
43
|
+
**Workflow:** before a task, agents read `index.md`, `current.md`, and their
|
|
44
|
+
branch's `active-work` file; while working they keep those current; at
|
|
45
|
+
checkpoints they flush with `/agent-memory sync`.
|
|
46
|
+
|
|
47
|
+
Full method:
|
|
48
|
+
[`skills/agent-memory/vendor/README.md`](./skills/agent-memory/vendor/README.md)
|
|
49
|
+
and
|
|
50
|
+
[`instructions.md`](./skills/agent-memory/vendor/memory/instructions.md).
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Skill (primary)
|
|
56
|
+
npx skills add diegoos/agent-memory --skill agent-memory
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
In your agent:
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
/agent-memory init # auto-detect harnesses, or: init cursor
|
|
63
|
+
/agent-memory bootstrap # optional: populate memory from the repo
|
|
64
|
+
/agent-memory install hooks cursor # print hook-install commands (skill never runs them)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Install lifecycle hooks with the `npx` CLI:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npx @dosx/agent-memory install hooks cursor
|
|
71
|
+
# interactive menu (skill + hooks / skill only / hooks only):
|
|
72
|
+
npx @dosx/agent-memory install cursor
|
|
73
|
+
# or from a checkout: bash hooks/install-hooks.sh cursor
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`init` wires each harness's **native instruction file** (for example Cursor
|
|
77
|
+
`.cursor/rules/agent-memory.mdc`, Copilot
|
|
78
|
+
`.github/instructions/agent-memory.instructions.md`, or `AGENTS.md` /
|
|
79
|
+
`CLAUDE.md` / `GEMINI.md`). It does **not** create harness roots (`.cursor/`,
|
|
80
|
+
`.claude/`, …) unless you ask — and it never copies hook scripts. Use
|
|
81
|
+
`init <harness>` when you already know the agent.
|
|
82
|
+
|
|
83
|
+
## The skill
|
|
84
|
+
|
|
85
|
+
[`/agent-memory`](./skills/agent-memory) is **manual-only** (never auto-triggers):
|
|
86
|
+
|
|
87
|
+
| Command | Does |
|
|
88
|
+
| ----------------------------- | ----------------------------------------------------------------- |
|
|
89
|
+
| `/agent-memory help` | List commands. |
|
|
90
|
+
| `/agent-memory init` | Create `.agents/memory/`; wire native instruction file(s). |
|
|
91
|
+
| `/agent-memory install hooks` | Print how to install/refresh hooks (user-run installer). |
|
|
92
|
+
| `/agent-memory update` | Migrate scaffolding; never overwrites your content blindly. |
|
|
93
|
+
| `/agent-memory bootstrap` | Analyze the project and populate the memory. |
|
|
94
|
+
| `/agent-memory sync` | Refresh `current.md` / active-work / `log.md` / `index.md`. |
|
|
95
|
+
| `/agent-memory lint` | Broken links, orphans, stale per-branch files, consistency. |
|
|
96
|
+
|
|
97
|
+
## Hooks
|
|
98
|
+
|
|
99
|
+
Optional lifecycle hooks keep `.agents/memory/` current **during** agent work
|
|
100
|
+
with deterministic checkpoints (no LLM loops): session binding, _Touched files_,
|
|
101
|
+
`log.md` path bullets on full checkpoints, `current.md` _In progress_ on session
|
|
102
|
+
start.
|
|
103
|
+
|
|
104
|
+
**Semantic** content stays agent-owned (or `/agent-memory sync`): decisions,
|
|
105
|
+
progress notes, log summary/type, lazy files.
|
|
106
|
+
|
|
107
|
+
Install steps, event matrix, and project-dir resolution:
|
|
108
|
+
[`hooks/README.md`](./hooks/README.md).
|
|
109
|
+
|
|
110
|
+
## Other install options
|
|
111
|
+
|
|
112
|
+
**Manual skeleton** (no skill CLI):
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
git clone --branch 0.0.13 --depth 1 \
|
|
116
|
+
https://github.com/diegoos/agent-memory /tmp/agent-memory
|
|
117
|
+
mkdir -p .agents
|
|
118
|
+
cp -R /tmp/agent-memory/skills/agent-memory/vendor/memory .agents/memory
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Then paste the agent-memory block from
|
|
122
|
+
[`skills/agent-memory/references/agent-block.md`](./skills/agent-memory/references/agent-block.md)
|
|
123
|
+
into your agent instructions file (keep the
|
|
124
|
+
`<!-- <agent-memory> -->` … `<!-- </agent-memory> -->` markers so `update` can
|
|
125
|
+
refresh only that block).
|
|
126
|
+
|
|
127
|
+
## Repository layout
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
agent-memory/
|
|
131
|
+
├── bin/agent-memory.js # npx CLI
|
|
132
|
+
├── package.json
|
|
133
|
+
├── hooks/ # installer + harness configs (outside the skill)
|
|
134
|
+
└── skills/agent-memory/ # SKILL.md + vendor/ + references/
|
|
135
|
+
└── vendor/ # SoT: memory skeleton + UPDATE.md + method README
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT. See [LICENSE](./LICENSE).
|
|
141
|
+
|
|
142
|
+
[llm-wiki]: https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { spawnSync } = require('node:child_process');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
|
|
8
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
9
|
+
const VERSION = require('../package.json').version;
|
|
10
|
+
const INSTALL_HOOKS_SH = path.join(ROOT, 'hooks', 'install-hooks.sh');
|
|
11
|
+
const REMOTE_SKILL_SOURCE = `diegoos/agent-memory#${VERSION}`;
|
|
12
|
+
|
|
13
|
+
const CANONICAL_HARNESSES = new Set([
|
|
14
|
+
'cursor',
|
|
15
|
+
'claude',
|
|
16
|
+
'codex',
|
|
17
|
+
'opencode',
|
|
18
|
+
'copilot',
|
|
19
|
+
'gemini',
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
const HARNESS_ALIASES = {
|
|
23
|
+
'claude-code': 'claude',
|
|
24
|
+
github: 'copilot',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Env keys forwarded to install-hooks.sh (keep in sync with OpenCode
|
|
29
|
+
* ENV_ALLOWLIST_EXACT + prefixes in hooks/opencode/agent-memory.ts).
|
|
30
|
+
*/
|
|
31
|
+
const ENV_ALLOWLIST_EXACT = new Set([
|
|
32
|
+
'PATH',
|
|
33
|
+
'HOME',
|
|
34
|
+
'USER',
|
|
35
|
+
'SHELL',
|
|
36
|
+
'TMPDIR',
|
|
37
|
+
'TMP',
|
|
38
|
+
'TEMP',
|
|
39
|
+
'LANG',
|
|
40
|
+
'TZ',
|
|
41
|
+
// Windows
|
|
42
|
+
'SystemRoot',
|
|
43
|
+
'SYSTEMROOT',
|
|
44
|
+
'windir',
|
|
45
|
+
'WINDIR',
|
|
46
|
+
'USERPROFILE',
|
|
47
|
+
'HOMEDRIVE',
|
|
48
|
+
'HOMEPATH',
|
|
49
|
+
'ComSpec',
|
|
50
|
+
'COMSPEC',
|
|
51
|
+
'PATHEXT',
|
|
52
|
+
// Git / XDG (safe.directory and config discovery)
|
|
53
|
+
'XDG_CONFIG_HOME',
|
|
54
|
+
'XDG_DATA_HOME',
|
|
55
|
+
'GIT_CONFIG_GLOBAL',
|
|
56
|
+
'GIT_CONFIG_SYSTEM',
|
|
57
|
+
'GIT_CONFIG',
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const ESC = '\u001b';
|
|
61
|
+
const CSI = `${ESC}[`;
|
|
62
|
+
|
|
63
|
+
function normalizeHarness(name) {
|
|
64
|
+
if (CANONICAL_HARNESSES.has(name)) return name;
|
|
65
|
+
return HARNESS_ALIASES[name] || null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isTTY() {
|
|
69
|
+
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function skillsAddCommandText() {
|
|
73
|
+
return `npx --yes skills add ${REMOTE_SKILL_SOURCE} --skill agent-memory`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function printHelp() {
|
|
77
|
+
console.log(`agent-memory ${VERSION}
|
|
78
|
+
|
|
79
|
+
Hooks installer for @dosx/agent-memory. The skill is installed separately
|
|
80
|
+
via npx skills add (not this CLI).
|
|
81
|
+
|
|
82
|
+
Usage:
|
|
83
|
+
agent-memory install hooks <harness>
|
|
84
|
+
agent-memory install <harness> # interactive menu (TTY)
|
|
85
|
+
agent-memory install skill # redirect to npx skills add
|
|
86
|
+
agent-memory help
|
|
87
|
+
|
|
88
|
+
Harnesses: cursor, claude (claude-code), codex, opencode, copilot (github), gemini
|
|
89
|
+
|
|
90
|
+
Examples:
|
|
91
|
+
npx @dosx/agent-memory install hooks cursor
|
|
92
|
+
npx @dosx/agent-memory install cursor
|
|
93
|
+
npx skills add diegoos/agent-memory#${VERSION} --skill agent-memory
|
|
94
|
+
`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Always shell:false — argv must not be re-parsed by cmd.exe. */
|
|
98
|
+
function run(command, args, options = {}) {
|
|
99
|
+
const result = spawnSync(command, args, {
|
|
100
|
+
stdio: 'inherit',
|
|
101
|
+
...options,
|
|
102
|
+
shell: false,
|
|
103
|
+
});
|
|
104
|
+
if (result.error) {
|
|
105
|
+
console.error(`error: ${result.error.message}`);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
if (result.signal) {
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
if (result.status === null || result.status !== 0) {
|
|
112
|
+
process.exit(result.status ?? 1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function buildInstallerEnv() {
|
|
117
|
+
const env = {
|
|
118
|
+
AGENT_MEMORY_PROJECT_DIR:
|
|
119
|
+
process.env.AGENT_MEMORY_PROJECT_DIR || process.cwd(),
|
|
120
|
+
AGENT_MEMORY_VERSION: VERSION,
|
|
121
|
+
};
|
|
122
|
+
for (const key of Object.keys(process.env)) {
|
|
123
|
+
if (ENV_ALLOWLIST_EXACT.has(key) || key.startsWith('LC_')) {
|
|
124
|
+
const val = process.env[key];
|
|
125
|
+
if (val !== undefined) env[key] = val;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return env;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function runSkillsAdd() {
|
|
132
|
+
const args = [
|
|
133
|
+
'--yes',
|
|
134
|
+
'skills',
|
|
135
|
+
'add',
|
|
136
|
+
REMOTE_SKILL_SOURCE,
|
|
137
|
+
'--skill',
|
|
138
|
+
'agent-memory',
|
|
139
|
+
];
|
|
140
|
+
const npx = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
141
|
+
run(npx, args);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function installHooks(harness) {
|
|
145
|
+
if (!fs.existsSync(INSTALL_HOOKS_SH)) {
|
|
146
|
+
console.error(`error: missing installer at ${INSTALL_HOOKS_SH}`);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
const bash = process.platform === 'win32' ? 'bash.exe' : 'bash';
|
|
150
|
+
run(bash, [INSTALL_HOOKS_SH, harness], { env: buildInstallerEnv() });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function renderSelectLines(title, options, selected) {
|
|
154
|
+
const lines = [title, ''];
|
|
155
|
+
for (let i = 0; i < options.length; i++) {
|
|
156
|
+
const active = i === selected;
|
|
157
|
+
const prefix = active ? `${ESC}[1m› ` : ' ';
|
|
158
|
+
const suffix = active ? `${ESC}[22m` : '';
|
|
159
|
+
lines.push(`${prefix}${options[i].label}${suffix}`);
|
|
160
|
+
}
|
|
161
|
+
lines.push('', '↑/↓ or j/k · Enter confirm · Ctrl+C/Esc cancel');
|
|
162
|
+
return lines;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function clearRenderedLines(lineCount) {
|
|
166
|
+
for (let i = 0; i < lineCount; i++) {
|
|
167
|
+
process.stdout.write(`${CSI}1A${CSI}2K`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Interactive single-select menu (TTY only). Returns the chosen option value.
|
|
173
|
+
* Aborts with exit 1 on Ctrl+C or Esc.
|
|
174
|
+
*/
|
|
175
|
+
function selectPrompt(title, options) {
|
|
176
|
+
return new Promise((resolve) => {
|
|
177
|
+
let selected = 0;
|
|
178
|
+
let renderedLineCount = 0;
|
|
179
|
+
let escState = 'normal';
|
|
180
|
+
let escTimer = null;
|
|
181
|
+
let rawModeEnabled = false;
|
|
182
|
+
const stdin = process.stdin;
|
|
183
|
+
|
|
184
|
+
function disableRawMode() {
|
|
185
|
+
if (rawModeEnabled && typeof stdin.setRawMode === 'function') {
|
|
186
|
+
stdin.setRawMode(false);
|
|
187
|
+
rawModeEnabled = false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function clearEscTimer() {
|
|
192
|
+
if (escTimer) {
|
|
193
|
+
clearTimeout(escTimer);
|
|
194
|
+
escTimer = null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function isCsiFinal(ch) {
|
|
199
|
+
const code = ch.charCodeAt(0);
|
|
200
|
+
return code >= 0x40 && code <= 0x7e;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function isAlphanumeric(ch) {
|
|
204
|
+
return /[0-9A-Za-z]/.test(ch);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function startEscTimer() {
|
|
208
|
+
clearEscTimer();
|
|
209
|
+
escTimer = setTimeout(() => {
|
|
210
|
+
escTimer = null;
|
|
211
|
+
if (escState === 'esc') {
|
|
212
|
+
escState = 'normal';
|
|
213
|
+
abort();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (escState === 'csi' || escState === 'ss3') {
|
|
217
|
+
escState = 'normal';
|
|
218
|
+
}
|
|
219
|
+
}, 50);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function moveUp() {
|
|
223
|
+
selected = (selected - 1 + options.length) % options.length;
|
|
224
|
+
redraw();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function moveDown() {
|
|
228
|
+
selected = (selected + 1) % options.length;
|
|
229
|
+
redraw();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function abort() {
|
|
233
|
+
cleanup();
|
|
234
|
+
process.stdout.write('\n');
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function cleanup() {
|
|
239
|
+
clearEscTimer();
|
|
240
|
+
disableRawMode();
|
|
241
|
+
stdin.pause();
|
|
242
|
+
stdin.removeListener('data', onData);
|
|
243
|
+
stdin.removeListener('end', onEnd);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function printMenu() {
|
|
247
|
+
const lines = renderSelectLines(title, options, selected);
|
|
248
|
+
lines.forEach((line) => process.stdout.write(`${line}\n`));
|
|
249
|
+
renderedLineCount = lines.length;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function redraw() {
|
|
253
|
+
clearRenderedLines(renderedLineCount);
|
|
254
|
+
printMenu();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function processChar(ch) {
|
|
258
|
+
if (escState === 'esc') {
|
|
259
|
+
clearEscTimer();
|
|
260
|
+
if (ch === '[') {
|
|
261
|
+
escState = 'csi';
|
|
262
|
+
startEscTimer();
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (ch === 'O') {
|
|
266
|
+
escState = 'ss3';
|
|
267
|
+
startEscTimer();
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (isAlphanumeric(ch)) {
|
|
271
|
+
escState = 'normal';
|
|
272
|
+
} else {
|
|
273
|
+
escState = 'normal';
|
|
274
|
+
abort();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (escState === 'csi') {
|
|
280
|
+
if (!isCsiFinal(ch)) {
|
|
281
|
+
startEscTimer();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
clearEscTimer();
|
|
285
|
+
escState = 'normal';
|
|
286
|
+
if (ch === 'A') {
|
|
287
|
+
moveUp();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (ch === 'B') {
|
|
291
|
+
moveDown();
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (escState === 'ss3') {
|
|
298
|
+
if (!isCsiFinal(ch)) {
|
|
299
|
+
startEscTimer();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
clearEscTimer();
|
|
303
|
+
escState = 'normal';
|
|
304
|
+
if (ch === 'A') {
|
|
305
|
+
moveUp();
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (ch === 'B') {
|
|
309
|
+
moveDown();
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (ch === '\u0003') {
|
|
316
|
+
abort();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (ch === ESC) {
|
|
320
|
+
escState = 'esc';
|
|
321
|
+
startEscTimer();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (ch === 'k') {
|
|
325
|
+
moveUp();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (ch === 'j') {
|
|
329
|
+
moveDown();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (ch === '\r' || ch === '\n') {
|
|
333
|
+
cleanup();
|
|
334
|
+
process.stdout.write('\n');
|
|
335
|
+
resolve(options[selected].value);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function onData(chunk) {
|
|
340
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
341
|
+
processChar(chunk[i]);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function onEnd() {
|
|
346
|
+
abort();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
let setupComplete = false;
|
|
350
|
+
try {
|
|
351
|
+
if (typeof stdin.setRawMode === 'function') {
|
|
352
|
+
stdin.setRawMode(true);
|
|
353
|
+
rawModeEnabled = true;
|
|
354
|
+
}
|
|
355
|
+
stdin.resume();
|
|
356
|
+
stdin.setEncoding('utf8');
|
|
357
|
+
stdin.on('data', onData);
|
|
358
|
+
stdin.on('end', onEnd);
|
|
359
|
+
printMenu();
|
|
360
|
+
setupComplete = true;
|
|
361
|
+
} finally {
|
|
362
|
+
if (!setupComplete) {
|
|
363
|
+
disableRawMode();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function failNonTTYInstallChoice(harness) {
|
|
370
|
+
console.error('error: interactive install requires a TTY.');
|
|
371
|
+
console.error(` Hooks: npx @dosx/agent-memory install hooks ${harness}`);
|
|
372
|
+
console.error(` Skill: ${skillsAddCommandText()}`);
|
|
373
|
+
process.exit(1);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function failNonTTYSkillsAdd() {
|
|
377
|
+
console.error('error: interactive install requires a TTY.');
|
|
378
|
+
console.error(` Skill: ${skillsAddCommandText()}`);
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function promptInstallChoice(harness) {
|
|
383
|
+
if (!isTTY()) {
|
|
384
|
+
failNonTTYInstallChoice(harness);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const choice = await selectPrompt(`Install agent-memory for ${harness}:`, [
|
|
388
|
+
{ label: 'Skill + hooks', value: 'both' },
|
|
389
|
+
{ label: 'Skill only', value: 'skill' },
|
|
390
|
+
{ label: 'Hooks only', value: 'hooks' },
|
|
391
|
+
]);
|
|
392
|
+
|
|
393
|
+
if (choice === 'both') {
|
|
394
|
+
runSkillsAdd();
|
|
395
|
+
installHooks(harness);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (choice === 'skill') {
|
|
399
|
+
runSkillsAdd();
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
installHooks(harness);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async function promptSkillsAddOrCancel() {
|
|
406
|
+
const choice = await selectPrompt('Continue?', [
|
|
407
|
+
{ label: 'Run npx skills add', value: 'run' },
|
|
408
|
+
{ label: 'Cancel', value: 'cancel' },
|
|
409
|
+
]);
|
|
410
|
+
|
|
411
|
+
if (choice === 'run') {
|
|
412
|
+
runSkillsAdd();
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
process.exit(0);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async function main(argv) {
|
|
419
|
+
const args = argv.slice(2);
|
|
420
|
+
if (
|
|
421
|
+
args.length === 0 ||
|
|
422
|
+
args[0] === 'help' ||
|
|
423
|
+
args[0] === '--help' ||
|
|
424
|
+
args[0] === '-h'
|
|
425
|
+
) {
|
|
426
|
+
printHelp();
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (args[0] !== 'install') {
|
|
431
|
+
console.error(`error: unknown command: ${args[0]}`);
|
|
432
|
+
printHelp();
|
|
433
|
+
process.exit(1);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const rest = args.slice(1);
|
|
437
|
+
if (rest.length === 0) {
|
|
438
|
+
console.error('error: missing install target');
|
|
439
|
+
printHelp();
|
|
440
|
+
process.exit(1);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (rest[0] === 'skill') {
|
|
444
|
+
if (rest.length > 1) {
|
|
445
|
+
console.error('error: install skill does not accept arguments');
|
|
446
|
+
process.exit(1);
|
|
447
|
+
}
|
|
448
|
+
if (!isTTY()) {
|
|
449
|
+
failNonTTYSkillsAdd();
|
|
450
|
+
}
|
|
451
|
+
console.log('This CLI installs hooks only. Install the skill with:');
|
|
452
|
+
console.log(` ${skillsAddCommandText()}`);
|
|
453
|
+
await promptSkillsAddOrCancel();
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (rest[0] === 'hooks') {
|
|
458
|
+
const raw = rest[1];
|
|
459
|
+
if (!raw) {
|
|
460
|
+
console.error('error: install hooks requires a harness argument');
|
|
461
|
+
printHelp();
|
|
462
|
+
process.exit(1);
|
|
463
|
+
}
|
|
464
|
+
if (rest.length > 2) {
|
|
465
|
+
console.error(`error: unexpected argument: ${rest[2]}`);
|
|
466
|
+
process.exit(1);
|
|
467
|
+
}
|
|
468
|
+
const harness = normalizeHarness(raw);
|
|
469
|
+
if (!harness) {
|
|
470
|
+
console.error(`error: unknown harness: ${raw}`);
|
|
471
|
+
printHelp();
|
|
472
|
+
process.exit(1);
|
|
473
|
+
}
|
|
474
|
+
installHooks(harness);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const harness = normalizeHarness(rest[0]);
|
|
479
|
+
if (harness) {
|
|
480
|
+
if (rest.length > 1) {
|
|
481
|
+
console.error(`error: unexpected argument: ${rest[1]}`);
|
|
482
|
+
process.exit(1);
|
|
483
|
+
}
|
|
484
|
+
await promptInstallChoice(harness);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
console.error(`error: unknown install target: ${rest[0]}`);
|
|
489
|
+
printHelp();
|
|
490
|
+
process.exit(1);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
main(process.argv).catch((err) => {
|
|
494
|
+
console.error(err);
|
|
495
|
+
process.exit(1);
|
|
496
|
+
});
|