@snoai/mem-claude 1.0.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 +176 -0
- package/README.md +36 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +126 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/doctor.d.ts +3 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +66 -0
- package/dist/doctor.js.map +1 -0
- package/dist/explicit.d.ts +9 -0
- package/dist/explicit.d.ts.map +1 -0
- package/dist/explicit.js +88 -0
- package/dist/explicit.js.map +1 -0
- package/dist/files.d.ts +6 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +71 -0
- package/dist/files.js.map +1 -0
- package/dist/hooks.d.ts +8 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +385 -0
- package/dist/hooks.js.map +1 -0
- package/dist/import.d.ts +13 -0
- package/dist/import.d.ts.map +1 -0
- package/dist/import.js +106 -0
- package/dist/import.js.map +1 -0
- package/dist/install.d.ts +26 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +118 -0
- package/dist/install.js.map +1 -0
- package/dist/memory-client.d.ts +4 -0
- package/dist/memory-client.d.ts.map +1 -0
- package/dist/memory-client.js +9 -0
- package/dist/memory-client.js.map +1 -0
- package/dist/messages.d.ts +9 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +9 -0
- package/dist/messages.js.map +1 -0
- package/dist/paths.d.ts +9 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +30 -0
- package/dist/paths.js.map +1 -0
- package/dist/recall.d.ts +2 -0
- package/dist/recall.d.ts.map +1 -0
- package/dist/recall.js +20 -0
- package/dist/recall.js.map +1 -0
- package/dist/scope.d.ts +6 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +36 -0
- package/dist/scope.js.map +1 -0
- package/dist/session-state.d.ts +55 -0
- package/dist/session-state.d.ts.map +1 -0
- package/dist/session-state.js +112 -0
- package/dist/session-state.js.map +1 -0
- package/dist/settings.d.ts +23 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +33 -0
- package/dist/settings.js.map +1 -0
- package/dist/skill-runs.d.ts +7 -0
- package/dist/skill-runs.d.ts.map +1 -0
- package/dist/skill-runs.js +108 -0
- package/dist/skill-runs.js.map +1 -0
- package/dist/worker.d.ts +23 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +319 -0
- package/dist/worker.js.map +1 -0
- package/package.json +40 -0
- package/skills/sno-mem-claude/SKILL.md +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Sno Memory for Claude Code
|
|
2
|
+
|
|
3
|
+
Long-term memory for Claude Code sessions. The memory service stores and retrieves project memories;
|
|
4
|
+
this plugin connects host hooks and the commands `recall`, `get`, `remember`, and `correct`.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Install Node.js 22.22.3+, 24.15.0+, or 25.9.0+ and Claude Code. Complete the
|
|
9
|
+
[shared memory setup](https://github.com/sno-ai/sno-station/blob/main/docs/memory-setup.md)
|
|
10
|
+
once, then run:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g @snoai/mem-claude@1.0.0
|
|
14
|
+
sno-mem-claude install --config-dir ~/.claude
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The shared setup installs the memory service and writes `~/.sno/settings.json`. The hooks
|
|
18
|
+
start the service when needed. Use `SNO_PROFILE_DIR` to select another profile root.
|
|
19
|
+
|
|
20
|
+
Open a new Claude Code session in your project. Run `sno-mem-claude doctor` to check the installation.
|
|
21
|
+
The plugin captures turns in the background and recalls relevant memory on session start and
|
|
22
|
+
prompts. Use `sno-mem-claude remember "Prefer tabs in this repository"` and
|
|
23
|
+
`sno-mem-claude recall "indentation"` for explicit memory operations. Correct an identified wrong entry with
|
|
24
|
+
`sno-mem-claude correct <id> "correct text"`; it returns a fresh id and keeps the previous entry
|
|
25
|
+
visible as retired history. Automatic memory blocks come from the service; child agents do not
|
|
26
|
+
inject memory or capture turns.
|
|
27
|
+
|
|
28
|
+
## Modes
|
|
29
|
+
|
|
30
|
+
The first-release setup selects Local First in `settings.json`, which stores memory locally.
|
|
31
|
+
Agent Native uses your host subscription for model-assisted work; REM Enhanced also uses
|
|
32
|
+
Sno's memory models. Preserve the existing encryption key when changing settings.
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
Licensed under [Apache-2.0](LICENSE).
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { doctor } from "./doctor.js";
|
|
5
|
+
import { correctCommand, getCommand, recallCommand, rememberCommand } from "./explicit.js";
|
|
6
|
+
import { postToolUse, preToolUse, sessionEnd, sessionStart, stop, userPromptSubmit } from "./hooks.js";
|
|
7
|
+
import { installClaude } from "./install.js";
|
|
8
|
+
import { importRepository } from "./import.js";
|
|
9
|
+
import { MESSAGES } from "./messages.js";
|
|
10
|
+
import { workspaceRoot } from "./scope.js";
|
|
11
|
+
import { runWorker } from "./worker.js";
|
|
12
|
+
async function readStdin() {
|
|
13
|
+
const chunks = [];
|
|
14
|
+
for await (const chunk of process.stdin)
|
|
15
|
+
chunks.push(Buffer.from(chunk));
|
|
16
|
+
const text = Buffer.concat(chunks).toString("utf8").trim();
|
|
17
|
+
return text ? JSON.parse(text) : {};
|
|
18
|
+
}
|
|
19
|
+
function option(args, name) {
|
|
20
|
+
const index = args.indexOf(name);
|
|
21
|
+
return index >= 0 ? args[index + 1] : undefined;
|
|
22
|
+
}
|
|
23
|
+
async function main() {
|
|
24
|
+
const [command, ...args] = process.argv.slice(2);
|
|
25
|
+
if (command === "session-start") {
|
|
26
|
+
process.stdout.write(`${await sessionStart(await readStdin())}\n`);
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
if (command === "user-prompt-submit") {
|
|
30
|
+
process.stdout.write(`${await userPromptSubmit(await readStdin())}\n`);
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
if (command === "stop") {
|
|
34
|
+
await stop(await readStdin());
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
if (command === "session-end") {
|
|
38
|
+
await sessionEnd(await readStdin());
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
if (command === "pre-tool-use") {
|
|
42
|
+
await preToolUse(await readStdin());
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
if (command === "post-tool-use") {
|
|
46
|
+
await postToolUse(await readStdin());
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
if (command === "worker") {
|
|
50
|
+
await runWorker();
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
if (command === "install") {
|
|
54
|
+
const configDir = option(args, "--config-dir");
|
|
55
|
+
if (!configDir || !isAbsolute(configDir))
|
|
56
|
+
throw new Error("--config-dir must be absolute");
|
|
57
|
+
const programPath = resolve(process.argv[1] ?? "sno-mem-claude");
|
|
58
|
+
await installClaude({
|
|
59
|
+
configDir,
|
|
60
|
+
programPath,
|
|
61
|
+
dryRun: args.includes("--dry-run"),
|
|
62
|
+
writeOutput: line => process.stdout.write(`${line}\n`),
|
|
63
|
+
});
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
if (command === "import") {
|
|
67
|
+
const repo = option(args, "--repo");
|
|
68
|
+
if (args.includes("--user") || !repo || !isAbsolute(repo))
|
|
69
|
+
throw new Error("import requires --repo <absolute-root>");
|
|
70
|
+
const result = await importRepository(await workspaceRoot(repo));
|
|
71
|
+
process.stdout.write(`blocks fed: ${result.blocksFed}\nreceipt: ${result.receiptPath}\n`);
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
if (command === "doctor") {
|
|
75
|
+
const configDir = option(args, "--config-dir") ?? process.env["CLAUDE_CONFIG_DIR"] ?? join(homedir(), ".claude");
|
|
76
|
+
const lines = await doctor(configDir).catch(() => [MESSAGES.doctorUnavailable]);
|
|
77
|
+
for (const line of lines)
|
|
78
|
+
process.stdout.write(`${line}\n`);
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
if (command === "recall") {
|
|
82
|
+
const result = await recallCommand(args.join(" "));
|
|
83
|
+
process.stdout.write(`${result.text}\n`);
|
|
84
|
+
return result.ok ? 0 : 1;
|
|
85
|
+
}
|
|
86
|
+
if (command === "get") {
|
|
87
|
+
const result = await getCommand(args[0] ?? "");
|
|
88
|
+
process.stdout.write(`${result.text}\n`);
|
|
89
|
+
return result.ok ? 0 : 1;
|
|
90
|
+
}
|
|
91
|
+
if (command === "remember") {
|
|
92
|
+
const result = await rememberCommand(args.join(" "));
|
|
93
|
+
process.stdout.write(`${result.text}\n`);
|
|
94
|
+
return result.ok ? 0 : 1;
|
|
95
|
+
}
|
|
96
|
+
if (command === "correct") {
|
|
97
|
+
const result = await correctCommand(args[0] ?? "", args.slice(1).join(" "));
|
|
98
|
+
process.stdout.write(`${result.text}\n`);
|
|
99
|
+
return result.ok ? 0 : 1;
|
|
100
|
+
}
|
|
101
|
+
process.stderr.write(`${MESSAGES.usage}\n`);
|
|
102
|
+
return 2;
|
|
103
|
+
}
|
|
104
|
+
main().then(code => {
|
|
105
|
+
process.exitCode = code;
|
|
106
|
+
if (["session-start", "user-prompt-submit", "stop", "session-end", "pre-tool-use", "post-tool-use", "worker"].includes(process.argv[2] ?? "")) {
|
|
107
|
+
process.stdout.write("", () => process.exit(code));
|
|
108
|
+
}
|
|
109
|
+
}, error => {
|
|
110
|
+
const reason = error instanceof Error ? error.message : "engine-failed";
|
|
111
|
+
const command = process.argv[2];
|
|
112
|
+
const silentHooks = ["stop", "session-end", "pre-tool-use", "post-tool-use"];
|
|
113
|
+
if (command === "session-start" || command === "user-prompt-submit" || (command !== undefined && silentHooks.includes(command))) {
|
|
114
|
+
process.stderr.write(`${JSON.stringify({ event: command, reason: "invalid-input" })}\n`);
|
|
115
|
+
if (command === "session-start" || command === "user-prompt-submit") {
|
|
116
|
+
const hookEventName = command === "session-start" ? "SessionStart" : "UserPromptSubmit";
|
|
117
|
+
process.stdout.write(`${JSON.stringify({ hookSpecificOutput: { hookEventName, additionalContext: "" } })}\n`);
|
|
118
|
+
}
|
|
119
|
+
process.exitCode = 0;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
process.stderr.write(`${reason}\n`);
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACvG,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,KAAK,UAAU,SAAS;IACvB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK;QAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACzE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,C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@@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,mBAAmB,CAAC;AACzC,eAAO,MAAM,OAAO,gBAAgB,CAAC;AACrC,eAAO,MAAM,QAAQ,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAgB,CAAC;AACzC,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AACrC,MAAM,CAAC,MAAM,QAAQ,GAAG,aAAa,CAAC"}
|
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../src/doctor.ts"],"names":[],"mappings":"AAUA,wBAAsB,aAAa,IAAI,OAAO,CAAC,SAAS,GAAG,WAAW,GAAG,aAAa,CAAC,CAUtF;AAsBD,wBAAsB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAmBjE"}
|
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { CODING_SKIN_HOOKS } from "@snoai/memory/coding-skin";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { isOwnedHookCommand, isOwnedPermissionRule, readSettings } from "./install.js";
|
|
6
|
+
import { importDirectory, sidecarDiscoveryPath } from "./paths.js";
|
|
7
|
+
const discoverySchema = z.object({ pid: z.number().int().positive(), port: z.number().int().positive(), token: z.string() });
|
|
8
|
+
const receiptSchema = z.object({ root: z.string() });
|
|
9
|
+
export async function sidecarStatus() {
|
|
10
|
+
try {
|
|
11
|
+
const discovery = discoverySchema.parse(JSON.parse(await readFile(sidecarDiscoveryPath(), "utf8")));
|
|
12
|
+
const response = await fetch(`http://127.0.0.1:${discovery.port}/healthz`, { signal: AbortSignal.timeout(5_000) });
|
|
13
|
+
const body = await response.json();
|
|
14
|
+
return response.ok && body && typeof body === "object" && "status" in body && body.status === "ok"
|
|
15
|
+
? "healthy" : "unhealthy";
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return "unavailable";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function importSummary() {
|
|
22
|
+
let files;
|
|
23
|
+
try {
|
|
24
|
+
files = await readdir(importDirectory());
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
28
|
+
return "absent";
|
|
29
|
+
return "unavailable";
|
|
30
|
+
}
|
|
31
|
+
const states = [];
|
|
32
|
+
for (const file of files.filter(file => file.endsWith(".json")).sort()) {
|
|
33
|
+
try {
|
|
34
|
+
const receipt = receiptSchema.parse(JSON.parse(await readFile(join(importDirectory(), file), "utf8")));
|
|
35
|
+
states.push(`${JSON.stringify(receipt.root)}=present`);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
states.push(`${JSON.stringify(file)}=unparsable`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return states.join(" ") || "absent";
|
|
42
|
+
}
|
|
43
|
+
export async function doctor(configDir) {
|
|
44
|
+
const settings = await readSettings(configDir).catch(() => undefined);
|
|
45
|
+
const hooks = Object.keys(CODING_SKIN_HOOKS).map(event => {
|
|
46
|
+
let state = "absent";
|
|
47
|
+
if (!settings)
|
|
48
|
+
state = "unparsable";
|
|
49
|
+
else if (settings.disableAllHooks)
|
|
50
|
+
state = "disabled";
|
|
51
|
+
else if (settings.hooks?.[event]?.some(group => group.hooks.some(hook => hook.type === "command" && hook.command
|
|
52
|
+
&& isOwnedHookCommand(hook.command, CODING_SKIN_HOOKS[event].subcommand))))
|
|
53
|
+
state = "present";
|
|
54
|
+
return `${event}=${state}`;
|
|
55
|
+
}).join(" ");
|
|
56
|
+
let permission = "unparsable";
|
|
57
|
+
if (settings)
|
|
58
|
+
permission = settings.permissions?.allow?.some(isOwnedPermissionRule) ? "present" : "absent";
|
|
59
|
+
return [
|
|
60
|
+
`sidecar: ${await sidecarStatus()}`,
|
|
61
|
+
`hooks: ${hooks}`,
|
|
62
|
+
`permission rule: ${permission}`,
|
|
63
|
+
`import receipts: ${await importSummary()}`,
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=doctor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../src/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAA2B,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7H,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAErD,MAAM,CAAC,KAAK,UAAU,aAAa;IAClC,IAAI,C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,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,IAAI,UAAU,GAAG,YAAY,CAAC;IAC9B,IAAI,QAAQ;QAAE,UAAU,GAAG,QAAQ,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC3G,OAAO;QACN,YAAY,MAAM,aAAa,EAAE,EAAE;QACnC,UAAU,KAAK,EAAE;QACjB,oBAAoB,UAAU,EAAE;QAChC,oBAAoB,MAAM,aAAa,EAAE,EAAE;KAC3C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CommandResult {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function recallCommand(query: string): Promise<CommandResult>;
|
|
6
|
+
export declare function getCommand(id: string): Promise<CommandResult>;
|
|
7
|
+
export declare function rememberCommand(content: string): Promise<CommandResult>;
|
|
8
|
+
export declare function correctCommand(id: string, content: string): Promise<CommandResult>;
|
|
9
|
+
//# sourceMappingURL=explicit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explicit.d.ts","sourceRoot":"","sources":["../src/explicit.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACb;AAeD,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAiBzE;AAED,wBAAsB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CASnE;AAuBD,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAG7E;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAGxF"}
|
package/dist/explicit.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ContractError } from "@snoai/memory/client";
|
|
2
|
+
import { readRecallSettings } from "./settings.js";
|
|
3
|
+
import { isDegradedConnection, connectMemory } from "./memory-client.js";
|
|
4
|
+
import { manualScope, workspaceRoot } from "./scope.js";
|
|
5
|
+
async function context() {
|
|
6
|
+
let recallLimit;
|
|
7
|
+
try {
|
|
8
|
+
recallLimit = readRecallSettings().explicitLimit;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return { ok: false, reason: error instanceof Error ? error.message : "engine-failed" };
|
|
12
|
+
}
|
|
13
|
+
const project = await workspaceRoot(process.cwd());
|
|
14
|
+
const client = await connectMemory();
|
|
15
|
+
if (isDegradedConnection(client))
|
|
16
|
+
return { ok: false, reason: client.error ?? client.reason };
|
|
17
|
+
return { ok: true, client, project, recallLimit };
|
|
18
|
+
}
|
|
19
|
+
export async function recallCommand(query) {
|
|
20
|
+
if (!query.trim())
|
|
21
|
+
return { ok: false, text: "invalid-input" };
|
|
22
|
+
const current = await context();
|
|
23
|
+
if (!current.ok)
|
|
24
|
+
return { ok: false, text: current.reason };
|
|
25
|
+
const recalled = await current.client.getRecall(query, manualScope(current.project), {
|
|
26
|
+
source: "manual",
|
|
27
|
+
limit: current.recallLimit,
|
|
28
|
+
includeMetadata: true,
|
|
29
|
+
});
|
|
30
|
+
if (recalled.degraded)
|
|
31
|
+
return { ok: false, text: recalled.error ?? recalled.reason };
|
|
32
|
+
if (recalled.toolResult?.isError) {
|
|
33
|
+
const reason = recalled.toolResult.content.map(item => item.text).join("\n");
|
|
34
|
+
return { ok: false, text: reason || "engine-failed" };
|
|
35
|
+
}
|
|
36
|
+
return recalled.contextText
|
|
37
|
+
? { ok: true, text: recalled.contextText }
|
|
38
|
+
: { ok: false, text: "engine-failed" };
|
|
39
|
+
}
|
|
40
|
+
export async function getCommand(id) {
|
|
41
|
+
if (!id.trim())
|
|
42
|
+
return { ok: false, text: "invalid-input" };
|
|
43
|
+
const current = await context();
|
|
44
|
+
if (!current.ok)
|
|
45
|
+
return { ok: false, text: current.reason };
|
|
46
|
+
const inspected = await current.client.inspect({ op: "get", id }, manualScope(current.project));
|
|
47
|
+
if (inspected.degraded)
|
|
48
|
+
return { ok: false, text: inspected.error ?? inspected.reason };
|
|
49
|
+
if (inspected.result.op !== "get" || !inspected.result.entry)
|
|
50
|
+
return { ok: false, text: "not-found" };
|
|
51
|
+
const entry = inspected.result.entry;
|
|
52
|
+
return { ok: true, text: `${entry.id}\n${entry.text}` };
|
|
53
|
+
}
|
|
54
|
+
async function mutateCommand(op) {
|
|
55
|
+
const current = await context();
|
|
56
|
+
if (!current.ok)
|
|
57
|
+
return { ok: false, text: current.reason };
|
|
58
|
+
try {
|
|
59
|
+
const mutated = await current.client.mutate(op, manualScope(current.project));
|
|
60
|
+
if (mutated.degraded)
|
|
61
|
+
return { ok: false, text: mutated.error ?? mutated.reason };
|
|
62
|
+
if (mutated.result.isError) {
|
|
63
|
+
const text = mutated.result.content.map(item => item.text).join("\n");
|
|
64
|
+
const reason = mutated.result.details["errorCode"];
|
|
65
|
+
return { ok: false, text: text || (typeof reason === "string" ? reason : "engine-failed") };
|
|
66
|
+
}
|
|
67
|
+
const id = mutated.result.details["id"];
|
|
68
|
+
return typeof id === "string" && id.length > 0
|
|
69
|
+
? { ok: true, text: id }
|
|
70
|
+
: { ok: false, text: "engine-failed" };
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof ContractError)
|
|
74
|
+
return { ok: false, text: error.message };
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export async function rememberCommand(content) {
|
|
79
|
+
if (!content.trim())
|
|
80
|
+
return { ok: false, text: "invalid-input" };
|
|
81
|
+
return mutateCommand({ op: "store", content, category: "episodic" });
|
|
82
|
+
}
|
|
83
|
+
export async function correctCommand(id, content) {
|
|
84
|
+
if (!id.trim() || !content.trim())
|
|
85
|
+
return { ok: false, text: "invalid-input" };
|
|
86
|
+
return mutateCommand({ op: "correct", id, content });
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=explicit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explicit.js","sourceRoot":"","sources":["../src/explicit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAiB,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAOxD,KAAK,UAAU,OAAO;IAIrB,IAAI,WAAmB,CAAC;IACxB,IAAI,CAAC;QAAC,WAAW,GAAG,kBAAkB,EAAE,CAAC,aAAa,CAAC;IAAC,CAAC;IACzD,OAAO,KAAK,EAAE,CAAC;QAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;IAAC,CAAC;IACzG,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,MAAM,aAAa,EAAE,CAAC;IACrC,IAAI,oBAAoB,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9F,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAa;IAChD,IA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C,IAAI,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IACjE,OAAO,aAAa,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAU,EAAE,OAAe;IAC/D,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IAC/E,OAAO,aAAa,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC"}
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function writeJsonAtomic(path: string, value: unknown): Promise<void>;
|
|
2
|
+
export interface PidFileLock {
|
|
3
|
+
release(): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export declare function acquirePidFileLock(path: string, staleAfterMs: number): Promise<PidFileLock | undefined>;
|
|
6
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAMA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAMjF;AAED,MAAM,WAAW,WAAW;IAC3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAsD7G"}
|