@vertesia/memory-cli 0.24.0-dev.202601221707

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 ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Composable
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @vertesia/memory-cli
2
+
3
+ A command-line tool for building and managing Vertesia memory packs. Memory packs are archives containing structured data for LLM context.
4
+
5
+ ## Features
6
+
7
+ - **Build Memory Packs**: Create memory archives from recipe scripts
8
+ - **Export Data**: Extract JSON objects from memory packs using mappings
9
+ - **Gzip Compression**: Optionally compress output files
10
+ - **Custom Variables**: Pass variables to recipe scripts via command line
11
+
12
+ ## Requirements
13
+
14
+ Node.js version 18 or higher is required.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install -g @vertesia/memory-cli
20
+ # or
21
+ pnpm add -g @vertesia/memory-cli
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Build a Memory Pack
27
+
28
+ Build a memory pack from a recipe script:
29
+
30
+ ```bash
31
+ memo build <recipe>
32
+ ```
33
+
34
+ #### Options
35
+
36
+ | Option | Description |
37
+ |--------|-------------|
38
+ | `-o, --out <file>` | Output file (default: `memory.tar`) |
39
+ | `-z, --gzip` | Compress output with gzip |
40
+ | `-i, --indent <spaces>` | JSON indentation (default: 2) |
41
+ | `-q, --quiet` | Suppress console output |
42
+ | `-t, --test` | Test recipe without building |
43
+
44
+ #### Passing Variables
45
+
46
+ Pass custom variables to your recipe script using `--var-<name>`:
47
+
48
+ ```bash
49
+ memo build recipe.ts --var-version 1.0.0 --var-env production
50
+ ```
51
+
52
+ Variables are available in your recipe script via the `vars` object.
53
+
54
+ ### Export from Memory Pack
55
+
56
+ Export a JSON object from a memory pack using a mapping:
57
+
58
+ ```bash
59
+ memo export <pack> --map <mapping>
60
+ ```
61
+
62
+ #### Examples
63
+
64
+ ```bash
65
+ # Export with inline JSON mapping
66
+ memo export memory.tar --map '{"title": "$.metadata.title", "content": "$.files[0].content"}'
67
+
68
+ # Export with mapping file
69
+ memo export memory.tar --map @mapping.json
70
+
71
+ # Export with custom indentation
72
+ memo export memory.tar --map @mapping.json --indent 4
73
+ ```
74
+
75
+ ## Recipe Scripts
76
+
77
+ Recipe scripts are TypeScript files that define how to build a memory pack. They use the `@vertesia/memory` API to collect and structure data.
78
+
79
+ Example recipe (`recipe.ts`):
80
+
81
+ ```typescript
82
+ import { MemoryBuilder } from '@vertesia/memory';
83
+
84
+ const builder = new MemoryBuilder();
85
+
86
+ // Add files, metadata, and structured data
87
+ builder.addFile('README.md', readFileSync('README.md'));
88
+ builder.setMetadata({ version: vars.version });
89
+
90
+ export default builder;
91
+ ```
92
+
93
+ ## API
94
+
95
+ The CLI can also be used programmatically:
96
+
97
+ ```typescript
98
+ import { setupMemoCommand } from '@vertesia/memory-cli';
99
+ import { Command } from 'commander';
100
+
101
+ const program = new Command();
102
+ setupMemoCommand(program);
103
+ program.parse();
104
+ ```
105
+
106
+ ## Documentation
107
+
108
+ See [Vertesia Documentation](https://docs.vertesiahq.com)
109
+
110
+ ## License
111
+
112
+ Apache-2.0
package/bin/memo.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import '../lib/cli.js'
package/lib/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/lib/cli.js ADDED
@@ -0,0 +1,20 @@
1
+ import { program } from 'commander';
2
+ import { setupMemoCommand } from './command.js';
3
+ import { dirname } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { readFileSync } from 'fs';
6
+ const packageDir = dirname(dirname(fileURLToPath(import.meta.url)));
7
+ let _package;
8
+ function getPackage() {
9
+ if (_package === undefined) {
10
+ _package = JSON.parse(readFileSync(`${packageDir}/package.json`, 'utf8'));
11
+ }
12
+ return _package;
13
+ }
14
+ function getVersion() {
15
+ return getPackage().version;
16
+ }
17
+ program.version(getVersion());
18
+ setupMemoCommand(program);
19
+ program.parse();
20
+ //# sourceMappingURL=cli.js.map
package/lib/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAElC,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAEpE,IAAI,QAAa,CAAC;AAClB,SAAS,UAAU;IACf,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,UAAU,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC;AACD,SAAS,UAAU;IACf,OAAO,UAAU,EAAE,CAAC,OAAO,CAAC;AAChC,CAAC;AAED,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAC9B,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAC1B,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function setupMemoCommand(command: Command, publish?: (file: string, name: string) => Promise<string>): Command;
3
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,WA8B3G"}
package/lib/command.js ADDED
@@ -0,0 +1,101 @@
1
+ import { loadMemoryPack } from '@vertesia/memory';
2
+ import { build } from '@vertesia/memory-commands';
3
+ import { Command } from 'commander';
4
+ import { readFile } from 'fs/promises';
5
+ import { dirname } from 'path';
6
+ import url from 'url';
7
+ export function setupMemoCommand(command, publish) {
8
+ const buildCmd = new Command("build").description("Build a memory pack from a recipe script.");
9
+ buildCmd.allowUnknownOption()
10
+ .option('-i, --indent <spaces>', 'The number of spaces to indent the JSON result. A indentation of 2 is used by default.')
11
+ .option('-q, --quiet', 'Do not log anything to the console.')
12
+ .option('-z, --gzip', 'Compress the output file using gzip.')
13
+ .option('-o, --out <file>', 'The output file. Defaults to "memory.tar".')
14
+ .option('-t, --test', 'Test the memory script without building it.')
15
+ .argument('<recipe>', 'The recipe script to build the memory from.')
16
+ .action((_arg, options, command) => {
17
+ memoAction(command, { ...options, publish }).catch((err) => {
18
+ console.error("Failed to run command: ", err);
19
+ process.exit(1);
20
+ });
21
+ });
22
+ const exportCmd = new Command("export").description("Export a JSON object from the memory pack given a mapping.");
23
+ exportCmd.option('--map <mapping>', 'The mapping to use. An inline JSON object or a path to a JSOn file prefixed with @')
24
+ .option('-i, --indent <spaces>', 'The number of spaces to indent the JSON result. No indentation is done by default.')
25
+ .argument('<pack>', 'The uncompressed memory pack to use (i.e. a .tar file).')
26
+ .action((arg, options, command) => {
27
+ exportAction(command, arg, options).catch((err) => {
28
+ console.error("Failed to run command: ", err);
29
+ process.exit(1);
30
+ });
31
+ });
32
+ command.addCommand(buildCmd);
33
+ command.addCommand(exportCmd);
34
+ return command;
35
+ }
36
+ function memoAction(command, options) {
37
+ const { script, vars } = parseArgs(command.args);
38
+ if (options.indent) {
39
+ options.indent = parseInt(options.indent);
40
+ }
41
+ if (!options.transpileDir) {
42
+ options.transpileDir = dirname(url.fileURLToPath(import.meta.url));
43
+ }
44
+ return build(script, { ...options, vars });
45
+ }
46
+ /**
47
+ * We take all --var-xxx options and return them as an object to be passed as the `vars` variable to the script
48
+ * @param args
49
+ */
50
+ function parseArgs(args) {
51
+ if (!args.length) {
52
+ console.error("No recipe script was provided.");
53
+ process.exit(1);
54
+ }
55
+ let script;
56
+ const vars = {};
57
+ let lastKey;
58
+ let lastCommittedOption;
59
+ for (const arg of args) {
60
+ if (arg.startsWith('--var-')) {
61
+ if (lastKey) {
62
+ vars[lastKey] = true;
63
+ }
64
+ lastKey = arg.substring(6);
65
+ }
66
+ else if (lastKey) {
67
+ vars[lastKey] = arg;
68
+ lastCommittedOption = lastKey;
69
+ lastKey = undefined;
70
+ }
71
+ else if (script) {
72
+ console.error(`Ambiguous command line arguments. Multiple recipe scripts found: ${script}, ${arg}`);
73
+ process.exit(1);
74
+ }
75
+ else {
76
+ script = arg;
77
+ }
78
+ }
79
+ if (!script) {
80
+ if (!lastCommittedOption) {
81
+ console.error("Ambiguous command line arguments. No recipe script was found.");
82
+ process.exit(1);
83
+ }
84
+ else {
85
+ script = vars[lastCommittedOption];
86
+ vars[lastCommittedOption] = true;
87
+ }
88
+ }
89
+ return { script, vars };
90
+ }
91
+ async function exportAction(_command, packFile, options) {
92
+ let mapParam = options.map;
93
+ if (mapParam.startsWith('@')) {
94
+ mapParam = await readFile(mapParam.substring(1), "utf-8");
95
+ }
96
+ const mapping = JSON.parse(mapParam);
97
+ const pack = await loadMemoryPack(packFile);
98
+ const obj = await pack.exportObject(mapping);
99
+ console.log(JSON.stringify(obj, null, options.indent || 2));
100
+ }
101
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,UAAU,gBAAgB,CAAC,OAAgB,EAAE,OAAyD;IACxG,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,2CAA2C,CAAC,CAAC;IAC/F,QAAQ,CAAC,kBAAkB,EAAE;SACxB,MAAM,CAAC,uBAAuB,EAAE,wFAAwF,CAAC;SACzH,MAAM,CAAC,aAAa,EAAE,qCAAqC,CAAC;SAC5D,MAAM,CAAC,YAAY,EAAE,sCAAsC,CAAC;SAC5D,MAAM,CAAC,kBAAkB,EAAE,4CAA4C,CAAC;SACxE,MAAM,CAAC,YAAY,EAAE,6CAA6C,CAAC;SACnE,QAAQ,CAAC,UAAU,EAAE,6CAA6C,CAAC;SACnE,MAAM,CAAC,CAAC,IAAY,EAAE,OAA4B,EAAE,OAAgB,EAAE,EAAE;QACrE,UAAU,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;YAC9D,OAAO,CAAC,KAAK,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C,CAAC;YAC/E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACJ,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACnC,IAAI,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC;QACrC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,QAAiB,EAAE,QAAgB,EAAE,OAA4B;IACzF,IAAI,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAC3B,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,QAAQ,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,OAAO,GAAwB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { setupMemoCommand } from './command.js';
2
+ export { setupMemoCommand };
3
+ //# 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,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { setupMemoCommand } from './command.js';
2
+ export { setupMemoCommand };
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@vertesia/memory-cli",
3
+ "description": "Vertesia memory builder CLI",
4
+ "version": "0.24.0-dev.202601221707",
5
+ "type": "module",
6
+ "bin": {
7
+ "memo": "./bin/memo.js"
8
+ },
9
+ "main": "./lib/index.js",
10
+ "types": "./lib/index.d.ts",
11
+ "files": [
12
+ "lib",
13
+ "bin"
14
+ ],
15
+ "license": "Apache-2.0",
16
+ "homepage": "https://docs.vertesiahq.com",
17
+ "keywords": [
18
+ "vertesia",
19
+ "memory",
20
+ "cli",
21
+ "llm",
22
+ "ai",
23
+ "context",
24
+ "typescript"
25
+ ],
26
+ "dependencies": {
27
+ "commander": "^14.0.2",
28
+ "@vertesia/memory": "0.24.0-dev.202601221707",
29
+ "@vertesia/memory-commands": "0.24.0-dev.202601221707"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^22.19.2",
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^4.0.16"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/vertesia/composableai.git",
39
+ "directory": "packages/memory-cli"
40
+ },
41
+ "scripts": {
42
+ "eslint": "eslint './src/**/*.{jsx,js,tsx,ts}'",
43
+ "build": "rm -rf ./lib ./tsconfig.tsbuildinfo && tsc --build",
44
+ "clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo"
45
+ }
46
+ }