@amalgm/tools 0.1.2 → 0.1.3
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 +7 -2
- package/dist/artifact-files.d.ts +2 -0
- package/dist/artifact-files.js +7 -0
- package/dist/artifacts.d.ts +3 -1
- package/dist/artifacts.js +14 -1
- package/dist/toolbox.js +7 -8
- package/package.json +2 -2
package/PURPOSE.md
CHANGED
|
@@ -81,11 +81,16 @@ registry or execution implementation.
|
|
|
81
81
|
20. Notification channels are host capabilities. Tools owns validation and
|
|
82
82
|
result semantics; an injected channel adapter owns formatting, recipient
|
|
83
83
|
lookup, credentials, and delivery.
|
|
84
|
+
21. Reopening a Toolbox preserves the temporal fields of every semantically
|
|
85
|
+
unchanged system projection already present in its portable index; boot
|
|
86
|
+
never rewrites tracked bytes merely to stamp the current machine's time.
|
|
84
87
|
|
|
85
88
|
## Predictable behavior
|
|
86
89
|
|
|
87
|
-
Applying the same definition twice produces the same catalog.
|
|
88
|
-
|
|
90
|
+
Applying the same definition twice produces the same catalog. Reopening the
|
|
91
|
+
same system projection produces the same portable index bytes on every
|
|
92
|
+
machine. Applying a changed action set replaces the old set atomically.
|
|
93
|
+
Selecting a whole tool
|
|
89
94
|
grants all of its enabled actions; selecting one action grants only that
|
|
90
95
|
action. Disabling or deleting a tool immediately removes all of its actions
|
|
91
96
|
from list and call surfaces. CLI arguments are passed directly to a process,
|
package/dist/artifact-files.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToolboxIndexDocument } from './artifacts.js';
|
|
1
2
|
import type { ActionRecord, Catalog, ToolRecord } from './types.js';
|
|
2
3
|
declare class ArtifactFiles {
|
|
3
4
|
private readonly directory;
|
|
@@ -9,6 +10,7 @@ declare class ArtifactFiles {
|
|
|
9
10
|
}): string;
|
|
10
11
|
removeTool(toolId: string): void;
|
|
11
12
|
writeIndex(catalog: Catalog): void;
|
|
13
|
+
readIndex(): ToolboxIndexDocument | null;
|
|
12
14
|
/** Give every persisted user tool its portable artifact and refresh the
|
|
13
15
|
* index. Additive only: a file for a tool this catalog does not know is
|
|
14
16
|
* never deleted here — removal is an explicit mutation. */
|
package/dist/artifact-files.js
CHANGED
|
@@ -51,6 +51,13 @@ class ArtifactFiles {
|
|
|
51
51
|
writeIndex(catalog) {
|
|
52
52
|
writeJsonIfChanged(this.file(TOOLBOX_INDEX_FILE_NAME), catalogIndexDocument(catalog));
|
|
53
53
|
}
|
|
54
|
+
readIndex() {
|
|
55
|
+
const value = readJson(this.file(TOOLBOX_INDEX_FILE_NAME));
|
|
56
|
+
if (!value || value.version !== 1 || !value.tools || typeof value.tools !== 'object'
|
|
57
|
+
|| !value.toolActions || typeof value.toolActions !== 'object')
|
|
58
|
+
return null;
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
54
61
|
/** Give every persisted user tool its portable artifact and refresh the
|
|
55
62
|
* index. Additive only: a file for a tool this catalog does not know is
|
|
56
63
|
* never deleted here — removal is an explicit mutation. */
|
package/dist/artifacts.d.ts
CHANGED
|
@@ -57,10 +57,12 @@ declare function artifactDocument(input: {
|
|
|
57
57
|
declare function isToolArtifactDocument(value: unknown): value is ToolArtifactDocument;
|
|
58
58
|
declare function toolboxIndexDocument(tools: Record<string, unknown>, toolActions: Record<string, unknown>): ToolboxIndexDocument;
|
|
59
59
|
declare function catalogIndexDocument(catalog: Pick<Catalog, 'tools' | 'actions'>): ToolboxIndexDocument;
|
|
60
|
+
declare function portableRecordSemantic(value: ToolRecord | ActionRecord): string;
|
|
61
|
+
declare function preserveProjectionTime<T extends ToolRecord | ActionRecord>(candidate: T, previous: unknown): T;
|
|
60
62
|
/** The migration of one legacy aggregate `toolbox.json` catalog, as a pure
|
|
61
63
|
* plan: every user tool becomes a per-tool artifact write, the whole legacy
|
|
62
64
|
* catalog becomes the index, and the aggregate file is renamed out of the
|
|
63
65
|
* way only after each record has a per-tool replacement. */
|
|
64
66
|
declare function legacyMigrationPlan(legacy: unknown): LegacyMigrationPlan;
|
|
65
|
-
export { LEGACY_TOOLBOX_BACKUP_FILE_NAME, LEGACY_TOOLBOX_FILE_NAME, TOOL_ARTIFACT_KIND, TOOL_ARTIFACT_SCHEMA_VERSION, TOOLBOX_INDEX_FILE_NAME, artifactDocument, catalogIndexDocument, isToolArtifactDocument, legacyMigrationPlan, safeToolId, toolboxIndexDocument, userArtifactFileName, };
|
|
67
|
+
export { LEGACY_TOOLBOX_BACKUP_FILE_NAME, LEGACY_TOOLBOX_FILE_NAME, TOOL_ARTIFACT_KIND, TOOL_ARTIFACT_SCHEMA_VERSION, TOOLBOX_INDEX_FILE_NAME, artifactDocument, catalogIndexDocument, isToolArtifactDocument, legacyMigrationPlan, safeToolId, portableRecordSemantic, preserveProjectionTime, toolboxIndexDocument, userArtifactFileName, };
|
|
66
68
|
export type { ArtifactFileWrite, LegacyMigrationPlan, ToolArtifactDocument, ToolboxIndexDocument };
|
package/dist/artifacts.js
CHANGED
|
@@ -81,6 +81,19 @@ function toolboxIndexDocument(tools, toolActions) {
|
|
|
81
81
|
function catalogIndexDocument(catalog) {
|
|
82
82
|
return toolboxIndexDocument(Object.fromEntries(catalog.tools.map((tool) => [tool.id, tool])), Object.fromEntries(catalog.actions.map((action) => [action.id, action])));
|
|
83
83
|
}
|
|
84
|
+
function portableRecordSemantic(value) {
|
|
85
|
+
const { createdAt, updatedAt, ...portable } = value;
|
|
86
|
+
return JSON.stringify(portable);
|
|
87
|
+
}
|
|
88
|
+
function preserveProjectionTime(candidate, previous) {
|
|
89
|
+
if (!previous || typeof previous !== 'object')
|
|
90
|
+
return candidate;
|
|
91
|
+
const record = previous;
|
|
92
|
+
if (typeof record.createdAt !== 'string' || typeof record.updatedAt !== 'string'
|
|
93
|
+
|| portableRecordSemantic(record) !== portableRecordSemantic(candidate))
|
|
94
|
+
return candidate;
|
|
95
|
+
return { ...candidate, createdAt: record.createdAt, updatedAt: record.updatedAt };
|
|
96
|
+
}
|
|
84
97
|
/** The migration of one legacy aggregate `toolbox.json` catalog, as a pure
|
|
85
98
|
* plan: every user tool becomes a per-tool artifact write, the whole legacy
|
|
86
99
|
* catalog becomes the index, and the aggregate file is renamed out of the
|
|
@@ -109,4 +122,4 @@ function legacyMigrationPlan(legacy) {
|
|
|
109
122
|
rename: { from: LEGACY_TOOLBOX_FILE_NAME, to: LEGACY_TOOLBOX_BACKUP_FILE_NAME },
|
|
110
123
|
};
|
|
111
124
|
}
|
|
112
|
-
export { LEGACY_TOOLBOX_BACKUP_FILE_NAME, LEGACY_TOOLBOX_FILE_NAME, TOOL_ARTIFACT_KIND, TOOL_ARTIFACT_SCHEMA_VERSION, TOOLBOX_INDEX_FILE_NAME, artifactDocument, catalogIndexDocument, isToolArtifactDocument, legacyMigrationPlan, safeToolId, toolboxIndexDocument, userArtifactFileName, };
|
|
125
|
+
export { LEGACY_TOOLBOX_BACKUP_FILE_NAME, LEGACY_TOOLBOX_FILE_NAME, TOOL_ARTIFACT_KIND, TOOL_ARTIFACT_SCHEMA_VERSION, TOOLBOX_INDEX_FILE_NAME, artifactDocument, catalogIndexDocument, isToolArtifactDocument, legacyMigrationPlan, safeToolId, portableRecordSemantic, preserveProjectionTime, toolboxIndexDocument, userArtifactFileName, };
|
package/dist/toolbox.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { resolveProductStateDir } from '@amalgm/core/identity';
|
|
4
4
|
import { apiDriver } from './api-driver.js';
|
|
5
5
|
import { ArtifactFiles } from './artifact-files.js';
|
|
6
|
+
import { portableRecordSemantic, preserveProjectionTime } from './artifacts.js';
|
|
6
7
|
import { cliDriver } from './cli-driver.js';
|
|
7
8
|
import { normalizeDefinition } from './definition.js';
|
|
8
9
|
import { assertMcpNamesUnique, id, mcpName } from './ids.js';
|
|
@@ -11,10 +12,6 @@ import { callableActions, queryTools, resolveAction, resolveCallableAction } fro
|
|
|
11
12
|
import { findSelected, selected } from './selection.js';
|
|
12
13
|
import { Store } from './store.js';
|
|
13
14
|
import { updateAction, updateTool, upsertAction } from './updates.js';
|
|
14
|
-
function semantic(value) {
|
|
15
|
-
const { createdAt, updatedAt, ...record } = value;
|
|
16
|
-
return JSON.stringify(record);
|
|
17
|
-
}
|
|
18
15
|
function defaultDatabase(options) {
|
|
19
16
|
if (options.databaseFile)
|
|
20
17
|
return path.resolve(options.databaseFile);
|
|
@@ -40,6 +37,7 @@ class Toolbox {
|
|
|
40
37
|
const databaseFile = defaultDatabase(options);
|
|
41
38
|
this.store = new Store(databaseFile);
|
|
42
39
|
this.artifacts = new ArtifactFiles(path.dirname(databaseFile));
|
|
40
|
+
const priorIndex = this.artifacts.readIndex();
|
|
43
41
|
this.onChange = options.onChange;
|
|
44
42
|
for (const driver of [cliDriver, apiDriver, ...(options.drivers || [])])
|
|
45
43
|
this.drivers.set(driver.type, driver);
|
|
@@ -49,8 +47,8 @@ class Toolbox {
|
|
|
49
47
|
const normalized = normalizeDefinition({ ...definition, origin: 'system' });
|
|
50
48
|
if (tools.some((tool) => tool.id === normalized.tool.id))
|
|
51
49
|
throw new Error(`Duplicate system tool: ${normalized.tool.id}`);
|
|
52
|
-
tools.push(normalized.tool);
|
|
53
|
-
actions.push(...normalized.actions);
|
|
50
|
+
tools.push(preserveProjectionTime(normalized.tool, priorIndex?.tools[normalized.tool.id]));
|
|
51
|
+
actions.push(...normalized.actions.map((action) => preserveProjectionTime(action, priorIndex?.toolActions[action.id])));
|
|
54
52
|
}
|
|
55
53
|
assertMcpNamesUnique(actions);
|
|
56
54
|
this.system = { version: 1, revision: 0, tools, actions };
|
|
@@ -116,9 +114,10 @@ class Toolbox {
|
|
|
116
114
|
...normalized.actions,
|
|
117
115
|
];
|
|
118
116
|
assertMcpNamesUnique(candidateActions);
|
|
119
|
-
const unchanged = existing &&
|
|
117
|
+
const unchanged = existing && portableRecordSemantic(existing) === portableRecordSemantic(normalized.tool)
|
|
120
118
|
&& normalized.actions.length === oldActions.size
|
|
121
|
-
&& normalized.actions.every((action) =>
|
|
119
|
+
&& normalized.actions.every((action) => portableRecordSemantic(action)
|
|
120
|
+
=== portableRecordSemantic(oldActions.get(action.id)));
|
|
122
121
|
if (unchanged)
|
|
123
122
|
return { tool: existing, actions: [...oldActions.values()].sort((a, b) => a.id.localeCompare(b.id)) };
|
|
124
123
|
const result = this.store.apply(normalized);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amalgm/tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Local-first tool definitions, Toolbox registry, and agent execution surfaces.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"node": ">=20"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@amalgm/core": "
|
|
52
|
+
"@amalgm/core": "0.2.0",
|
|
53
53
|
"better-sqlite3": "^12.6.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|