@engram-cli/contracts 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/README.md +12 -0
- package/dist/caps.d.ts +12 -0
- package/dist/caps.d.ts.map +1 -0
- package/dist/caps.js +11 -0
- package/dist/capsule.d.ts +184 -0
- package/dist/capsule.d.ts.map +1 -0
- package/dist/capsule.js +36 -0
- package/dist/helpers.d.ts +17 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +84 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/markdown.d.ts +4 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +57 -0
- package/dist/memory-event.d.ts +47 -0
- package/dist/memory-event.d.ts.map +1 -0
- package/dist/memory-event.js +27 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# packages/contracts
|
|
2
|
+
|
|
3
|
+
Shared **MemoryEvent** + **Capsule** zod schemas, list caps, markdown projector.
|
|
4
|
+
|
|
5
|
+
Canonical field definitions and team API contract: [CONTEXT.md](../CONTEXT.md).
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
npm run build
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Consumed by `backend/` via `"@engram-cli/contracts": "file:../packages/contracts"`.
|
package/dist/caps.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Capsule / ingest list and size caps (canonical). */
|
|
2
|
+
export declare const CAPS: {
|
|
3
|
+
readonly recentFiles: 8;
|
|
4
|
+
readonly errors: 5;
|
|
5
|
+
readonly failedCommands: 5;
|
|
6
|
+
readonly manualNotes: 5;
|
|
7
|
+
readonly summaryBytes: 2048;
|
|
8
|
+
readonly stderrBytes: 2048;
|
|
9
|
+
readonly contentBytes: 2048;
|
|
10
|
+
};
|
|
11
|
+
export declare const CAPSULE_SCHEMA_VERSION = 1;
|
|
12
|
+
//# sourceMappingURL=caps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caps.d.ts","sourceRoot":"","sources":["../src/caps.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,eAAO,MAAM,IAAI;;;;;;;;CAQP,CAAC;AAEX,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
|
package/dist/caps.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Capsule / ingest list and size caps (canonical). */
|
|
2
|
+
export const CAPS = {
|
|
3
|
+
recentFiles: 8,
|
|
4
|
+
errors: 5,
|
|
5
|
+
failedCommands: 5,
|
|
6
|
+
manualNotes: 5,
|
|
7
|
+
summaryBytes: 2048,
|
|
8
|
+
stderrBytes: 2048,
|
|
9
|
+
contentBytes: 2048,
|
|
10
|
+
};
|
|
11
|
+
export const CAPSULE_SCHEMA_VERSION = 1;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CapsuleErrorSchema: z.ZodObject<{
|
|
3
|
+
message: z.ZodString;
|
|
4
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
5
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
message: string;
|
|
8
|
+
file_path?: string | undefined;
|
|
9
|
+
line?: number | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
message: string;
|
|
12
|
+
file_path?: string | undefined;
|
|
13
|
+
line?: number | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
export type CapsuleError = z.infer<typeof CapsuleErrorSchema>;
|
|
16
|
+
export declare const CapsuleFailedCommandSchema: z.ZodObject<{
|
|
17
|
+
command: z.ZodString;
|
|
18
|
+
exit_code: z.ZodNumber;
|
|
19
|
+
stderr_tail: z.ZodOptional<z.ZodString>;
|
|
20
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
command: string;
|
|
23
|
+
exit_code: number;
|
|
24
|
+
stderr_tail?: string | undefined;
|
|
25
|
+
cwd?: string | undefined;
|
|
26
|
+
}, {
|
|
27
|
+
command: string;
|
|
28
|
+
exit_code: number;
|
|
29
|
+
stderr_tail?: string | undefined;
|
|
30
|
+
cwd?: string | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export type CapsuleFailedCommand = z.infer<typeof CapsuleFailedCommandSchema>;
|
|
33
|
+
export declare const CapsuleGitSchema: z.ZodObject<{
|
|
34
|
+
branch: z.ZodOptional<z.ZodString>;
|
|
35
|
+
last_commit: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
branch?: string | undefined;
|
|
38
|
+
last_commit?: string | undefined;
|
|
39
|
+
}, {
|
|
40
|
+
branch?: string | undefined;
|
|
41
|
+
last_commit?: string | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
export type CapsuleGit = z.infer<typeof CapsuleGitSchema>;
|
|
44
|
+
export declare const CapsuleManualNoteSchema: z.ZodObject<{
|
|
45
|
+
kind: z.ZodEnum<["code_selection", "clipboard", "chat_summary"]>;
|
|
46
|
+
text: z.ZodString;
|
|
47
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
48
|
+
chat_label: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
kind: "code_selection" | "clipboard" | "chat_summary";
|
|
51
|
+
text: string;
|
|
52
|
+
file_path?: string | undefined;
|
|
53
|
+
chat_label?: string | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
kind: "code_selection" | "clipboard" | "chat_summary";
|
|
56
|
+
text: string;
|
|
57
|
+
file_path?: string | undefined;
|
|
58
|
+
chat_label?: string | undefined;
|
|
59
|
+
}>;
|
|
60
|
+
export type CapsuleManualNote = z.infer<typeof CapsuleManualNoteSchema>;
|
|
61
|
+
export declare const CapsuleSchema: z.ZodObject<{
|
|
62
|
+
capsule_id: z.ZodString;
|
|
63
|
+
project: z.ZodString;
|
|
64
|
+
created_at: z.ZodString;
|
|
65
|
+
source_ide: z.ZodOptional<z.ZodString>;
|
|
66
|
+
schema_version: z.ZodDefault<z.ZodNumber>;
|
|
67
|
+
summary: z.ZodString;
|
|
68
|
+
recent_files: z.ZodArray<z.ZodString, "many">;
|
|
69
|
+
errors: z.ZodArray<z.ZodObject<{
|
|
70
|
+
message: z.ZodString;
|
|
71
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
72
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
73
|
+
}, "strip", z.ZodTypeAny, {
|
|
74
|
+
message: string;
|
|
75
|
+
file_path?: string | undefined;
|
|
76
|
+
line?: number | undefined;
|
|
77
|
+
}, {
|
|
78
|
+
message: string;
|
|
79
|
+
file_path?: string | undefined;
|
|
80
|
+
line?: number | undefined;
|
|
81
|
+
}>, "many">;
|
|
82
|
+
failed_commands: z.ZodArray<z.ZodObject<{
|
|
83
|
+
command: z.ZodString;
|
|
84
|
+
exit_code: z.ZodNumber;
|
|
85
|
+
stderr_tail: z.ZodOptional<z.ZodString>;
|
|
86
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, "strip", z.ZodTypeAny, {
|
|
88
|
+
command: string;
|
|
89
|
+
exit_code: number;
|
|
90
|
+
stderr_tail?: string | undefined;
|
|
91
|
+
cwd?: string | undefined;
|
|
92
|
+
}, {
|
|
93
|
+
command: string;
|
|
94
|
+
exit_code: number;
|
|
95
|
+
stderr_tail?: string | undefined;
|
|
96
|
+
cwd?: string | undefined;
|
|
97
|
+
}>, "many">;
|
|
98
|
+
git: z.ZodObject<{
|
|
99
|
+
branch: z.ZodOptional<z.ZodString>;
|
|
100
|
+
last_commit: z.ZodOptional<z.ZodString>;
|
|
101
|
+
}, "strip", z.ZodTypeAny, {
|
|
102
|
+
branch?: string | undefined;
|
|
103
|
+
last_commit?: string | undefined;
|
|
104
|
+
}, {
|
|
105
|
+
branch?: string | undefined;
|
|
106
|
+
last_commit?: string | undefined;
|
|
107
|
+
}>;
|
|
108
|
+
manual_notes: z.ZodArray<z.ZodObject<{
|
|
109
|
+
kind: z.ZodEnum<["code_selection", "clipboard", "chat_summary"]>;
|
|
110
|
+
text: z.ZodString;
|
|
111
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
112
|
+
chat_label: z.ZodOptional<z.ZodString>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
kind: "code_selection" | "clipboard" | "chat_summary";
|
|
115
|
+
text: string;
|
|
116
|
+
file_path?: string | undefined;
|
|
117
|
+
chat_label?: string | undefined;
|
|
118
|
+
}, {
|
|
119
|
+
kind: "code_selection" | "clipboard" | "chat_summary";
|
|
120
|
+
text: string;
|
|
121
|
+
file_path?: string | undefined;
|
|
122
|
+
chat_label?: string | undefined;
|
|
123
|
+
}>, "many">;
|
|
124
|
+
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
capsule_id: string;
|
|
126
|
+
project: string;
|
|
127
|
+
created_at: string;
|
|
128
|
+
schema_version: number;
|
|
129
|
+
summary: string;
|
|
130
|
+
recent_files: string[];
|
|
131
|
+
errors: {
|
|
132
|
+
message: string;
|
|
133
|
+
file_path?: string | undefined;
|
|
134
|
+
line?: number | undefined;
|
|
135
|
+
}[];
|
|
136
|
+
failed_commands: {
|
|
137
|
+
command: string;
|
|
138
|
+
exit_code: number;
|
|
139
|
+
stderr_tail?: string | undefined;
|
|
140
|
+
cwd?: string | undefined;
|
|
141
|
+
}[];
|
|
142
|
+
git: {
|
|
143
|
+
branch?: string | undefined;
|
|
144
|
+
last_commit?: string | undefined;
|
|
145
|
+
};
|
|
146
|
+
manual_notes: {
|
|
147
|
+
kind: "code_selection" | "clipboard" | "chat_summary";
|
|
148
|
+
text: string;
|
|
149
|
+
file_path?: string | undefined;
|
|
150
|
+
chat_label?: string | undefined;
|
|
151
|
+
}[];
|
|
152
|
+
source_ide?: string | undefined;
|
|
153
|
+
}, {
|
|
154
|
+
capsule_id: string;
|
|
155
|
+
project: string;
|
|
156
|
+
created_at: string;
|
|
157
|
+
summary: string;
|
|
158
|
+
recent_files: string[];
|
|
159
|
+
errors: {
|
|
160
|
+
message: string;
|
|
161
|
+
file_path?: string | undefined;
|
|
162
|
+
line?: number | undefined;
|
|
163
|
+
}[];
|
|
164
|
+
failed_commands: {
|
|
165
|
+
command: string;
|
|
166
|
+
exit_code: number;
|
|
167
|
+
stderr_tail?: string | undefined;
|
|
168
|
+
cwd?: string | undefined;
|
|
169
|
+
}[];
|
|
170
|
+
git: {
|
|
171
|
+
branch?: string | undefined;
|
|
172
|
+
last_commit?: string | undefined;
|
|
173
|
+
};
|
|
174
|
+
manual_notes: {
|
|
175
|
+
kind: "code_selection" | "clipboard" | "chat_summary";
|
|
176
|
+
text: string;
|
|
177
|
+
file_path?: string | undefined;
|
|
178
|
+
chat_label?: string | undefined;
|
|
179
|
+
}[];
|
|
180
|
+
source_ide?: string | undefined;
|
|
181
|
+
schema_version?: number | undefined;
|
|
182
|
+
}>;
|
|
183
|
+
export type Capsule = z.infer<typeof CapsuleSchema>;
|
|
184
|
+
//# sourceMappingURL=capsule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capsule.d.ts","sourceRoot":"","sources":["../src/capsule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;EAI7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;EAKrC,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E,eAAO,MAAM,gBAAgB;;;;;;;;;EAG3B,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;EAKlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYxB,CAAC;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
package/dist/capsule.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CAPSULE_SCHEMA_VERSION } from "./caps.js";
|
|
3
|
+
export const CapsuleErrorSchema = z.object({
|
|
4
|
+
message: z.string(),
|
|
5
|
+
file_path: z.string().optional(),
|
|
6
|
+
line: z.number().int().nonnegative().optional(),
|
|
7
|
+
});
|
|
8
|
+
export const CapsuleFailedCommandSchema = z.object({
|
|
9
|
+
command: z.string(),
|
|
10
|
+
exit_code: z.number().int(),
|
|
11
|
+
stderr_tail: z.string().optional(),
|
|
12
|
+
cwd: z.string().optional(),
|
|
13
|
+
});
|
|
14
|
+
export const CapsuleGitSchema = z.object({
|
|
15
|
+
branch: z.string().optional(),
|
|
16
|
+
last_commit: z.string().optional(),
|
|
17
|
+
});
|
|
18
|
+
export const CapsuleManualNoteSchema = z.object({
|
|
19
|
+
kind: z.enum(["code_selection", "clipboard", "chat_summary"]),
|
|
20
|
+
text: z.string(),
|
|
21
|
+
file_path: z.string().optional(),
|
|
22
|
+
chat_label: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
export const CapsuleSchema = z.object({
|
|
25
|
+
capsule_id: z.string().min(1),
|
|
26
|
+
project: z.string().min(1),
|
|
27
|
+
created_at: z.string().min(1),
|
|
28
|
+
source_ide: z.string().optional(),
|
|
29
|
+
schema_version: z.number().int().default(CAPSULE_SCHEMA_VERSION),
|
|
30
|
+
summary: z.string(),
|
|
31
|
+
recent_files: z.array(z.string()),
|
|
32
|
+
errors: z.array(CapsuleErrorSchema),
|
|
33
|
+
failed_commands: z.array(CapsuleFailedCommandSchema),
|
|
34
|
+
git: CapsuleGitSchema,
|
|
35
|
+
manual_notes: z.array(CapsuleManualNoteSchema),
|
|
36
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MemoryEvent } from "./memory-event.js";
|
|
2
|
+
/** Project slug → Supermemory containerTag. */
|
|
3
|
+
export declare function projectContainerTag(slug: string): string;
|
|
4
|
+
/** Project name/folder → Engram project slug (strips the `project_` prefix). */
|
|
5
|
+
export declare function normalizeProjectSlug(name: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Successful shell commands worth capturing even when exit code is 0.
|
|
8
|
+
* Kept in contracts so the terminal hook and CLI stay in sync.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SIGNAL_COMMAND_PATTERNS: RegExp[];
|
|
11
|
+
/** True if a successful command is a signal command worth capturing. */
|
|
12
|
+
export declare function isSignalCommand(command: string): boolean;
|
|
13
|
+
/** Truncate a string to at most `maxBytes` UTF-8 bytes. */
|
|
14
|
+
export declare function truncateBytes(text: string, maxBytes: number): string;
|
|
15
|
+
/** Deterministic fact string stored as Supermemory document content. */
|
|
16
|
+
export declare function deterministicFactString(event: MemoryEvent): string;
|
|
17
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,+CAA+C;AAC/C,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQxD;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,EAU3C,CAAC;AAEF,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGxD;AAMD,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOpE;AAED,wEAAwE;AACxE,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAkClE"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CAPS } from "./caps.js";
|
|
2
|
+
/** Project slug → Supermemory containerTag. */
|
|
3
|
+
export function projectContainerTag(slug) {
|
|
4
|
+
const normalized = slug
|
|
5
|
+
.trim()
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.replace(/[^a-z0-9._-]+/g, "_")
|
|
8
|
+
.replace(/^_+|_+$/g, "")
|
|
9
|
+
.slice(0, 80);
|
|
10
|
+
return `project_${normalized || "unknown"}`;
|
|
11
|
+
}
|
|
12
|
+
/** Project name/folder → Engram project slug (strips the `project_` prefix). */
|
|
13
|
+
export function normalizeProjectSlug(name) {
|
|
14
|
+
return projectContainerTag(name).replace(/^project_/, "") || "unknown";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Successful shell commands worth capturing even when exit code is 0.
|
|
18
|
+
* Kept in contracts so the terminal hook and CLI stay in sync.
|
|
19
|
+
*/
|
|
20
|
+
export const SIGNAL_COMMAND_PATTERNS = [
|
|
21
|
+
/^npm\s+(?:test|run\s+(?:test|build|deploy|check|lint|typecheck))/i,
|
|
22
|
+
/^pnpm\s+(?:test|run\s+(?:test|build|deploy|check|lint|typecheck))/i,
|
|
23
|
+
/^yarn\s+(?:test|run\s+(?:test|build|deploy|check|lint|typecheck))/i,
|
|
24
|
+
/^make\b/i,
|
|
25
|
+
/^cargo\s+(?:build|test|check|run)\b/i,
|
|
26
|
+
/^go\s+(?:build|test|run)\b/i,
|
|
27
|
+
/^docker\s+(?:build|compose\s+build|push)\b/i,
|
|
28
|
+
/^(?:pytest|vitest|jest|mocha|ava|tap)\b/i,
|
|
29
|
+
/^\.\/build\.sh\b/i,
|
|
30
|
+
];
|
|
31
|
+
/** True if a successful command is a signal command worth capturing. */
|
|
32
|
+
export function isSignalCommand(command) {
|
|
33
|
+
const firstLine = command.split("\n")[0]?.trim() ?? command;
|
|
34
|
+
return SIGNAL_COMMAND_PATTERNS.some((re) => re.test(firstLine));
|
|
35
|
+
}
|
|
36
|
+
function utf8ByteLength(text) {
|
|
37
|
+
return new TextEncoder().encode(text).length;
|
|
38
|
+
}
|
|
39
|
+
/** Truncate a string to at most `maxBytes` UTF-8 bytes. */
|
|
40
|
+
export function truncateBytes(text, maxBytes) {
|
|
41
|
+
if (utf8ByteLength(text) <= maxBytes)
|
|
42
|
+
return text;
|
|
43
|
+
let end = Math.min(text.length, maxBytes);
|
|
44
|
+
while (end > 0 && utf8ByteLength(text.slice(0, end)) > maxBytes) {
|
|
45
|
+
end -= 1;
|
|
46
|
+
}
|
|
47
|
+
return `${text.slice(0, end)}…`;
|
|
48
|
+
}
|
|
49
|
+
/** Deterministic fact string stored as Supermemory document content. */
|
|
50
|
+
export function deterministicFactString(event) {
|
|
51
|
+
const raw = (() => {
|
|
52
|
+
switch (event.event_type) {
|
|
53
|
+
case "file_open":
|
|
54
|
+
return `opened: ${event.file_path ?? event.content}`;
|
|
55
|
+
case "file_save":
|
|
56
|
+
return `saved: ${event.file_path ?? event.content}`;
|
|
57
|
+
case "error": {
|
|
58
|
+
const loc = event.file_path
|
|
59
|
+
? `${event.file_path}${event.line != null ? `:${event.line}` : ""}`
|
|
60
|
+
: undefined;
|
|
61
|
+
return loc ? `error: ${event.content} in ${loc}` : `error: ${event.content}`;
|
|
62
|
+
}
|
|
63
|
+
case "command": {
|
|
64
|
+
const code = event.exit_code ?? 0;
|
|
65
|
+
return `cmd (exit ${code}): ${event.content}`;
|
|
66
|
+
}
|
|
67
|
+
case "branch_switch":
|
|
68
|
+
return `branch: ${event.content}`;
|
|
69
|
+
case "commit":
|
|
70
|
+
return `commit: ${event.content}`;
|
|
71
|
+
case "code_selection":
|
|
72
|
+
return `selection: ${event.content}`;
|
|
73
|
+
case "clipboard":
|
|
74
|
+
return `clipboard: ${event.content}`;
|
|
75
|
+
case "chat_summary": {
|
|
76
|
+
const label = event.chat_label ? `[${event.chat_label}]` : "";
|
|
77
|
+
return `chat_summary${label}: ${event.content}`;
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
return event.content;
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
return truncateBytes(raw, CAPS.contentBytes);
|
|
84
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { CAPS, CAPSULE_SCHEMA_VERSION } from "./caps.js";
|
|
2
|
+
export { MemorySourceSchema, MemoryEventTypeSchema, MemoryEventSchema, type MemorySource, type MemoryEventType, type MemoryEvent, } from "./memory-event.js";
|
|
3
|
+
export { CapsuleErrorSchema, CapsuleFailedCommandSchema, CapsuleGitSchema, CapsuleManualNoteSchema, CapsuleSchema, type CapsuleError, type CapsuleFailedCommand, type CapsuleGit, type CapsuleManualNote, type Capsule, } from "./capsule.js";
|
|
4
|
+
export { projectContainerTag, normalizeProjectSlug, truncateBytes, deterministicFactString, isSignalCommand, SIGNAL_COMMAND_PATTERNS, } from "./helpers.js";
|
|
5
|
+
export { toMarkdown } from "./markdown.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,eAAe,EACf,uBAAuB,GACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CAPS, CAPSULE_SCHEMA_VERSION } from "./caps.js";
|
|
2
|
+
export { MemorySourceSchema, MemoryEventTypeSchema, MemoryEventSchema, } from "./memory-event.js";
|
|
3
|
+
export { CapsuleErrorSchema, CapsuleFailedCommandSchema, CapsuleGitSchema, CapsuleManualNoteSchema, CapsuleSchema, } from "./capsule.js";
|
|
4
|
+
export { projectContainerTag, normalizeProjectSlug, truncateBytes, deterministicFactString, isSignalCommand, SIGNAL_COMMAND_PATTERNS, } from "./helpers.js";
|
|
5
|
+
export { toMarkdown } from "./markdown.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAwDnD"}
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Project Markdown projection of a capsule (ENGRAM_CONTEXT.md). */
|
|
2
|
+
export function toMarkdown(capsule) {
|
|
3
|
+
const lines = [
|
|
4
|
+
`# Engram Context — ${capsule.project}`,
|
|
5
|
+
"",
|
|
6
|
+
`capsule_id: ${capsule.capsule_id}`,
|
|
7
|
+
`created_at: ${capsule.created_at}`,
|
|
8
|
+
`schema_version: ${capsule.schema_version}`,
|
|
9
|
+
];
|
|
10
|
+
if (capsule.source_ide)
|
|
11
|
+
lines.push(`source_ide: ${capsule.source_ide}`);
|
|
12
|
+
lines.push("", "## Summary", "", capsule.summary || "(empty)", "");
|
|
13
|
+
if (capsule.recent_files.length) {
|
|
14
|
+
lines.push("## Recent files", "");
|
|
15
|
+
for (const f of capsule.recent_files)
|
|
16
|
+
lines.push(`- ${f}`);
|
|
17
|
+
lines.push("");
|
|
18
|
+
}
|
|
19
|
+
if (capsule.errors.length) {
|
|
20
|
+
lines.push("## Errors", "");
|
|
21
|
+
for (const e of capsule.errors) {
|
|
22
|
+
const loc = e.file_path
|
|
23
|
+
? `${e.file_path}${e.line != null ? `:${e.line}` : ""}`
|
|
24
|
+
: "";
|
|
25
|
+
lines.push(`- ${loc ? `${loc} — ` : ""}${e.message}`);
|
|
26
|
+
}
|
|
27
|
+
lines.push("");
|
|
28
|
+
}
|
|
29
|
+
if (capsule.failed_commands.length) {
|
|
30
|
+
lines.push("## Failed commands", "");
|
|
31
|
+
for (const c of capsule.failed_commands) {
|
|
32
|
+
lines.push(`- \`${c.command}\` (exit ${c.exit_code})`);
|
|
33
|
+
if (c.stderr_tail)
|
|
34
|
+
lines.push(` stderr: ${c.stderr_tail}`);
|
|
35
|
+
}
|
|
36
|
+
lines.push("");
|
|
37
|
+
}
|
|
38
|
+
if (capsule.git.branch || capsule.git.last_commit) {
|
|
39
|
+
lines.push("## Git", "");
|
|
40
|
+
if (capsule.git.branch)
|
|
41
|
+
lines.push(`- branch: ${capsule.git.branch}`);
|
|
42
|
+
if (capsule.git.last_commit)
|
|
43
|
+
lines.push(`- last_commit: ${capsule.git.last_commit}`);
|
|
44
|
+
lines.push("");
|
|
45
|
+
}
|
|
46
|
+
if (capsule.manual_notes.length) {
|
|
47
|
+
lines.push("## Manual notes", "");
|
|
48
|
+
for (const n of capsule.manual_notes) {
|
|
49
|
+
const prefix = n.chat_label
|
|
50
|
+
? `[${n.kind}:${n.chat_label}]`
|
|
51
|
+
: `[${n.kind}]`;
|
|
52
|
+
lines.push(`- ${prefix} ${n.text}`);
|
|
53
|
+
}
|
|
54
|
+
lines.push("");
|
|
55
|
+
}
|
|
56
|
+
return lines.join("\n");
|
|
57
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const MemorySourceSchema: z.ZodEnum<["vscode", "terminal", "git", "manual"]>;
|
|
3
|
+
export type MemorySource = z.infer<typeof MemorySourceSchema>;
|
|
4
|
+
export declare const MemoryEventTypeSchema: z.ZodEnum<["file_open", "code_selection", "error", "file_save", "command", "branch_switch", "commit", "clipboard", "chat_summary"]>;
|
|
5
|
+
export type MemoryEventType = z.infer<typeof MemoryEventTypeSchema>;
|
|
6
|
+
export declare const MemoryEventSchema: z.ZodObject<{
|
|
7
|
+
source: z.ZodEnum<["vscode", "terminal", "git", "manual"]>;
|
|
8
|
+
event_type: z.ZodEnum<["file_open", "code_selection", "error", "file_save", "command", "branch_switch", "commit", "clipboard", "chat_summary"]>;
|
|
9
|
+
content: z.ZodString;
|
|
10
|
+
project: z.ZodString;
|
|
11
|
+
timestamp: z.ZodString;
|
|
12
|
+
session_id: z.ZodString;
|
|
13
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
14
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
15
|
+
exit_code: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
ide: z.ZodOptional<z.ZodString>;
|
|
17
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
chat_label: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
project: string;
|
|
21
|
+
source: "git" | "vscode" | "terminal" | "manual";
|
|
22
|
+
event_type: "command" | "code_selection" | "clipboard" | "chat_summary" | "file_open" | "error" | "file_save" | "branch_switch" | "commit";
|
|
23
|
+
content: string;
|
|
24
|
+
timestamp: string;
|
|
25
|
+
session_id: string;
|
|
26
|
+
file_path?: string | undefined;
|
|
27
|
+
line?: number | undefined;
|
|
28
|
+
exit_code?: number | undefined;
|
|
29
|
+
cwd?: string | undefined;
|
|
30
|
+
chat_label?: string | undefined;
|
|
31
|
+
ide?: string | undefined;
|
|
32
|
+
}, {
|
|
33
|
+
project: string;
|
|
34
|
+
source: "git" | "vscode" | "terminal" | "manual";
|
|
35
|
+
event_type: "command" | "code_selection" | "clipboard" | "chat_summary" | "file_open" | "error" | "file_save" | "branch_switch" | "commit";
|
|
36
|
+
content: string;
|
|
37
|
+
timestamp: string;
|
|
38
|
+
session_id: string;
|
|
39
|
+
file_path?: string | undefined;
|
|
40
|
+
line?: number | undefined;
|
|
41
|
+
exit_code?: number | undefined;
|
|
42
|
+
cwd?: string | undefined;
|
|
43
|
+
chat_label?: string | undefined;
|
|
44
|
+
ide?: string | undefined;
|
|
45
|
+
}>;
|
|
46
|
+
export type MemoryEvent = z.infer<typeof MemoryEventSchema>;
|
|
47
|
+
//# sourceMappingURL=memory-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-event.d.ts","sourceRoot":"","sources":["../src/memory-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,kBAAkB,oDAAkD,CAAC;AAClF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,qBAAqB,qIAUhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAa5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const MemorySourceSchema = z.enum(["vscode", "terminal", "git", "manual"]);
|
|
3
|
+
export const MemoryEventTypeSchema = z.enum([
|
|
4
|
+
"file_open",
|
|
5
|
+
"code_selection",
|
|
6
|
+
"error",
|
|
7
|
+
"file_save",
|
|
8
|
+
"command",
|
|
9
|
+
"branch_switch",
|
|
10
|
+
"commit",
|
|
11
|
+
"clipboard",
|
|
12
|
+
"chat_summary",
|
|
13
|
+
]);
|
|
14
|
+
export const MemoryEventSchema = z.object({
|
|
15
|
+
source: MemorySourceSchema,
|
|
16
|
+
event_type: MemoryEventTypeSchema,
|
|
17
|
+
content: z.string().min(1),
|
|
18
|
+
project: z.string().min(1),
|
|
19
|
+
timestamp: z.string().min(1),
|
|
20
|
+
session_id: z.string().min(1),
|
|
21
|
+
file_path: z.string().optional(),
|
|
22
|
+
cwd: z.string().optional(),
|
|
23
|
+
exit_code: z.number().int().optional(),
|
|
24
|
+
ide: z.string().optional(),
|
|
25
|
+
line: z.number().int().nonnegative().optional(),
|
|
26
|
+
chat_label: z.string().optional(),
|
|
27
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@engram-cli/contracts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared schemas and helpers for Engram",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
16
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"zod": "^3.25.76"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.8.3"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"engram",
|
|
35
|
+
"contracts",
|
|
36
|
+
"zod"
|
|
37
|
+
]
|
|
38
|
+
}
|