@amalgm/tools 0.1.7-preview.37556891038 → 0.1.7-preview.44182693708
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/PURPOSE.md +16 -15
- package/README.md +32 -33
- package/dist/artifacts.d.ts +9 -31
- package/dist/artifacts.js +8 -45
- package/dist/http.d.ts +5 -5
- package/dist/http.js +1 -6
- package/dist/index.d.ts +2 -6
- package/dist/index.js +1 -4
- package/dist/mcp-server.d.ts +5 -7
- package/dist/mcp-server.js +4 -26
- package/dist/results.d.ts +1 -4
- package/dist/results.js +1 -9
- package/dist/store.d.ts +0 -3
- package/dist/store.js +0 -13
- package/dist/tool-files.d.ts +40 -0
- package/dist/tool-files.js +136 -0
- package/dist/toolbox-deployments.d.ts +0 -3
- package/dist/toolbox-deployments.js +0 -17
- package/dist/toolbox-projection.d.ts +9 -5
- package/dist/toolbox-projection.js +27 -18
- package/dist/toolbox.d.ts +2 -1
- package/dist/toolbox.js +9 -12
- package/dist/types.d.ts +7 -11
- package/docs/SHELL_INTEGRATION.md +21 -7
- package/package.json +7 -14
- package/skills/tools/SKILL.md +28 -41
- package/dist/artifact-files.d.ts +0 -30
- package/dist/artifact-files.js +0 -123
- package/dist/bin/mcp.d.ts +0 -2
- package/dist/bin/mcp.js +0 -13
- package/dist/bin/tools.d.ts +0 -2
- package/dist/bin/tools.js +0 -3
- package/dist/cli.d.ts +0 -18
- package/dist/cli.js +0 -125
- package/dist/commands.d.ts +0 -27
- package/dist/commands.js +0 -16
- package/dist/deployment-files.d.ts +0 -10
- package/dist/deployment-files.js +0 -38
- package/dist/module.d.ts +0 -3
- package/dist/module.js +0 -22
- package/dist/toolbox-state-dir.d.ts +0 -2
- package/dist/toolbox-state-dir.js +0 -18
package/dist/artifact-files.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { ToolboxIndexDocument } from './artifacts.js';
|
|
2
|
-
import type { ActionRecord, Catalog, ToolRecord } from './types.js';
|
|
3
|
-
declare class ArtifactFiles {
|
|
4
|
-
private readonly directory;
|
|
5
|
-
constructor(directory: string);
|
|
6
|
-
private file;
|
|
7
|
-
writeTool(entry: {
|
|
8
|
-
tool: ToolRecord;
|
|
9
|
-
actions: ActionRecord[];
|
|
10
|
-
}): string;
|
|
11
|
-
removeTool(toolId: string): void;
|
|
12
|
-
writeIndex(catalog: Catalog): void;
|
|
13
|
-
readIndex(): ToolboxIndexDocument | null;
|
|
14
|
-
/** Give every persisted user tool its portable artifact and refresh the
|
|
15
|
-
* index. Additive only: a file for a tool this catalog does not know is
|
|
16
|
-
* never deleted here — removal or snapshot hydration is explicit. */
|
|
17
|
-
materialize(catalog: Catalog): void;
|
|
18
|
-
/** Execute the legacy `toolbox.json` migration plan: per-tool artifacts
|
|
19
|
-
* first, then the index, and only then the rename that retires the
|
|
20
|
-
* aggregate file. */
|
|
21
|
-
migrateLegacy(): boolean;
|
|
22
|
-
/** Read every valid per-tool artifact back. A document only counts when
|
|
23
|
-
* its file carries the exact name its tool id demands — a copied or
|
|
24
|
-
* renamed file never smuggles in a second identity. */
|
|
25
|
-
read(): {
|
|
26
|
-
tools: Record<string, ToolRecord>;
|
|
27
|
-
toolActions: Record<string, ActionRecord>;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export { ArtifactFiles };
|
package/dist/artifact-files.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { LEGACY_TOOLBOX_FILE_NAME, TOOLBOX_INDEX_FILE_NAME, artifactDocument, catalogIndexDocument, isToolArtifactDocument, legacyMigrationPlan, safeToolId, userArtifactFileName, } from './artifacts.js';
|
|
4
|
-
/**
|
|
5
|
-
* The host adapter for current compatibility projections: it executes the
|
|
6
|
-
* pure documents and plans from `artifacts.ts` against one local state
|
|
7
|
-
* directory. Writes are atomic
|
|
8
|
-
* (tmp file + rename) and skipped when the bytes are unchanged, matching
|
|
9
|
-
* Engine `lib/storage.js`.
|
|
10
|
-
*
|
|
11
|
-
* DELIBERATE DEVIATION: Engine keeps the index and the legacy backup
|
|
12
|
-
* beside — not inside — its cloud-backed toolbox folder. A standalone
|
|
13
|
-
* state directory already holds the local `tools.db` cache, so both files
|
|
14
|
-
* live inside it, next to the database.
|
|
15
|
-
*/
|
|
16
|
-
function readJson(file) {
|
|
17
|
-
try {
|
|
18
|
-
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function writeJsonIfChanged(file, value) {
|
|
25
|
-
if (JSON.stringify(readJson(file)) === JSON.stringify(value))
|
|
26
|
-
return;
|
|
27
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
28
|
-
const temporary = `${file}.tmp`;
|
|
29
|
-
fs.writeFileSync(temporary, JSON.stringify(value, null, 2));
|
|
30
|
-
fs.renameSync(temporary, file);
|
|
31
|
-
}
|
|
32
|
-
class ArtifactFiles {
|
|
33
|
-
directory;
|
|
34
|
-
constructor(directory) {
|
|
35
|
-
this.directory = directory;
|
|
36
|
-
}
|
|
37
|
-
file(name) { return path.join(this.directory, name); }
|
|
38
|
-
writeTool(entry) {
|
|
39
|
-
const target = this.file(userArtifactFileName(entry.tool.id));
|
|
40
|
-
writeJsonIfChanged(target, artifactDocument(entry));
|
|
41
|
-
return target;
|
|
42
|
-
}
|
|
43
|
-
removeTool(toolId) {
|
|
44
|
-
try {
|
|
45
|
-
fs.unlinkSync(this.file(userArtifactFileName(toolId)));
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
if (error.code !== 'ENOENT')
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
writeIndex(catalog) {
|
|
53
|
-
writeJsonIfChanged(this.file(TOOLBOX_INDEX_FILE_NAME), catalogIndexDocument(catalog));
|
|
54
|
-
}
|
|
55
|
-
readIndex() {
|
|
56
|
-
const value = readJson(this.file(TOOLBOX_INDEX_FILE_NAME));
|
|
57
|
-
if (!value || value.version !== 1 || !value.tools || typeof value.tools !== 'object'
|
|
58
|
-
|| !value.toolActions || typeof value.toolActions !== 'object')
|
|
59
|
-
return null;
|
|
60
|
-
return value;
|
|
61
|
-
}
|
|
62
|
-
/** Give every persisted user tool its portable artifact and refresh the
|
|
63
|
-
* index. Additive only: a file for a tool this catalog does not know is
|
|
64
|
-
* never deleted here — removal or snapshot hydration is explicit. */
|
|
65
|
-
materialize(catalog) {
|
|
66
|
-
for (const tool of catalog.tools) {
|
|
67
|
-
if (tool.origin === 'system')
|
|
68
|
-
continue;
|
|
69
|
-
this.writeTool({ tool, actions: catalog.actions.filter((action) => action.toolId === tool.id) });
|
|
70
|
-
}
|
|
71
|
-
this.writeIndex(catalog);
|
|
72
|
-
}
|
|
73
|
-
/** Execute the legacy `toolbox.json` migration plan: per-tool artifacts
|
|
74
|
-
* first, then the index, and only then the rename that retires the
|
|
75
|
-
* aggregate file. */
|
|
76
|
-
migrateLegacy() {
|
|
77
|
-
const legacy = this.file(LEGACY_TOOLBOX_FILE_NAME);
|
|
78
|
-
if (!fs.existsSync(legacy))
|
|
79
|
-
return false;
|
|
80
|
-
const plan = legacyMigrationPlan(readJson(legacy));
|
|
81
|
-
if (!plan.migrated || !plan.rename)
|
|
82
|
-
return false;
|
|
83
|
-
for (const write of plan.files)
|
|
84
|
-
writeJsonIfChanged(this.file(write.fileName), write.document);
|
|
85
|
-
if (plan.index)
|
|
86
|
-
writeJsonIfChanged(this.file(TOOLBOX_INDEX_FILE_NAME), plan.index);
|
|
87
|
-
let target = this.file(plan.rename.to);
|
|
88
|
-
if (fs.existsSync(target))
|
|
89
|
-
target = this.file(`toolbox.legacy-${Date.now()}.json`);
|
|
90
|
-
fs.renameSync(legacy, target);
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
/** Read every valid per-tool artifact back. A document only counts when
|
|
94
|
-
* its file carries the exact name its tool id demands — a copied or
|
|
95
|
-
* renamed file never smuggles in a second identity. */
|
|
96
|
-
read() {
|
|
97
|
-
const tools = {};
|
|
98
|
-
const toolActions = {};
|
|
99
|
-
let entries = [];
|
|
100
|
-
try {
|
|
101
|
-
entries = fs.readdirSync(this.directory, { withFileTypes: true });
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
return { tools, toolActions };
|
|
105
|
-
}
|
|
106
|
-
for (const entry of entries) {
|
|
107
|
-
if (!entry.isFile() || !entry.name.endsWith('.json') || entry.name === LEGACY_TOOLBOX_FILE_NAME)
|
|
108
|
-
continue;
|
|
109
|
-
const document = readJson(path.join(this.directory, entry.name));
|
|
110
|
-
if (!isToolArtifactDocument(document))
|
|
111
|
-
continue;
|
|
112
|
-
const toolId = safeToolId(document.tool.id);
|
|
113
|
-
if (userArtifactFileName(toolId) !== entry.name)
|
|
114
|
-
continue;
|
|
115
|
-
tools[toolId] = { ...document.tool, id: toolId };
|
|
116
|
-
for (const action of document.actions) {
|
|
117
|
-
toolActions[String(action.id)] = { ...action, toolId };
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return { tools, toolActions };
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
export { ArtifactFiles };
|
package/dist/bin/mcp.d.ts
DELETED
package/dist/bin/mcp.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createMcpServer } from '../mcp-server.js';
|
|
3
|
-
const args = process.argv.slice(2);
|
|
4
|
-
const stateIndex = args.indexOf('--state-dir');
|
|
5
|
-
const stateDir = stateIndex >= 0 ? args[stateIndex + 1] : undefined;
|
|
6
|
-
const server = createMcpServer({ stateDir });
|
|
7
|
-
server.start();
|
|
8
|
-
const close = () => {
|
|
9
|
-
server.toolbox.close();
|
|
10
|
-
process.exit(0);
|
|
11
|
-
};
|
|
12
|
-
process.once('SIGINT', close);
|
|
13
|
-
process.once('SIGTERM', close);
|
package/dist/bin/tools.d.ts
DELETED
package/dist/bin/tools.js
DELETED
package/dist/cli.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { CliIo, LoadoutInput } from './types.js';
|
|
2
|
-
declare const HELP = "Usage: amalgm-tools [--state-dir DIR] [--loadout IDS] <command>\n\nCommands:\n apply <definition.js|json> Apply one tool or an array of tools\n list List tools and enabled actions\n catalog Print the complete canonical catalog\n show <tool-or-action-id> Show one record\n enable <tool-or-action-id> Enable one record\n disable <tool-or-action-id> Disable one record\n remove <tool-or-action-id> Remove one record\n link <tool-id> <app-id> Link one tool to the app it belongs to\n unlink <tool-id> Detach one tool from its app\n run <action-id> [--input JSON]\n Run an action\n connections List MCP connections for a composing host";
|
|
3
|
-
interface Parsed {
|
|
4
|
-
command?: string;
|
|
5
|
-
args: string[];
|
|
6
|
-
stateDir?: string;
|
|
7
|
-
loadout?: LoadoutInput;
|
|
8
|
-
input: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
/** One call on the command surface: an MCP tool name and its arguments. */
|
|
11
|
-
interface Call {
|
|
12
|
-
name: string;
|
|
13
|
-
args: Record<string, unknown>;
|
|
14
|
-
}
|
|
15
|
-
declare function parse(argv: string[]): Parsed;
|
|
16
|
-
declare function runCli(argv: string[], io?: CliIo): Promise<number>;
|
|
17
|
-
export { HELP, parse, runCli };
|
|
18
|
-
export type { Call, Parsed };
|
package/dist/cli.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { createToolboxCommands } from './commands.js';
|
|
2
|
-
import { id, mcpName } from './ids.js';
|
|
3
|
-
import { loadDefinitions } from './module.js';
|
|
4
|
-
import { Toolbox } from './toolbox.js';
|
|
5
|
-
const HELP = `Usage: amalgm-tools [--state-dir DIR] [--loadout IDS] <command>
|
|
6
|
-
|
|
7
|
-
Commands:
|
|
8
|
-
apply <definition.js|json> Apply one tool or an array of tools
|
|
9
|
-
list List tools and enabled actions
|
|
10
|
-
catalog Print the complete canonical catalog
|
|
11
|
-
show <tool-or-action-id> Show one record
|
|
12
|
-
enable <tool-or-action-id> Enable one record
|
|
13
|
-
disable <tool-or-action-id> Disable one record
|
|
14
|
-
remove <tool-or-action-id> Remove one record
|
|
15
|
-
link <tool-id> <app-id> Link one tool to the app it belongs to
|
|
16
|
-
unlink <tool-id> Detach one tool from its app
|
|
17
|
-
run <action-id> [--input JSON]
|
|
18
|
-
Run an action
|
|
19
|
-
connections List MCP connections for a composing host`;
|
|
20
|
-
function parse(argv) {
|
|
21
|
-
const args = [...argv];
|
|
22
|
-
let stateDir;
|
|
23
|
-
let loadout;
|
|
24
|
-
let input = {};
|
|
25
|
-
for (let index = 0; index < args.length;) {
|
|
26
|
-
const flag = args[index];
|
|
27
|
-
if (flag === '--state-dir') {
|
|
28
|
-
if (!args[index + 1])
|
|
29
|
-
throw new Error('--state-dir requires a value');
|
|
30
|
-
stateDir = args[index + 1];
|
|
31
|
-
args.splice(index, 2);
|
|
32
|
-
}
|
|
33
|
-
else if (flag === '--loadout') {
|
|
34
|
-
if (args[index + 1] === undefined)
|
|
35
|
-
throw new Error('--loadout requires a comma-separated value');
|
|
36
|
-
loadout = args[index + 1].split(',').map((value) => value.trim()).filter(Boolean);
|
|
37
|
-
args.splice(index, 2);
|
|
38
|
-
}
|
|
39
|
-
else if (flag === '--input') {
|
|
40
|
-
if (!args[index + 1])
|
|
41
|
-
throw new Error('--input requires JSON');
|
|
42
|
-
input = JSON.parse(args[index + 1]);
|
|
43
|
-
args.splice(index, 2);
|
|
44
|
-
}
|
|
45
|
-
else
|
|
46
|
-
index += 1;
|
|
47
|
-
}
|
|
48
|
-
return { command: args.shift(), args, stateDir, loadout, input };
|
|
49
|
-
}
|
|
50
|
-
function required(value, label) {
|
|
51
|
-
if (!value)
|
|
52
|
-
throw new Error(`${label} is required`);
|
|
53
|
-
return value;
|
|
54
|
-
}
|
|
55
|
-
/** Map one parsed command line to its calls; `apply` makes one call per definition. */
|
|
56
|
-
async function calls(parsed) {
|
|
57
|
-
const [first, second] = parsed.args;
|
|
58
|
-
const record = (name, label) => ({ name, args: { id: required(first, label) } });
|
|
59
|
-
switch (parsed.command) {
|
|
60
|
-
case 'apply': {
|
|
61
|
-
const definitions = await loadDefinitions(required(first, 'definition file'));
|
|
62
|
-
return definitions.map((tool) => ({ name: 'toolbox_tool_apply', args: { tool } }));
|
|
63
|
-
}
|
|
64
|
-
case 'list': return [{ name: 'toolbox_tools_selected', args: {} }];
|
|
65
|
-
case 'catalog': return [{ name: 'toolbox_tools_list', args: {} }];
|
|
66
|
-
case 'show': return [record('toolbox_tool_get', 'tool or action id')];
|
|
67
|
-
case 'enable': return [record('toolbox_record_enable', 'record id')];
|
|
68
|
-
case 'disable': return [record('toolbox_record_disable', 'record id')];
|
|
69
|
-
case 'remove': return [record('toolbox_record_remove', 'record id')];
|
|
70
|
-
case 'link': return [{
|
|
71
|
-
name: 'toolbox_tool_link',
|
|
72
|
-
args: { id: required(first, 'tool id'), app_id: required(second, 'app id') },
|
|
73
|
-
}];
|
|
74
|
-
case 'unlink': return [record('toolbox_tool_unlink', 'tool id')];
|
|
75
|
-
case 'run': return [{ name: mcpName({ id: id(first, 'action id') }), args: parsed.input }];
|
|
76
|
-
case 'connections': return [{ name: 'toolbox_mcp_connections', args: {} }];
|
|
77
|
-
default: throw new Error(`Unknown command: ${parsed.command}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function open(io, parsed) {
|
|
81
|
-
if (io.commands)
|
|
82
|
-
return { commands: io.commands, close() { } };
|
|
83
|
-
const toolbox = new Toolbox({ stateDir: parsed.stateDir });
|
|
84
|
-
return { commands: createToolboxCommands(toolbox, parsed.loadout), close: () => toolbox.close() };
|
|
85
|
-
}
|
|
86
|
-
function write(output, value) {
|
|
87
|
-
output.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
88
|
-
}
|
|
89
|
-
function fail(output, error) {
|
|
90
|
-
output.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
91
|
-
return 1;
|
|
92
|
-
}
|
|
93
|
-
async function runCli(argv, io = {}) {
|
|
94
|
-
const stdout = io.stdout || process.stdout;
|
|
95
|
-
const stderr = io.stderr || process.stderr;
|
|
96
|
-
let parsed;
|
|
97
|
-
try {
|
|
98
|
-
parsed = parse(argv);
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
return fail(stderr, error);
|
|
102
|
-
}
|
|
103
|
-
if (!parsed.command || ['help', '-h', '--help'].includes(parsed.command)) {
|
|
104
|
-
stdout.write(`${HELP}\n`);
|
|
105
|
-
return 0;
|
|
106
|
-
}
|
|
107
|
-
try {
|
|
108
|
-
const planned = await calls(parsed);
|
|
109
|
-
const session = open(io, parsed);
|
|
110
|
-
try {
|
|
111
|
-
const results = [];
|
|
112
|
-
for (const call of planned)
|
|
113
|
-
results.push(await session.commands.execute(call.name, call.args));
|
|
114
|
-
write(stdout, results.length === 1 ? results[0] : results);
|
|
115
|
-
}
|
|
116
|
-
finally {
|
|
117
|
-
session.close();
|
|
118
|
-
}
|
|
119
|
-
return 0;
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
return fail(stderr, error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
export { HELP, parse, runCli };
|
package/dist/commands.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Toolbox } from './toolbox.js';
|
|
2
|
-
import type { LoadoutInput } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* The one command surface. The CLI speaks only this; a host forwards it to a
|
|
5
|
-
* running runtime's MCP over HTTP, and `createToolboxCommands` runs it against
|
|
6
|
-
* a local Toolbox through that Toolbox's own MCP tools.
|
|
7
|
-
*
|
|
8
|
-
* `name` is an MCP tool name from this package's MCP surface: a management
|
|
9
|
-
* tool (`toolbox_*`, single underscore) or an action tool (`toolbox__<id>`,
|
|
10
|
-
* from `mcpName`). `args` is the MCP `arguments` object for that tool.
|
|
11
|
-
*
|
|
12
|
-
* `execute` resolves to the tool's value, unwrapped from the MCP call result:
|
|
13
|
-
* - any result with `isError: true` rejects with an Error whose message is
|
|
14
|
-
* the result's text content (every `content[].text`, joined by newlines);
|
|
15
|
-
* - a management tool's value is `result.structuredContent` (its text
|
|
16
|
-
* content is the same value as JSON and is never consulted);
|
|
17
|
-
* - an action tool's value is the whole MCP result (`content`,
|
|
18
|
-
* `structuredContent`, `truncated`) exactly as the driver returned it.
|
|
19
|
-
* A remote implementation sends `name`/`args` as an MCP `tools/call` and
|
|
20
|
-
* applies these three rules to the response.
|
|
21
|
-
*/
|
|
22
|
-
interface ToolCommands {
|
|
23
|
-
execute(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
24
|
-
}
|
|
25
|
-
declare function createToolboxCommands(toolbox: Toolbox, loadout?: LoadoutInput): ToolCommands;
|
|
26
|
-
export { createToolboxCommands };
|
|
27
|
-
export type { ToolCommands };
|
package/dist/commands.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { isActionMcpName } from './ids.js';
|
|
2
|
-
import { callMcpTool } from './mcp.js';
|
|
3
|
-
import { structuredValue } from './results.js';
|
|
4
|
-
function unwrap(name, result) {
|
|
5
|
-
if (result.isError)
|
|
6
|
-
throw new Error(result.content.filter((item) => item.type === 'text').map((item) => item.text).join('\n'));
|
|
7
|
-
return isActionMcpName(name) ? result : structuredValue(result.structuredContent);
|
|
8
|
-
}
|
|
9
|
-
function createToolboxCommands(toolbox, loadout) {
|
|
10
|
-
return {
|
|
11
|
-
async execute(name, args) {
|
|
12
|
-
return unwrap(name, await callMcpTool(toolbox, name, args, { loadout }));
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export { createToolboxCommands };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ToolDeployment } from './types.js';
|
|
2
|
-
/** Host effect for the portable, immutable deployment document tree. */
|
|
3
|
-
declare class DeploymentFiles {
|
|
4
|
-
private readonly root;
|
|
5
|
-
constructor(root: string);
|
|
6
|
-
file(deployment: ToolDeployment): string;
|
|
7
|
-
write(deployment: ToolDeployment): string;
|
|
8
|
-
materialize(deployments: readonly ToolDeployment[]): void;
|
|
9
|
-
}
|
|
10
|
-
export { DeploymentFiles };
|
package/dist/deployment-files.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { canonicalJson } from './deployments.js';
|
|
4
|
-
/** Host effect for the portable, immutable deployment document tree. */
|
|
5
|
-
class DeploymentFiles {
|
|
6
|
-
root;
|
|
7
|
-
constructor(root) {
|
|
8
|
-
this.root = root;
|
|
9
|
-
}
|
|
10
|
-
file(deployment) {
|
|
11
|
-
return path.join(this.root, deployment.subjectId, 'deployments', `${deployment.id}.json`);
|
|
12
|
-
}
|
|
13
|
-
write(deployment) {
|
|
14
|
-
const target = this.file(deployment);
|
|
15
|
-
const bytes = `${JSON.stringify(deployment, null, 2)}\n`;
|
|
16
|
-
try {
|
|
17
|
-
const existing = fs.readFileSync(target, 'utf8');
|
|
18
|
-
if (canonicalJson(JSON.parse(existing)) !== canonicalJson(deployment)) {
|
|
19
|
-
throw new Error(`Deployment file is immutable: ${deployment.id}`);
|
|
20
|
-
}
|
|
21
|
-
return target;
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
if (error.code !== 'ENOENT')
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
28
|
-
const temporary = `${target}.tmp`;
|
|
29
|
-
fs.writeFileSync(temporary, bytes, { flag: 'wx' });
|
|
30
|
-
fs.renameSync(temporary, target);
|
|
31
|
-
return target;
|
|
32
|
-
}
|
|
33
|
-
materialize(deployments) {
|
|
34
|
-
for (const deployment of deployments)
|
|
35
|
-
this.write(deployment);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export { DeploymentFiles };
|
package/dist/module.d.ts
DELETED
package/dist/module.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
async function loadDefinitions(file) {
|
|
5
|
-
const absolute = path.resolve(file);
|
|
6
|
-
if (!fs.existsSync(absolute))
|
|
7
|
-
throw new Error(`Definition file not found: ${absolute}`);
|
|
8
|
-
let value;
|
|
9
|
-
if (path.extname(absolute).toLowerCase() === '.json') {
|
|
10
|
-
value = JSON.parse(fs.readFileSync(absolute, 'utf8'));
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
const loaded = await import(`${pathToFileURL(absolute).href}?updated=${fs.statSync(absolute).mtimeMs}`);
|
|
14
|
-
value = loaded.default ?? loaded.tools ?? loaded.tool;
|
|
15
|
-
}
|
|
16
|
-
const definitions = Array.isArray(value) ? value : [value];
|
|
17
|
-
if (!definitions.length || definitions.some((definition) => !definition || typeof definition !== 'object')) {
|
|
18
|
-
throw new Error('Definition module must export one tool or an array of tools');
|
|
19
|
-
}
|
|
20
|
-
return definitions;
|
|
21
|
-
}
|
|
22
|
-
export { loadDefinitions };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { resolveProductStateDir } from '@amalgm/core/identity';
|
|
4
|
-
export function defaultDatabase(options) {
|
|
5
|
-
if (options.databaseFile)
|
|
6
|
-
return path.resolve(options.databaseFile);
|
|
7
|
-
// The state-dir LAW lives in @amalgm/core; only the effectful reads
|
|
8
|
-
// (process.env, os.homedir) happen here at the construction boundary.
|
|
9
|
-
// Precedence: AMALGM_TOOLS_DIR, then AMALGM_DIR/toolbox, then the
|
|
10
|
-
// scoped layout <home>/.amalgm/users/<scope>/toolbox.
|
|
11
|
-
const state = options.stateDir || resolveProductStateDir({
|
|
12
|
-
product: 'tools',
|
|
13
|
-
primitive: 'toolbox',
|
|
14
|
-
env: process.env,
|
|
15
|
-
homedir: path.join(os.homedir(), '.amalgm'),
|
|
16
|
-
});
|
|
17
|
-
return path.join(path.resolve(state), 'tools.db');
|
|
18
|
-
}
|