@skillsmith/core 0.8.1 → 0.9.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/CHANGELOG.md +10 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/src/config/device-identity.d.ts +113 -0
- package/dist/src/config/device-identity.d.ts.map +1 -0
- package/dist/src/config/device-identity.js +171 -0
- package/dist/src/config/device-identity.js.map +1 -0
- package/dist/src/config/device-identity.test.d.ts +10 -0
- package/dist/src/config/device-identity.test.d.ts.map +1 -0
- package/dist/src/config/device-identity.test.js +213 -0
- package/dist/src/config/device-identity.test.js.map +1 -0
- package/dist/src/config/index.d.ts +9 -0
- package/dist/src/config/index.d.ts.map +1 -1
- package/dist/src/config/index.js.map +1 -1
- package/dist/src/exports/services.d.ts +1 -1
- package/dist/src/exports/services.d.ts.map +1 -1
- package/dist/src/exports/services.js +5 -1
- package/dist/src/exports/services.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/install/index.d.ts +1 -1
- package/dist/src/install/index.d.ts.map +1 -1
- package/dist/src/install/index.js +1 -1
- package/dist/src/install/index.js.map +1 -1
- package/dist/src/install/paths.d.ts +16 -0
- package/dist/src/install/paths.d.ts.map +1 -1
- package/dist/src/install/paths.js +22 -0
- package/dist/src/install/paths.js.map +1 -1
- package/dist/src/install/paths.test.d.ts +2 -0
- package/dist/src/install/paths.test.d.ts.map +1 -0
- package/dist/src/install/paths.test.js +61 -0
- package/dist/src/install/paths.test.js.map +1 -0
- package/dist/src/provenance/SourceRecoveryService.d.ts +17 -4
- package/dist/src/provenance/SourceRecoveryService.d.ts.map +1 -1
- package/dist/src/provenance/SourceRecoveryService.js +37 -10
- package/dist/src/provenance/SourceRecoveryService.js.map +1 -1
- package/dist/src/provenance/index.d.ts +1 -0
- package/dist/src/provenance/index.d.ts.map +1 -1
- package/dist/src/provenance/index.js +1 -0
- package/dist/src/provenance/index.js.map +1 -1
- package/dist/src/provenance/name-variants.d.ts +32 -0
- package/dist/src/provenance/name-variants.d.ts.map +1 -0
- package/dist/src/provenance/name-variants.js +59 -0
- package/dist/src/provenance/name-variants.js.map +1 -0
- package/dist/src/provenance/types.d.ts +12 -0
- package/dist/src/provenance/types.d.ts.map +1 -1
- package/dist/src/provenance/types.js.map +1 -1
- package/dist/src/security/scanner/SecurityScanner.scanners.d.ts +10 -0
- package/dist/src/security/scanner/SecurityScanner.scanners.d.ts.map +1 -1
- package/dist/src/security/scanner/SecurityScanner.scanners.js +68 -1
- package/dist/src/security/scanner/SecurityScanner.scanners.js.map +1 -1
- package/dist/src/sync/index.d.ts +6 -0
- package/dist/src/sync/index.d.ts.map +1 -1
- package/dist/src/sync/index.js +8 -0
- package/dist/src/sync/index.js.map +1 -1
- package/dist/src/sync/inventory-builder.d.ts +21 -0
- package/dist/src/sync/inventory-builder.d.ts.map +1 -0
- package/dist/src/sync/inventory-builder.js +26 -0
- package/dist/src/sync/inventory-builder.js.map +1 -0
- package/dist/src/sync/inventory-client.d.ts +64 -0
- package/dist/src/sync/inventory-client.d.ts.map +1 -0
- package/dist/src/sync/inventory-client.js +150 -0
- package/dist/src/sync/inventory-client.js.map +1 -0
- package/dist/src/sync/inventory-client.test.d.ts +14 -0
- package/dist/src/sync/inventory-client.test.d.ts.map +1 -0
- package/dist/src/sync/inventory-client.test.js +146 -0
- package/dist/src/sync/inventory-client.test.js.map +1 -0
- package/dist/src/sync/inventory-collector.d.ts +35 -0
- package/dist/src/sync/inventory-collector.d.ts.map +1 -0
- package/dist/src/sync/inventory-collector.js +149 -0
- package/dist/src/sync/inventory-collector.js.map +1 -0
- package/dist/src/sync/inventory-collector.test.d.ts +14 -0
- package/dist/src/sync/inventory-collector.test.d.ts.map +1 -0
- package/dist/src/sync/inventory-collector.test.js +107 -0
- package/dist/src/sync/inventory-collector.test.js.map +1 -0
- package/dist/src/sync/inventory-device.d.ts +36 -0
- package/dist/src/sync/inventory-device.d.ts.map +1 -0
- package/dist/src/sync/inventory-device.js +58 -0
- package/dist/src/sync/inventory-device.js.map +1 -0
- package/dist/src/sync/inventory-push.d.ts +45 -0
- package/dist/src/sync/inventory-push.d.ts.map +1 -0
- package/dist/src/sync/inventory-push.js +62 -0
- package/dist/src/sync/inventory-push.js.map +1 -0
- package/dist/src/sync/inventory-push.test.d.ts +16 -0
- package/dist/src/sync/inventory-push.test.d.ts.map +1 -0
- package/dist/src/sync/inventory-push.test.js +104 -0
- package/dist/src/sync/inventory-push.test.js.map +1 -0
- package/dist/src/sync/inventory-types.d.ts +101 -0
- package/dist/src/sync/inventory-types.d.ts.map +1 -0
- package/dist/src/sync/inventory-types.js +42 -0
- package/dist/src/sync/inventory-types.js.map +1 -0
- package/dist/tests/provenance/SourceRecoveryService.test.js +73 -0
- package/dist/tests/provenance/SourceRecoveryService.test.js.map +1 -1
- package/dist/tests/provenance/backfill.test.js +18 -0
- package/dist/tests/provenance/backfill.test.js.map +1 -1
- package/dist/tests/provenance/name-variants.test.d.ts +2 -0
- package/dist/tests/provenance/name-variants.test.d.ts.map +1 -0
- package/dist/tests/provenance/name-variants.test.js +51 -0
- package/dist/tests/provenance/name-variants.test.js.map +1 -0
- package/dist/tests/security/pii-detection.test.js +107 -0
- package/dist/tests/security/pii-detection.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-client.test.js","sourceRoot":"","sources":["../../../src/sync/inventory-client.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAExE,EAAE,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/C,eAAe,EAAE,EAAE,CAAC,EAAE,EAAE;IACxB,k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ySkillEntry} per (harness, skill) observed on disk. This is
|
|
6
|
+
* the shared scanner that both the CLI `inventory push` command (Wave 3) and the
|
|
7
|
+
* MCP inventory tool call before handing the snapshot to {@link uploadInventory}.
|
|
8
|
+
*
|
|
9
|
+
* Design parity with the CLI scanner at
|
|
10
|
+
* `packages/cli/src/utils/skills-directory.ts`:
|
|
11
|
+
* - Uses the SAME {@link SkillParser} to resolve `skill_id` / `version`.
|
|
12
|
+
* - Realpath-deduplicates ACROSS harnesses (collapses symlink aliases), but does
|
|
13
|
+
* NOT name-deduplicate — the same skill independently installed under two
|
|
14
|
+
* harnesses is two distinct rows (the `device_skills` PK is `(harness, skill_id)`).
|
|
15
|
+
*
|
|
16
|
+
* @module @skillsmith/core/sync/inventory-collector
|
|
17
|
+
*/
|
|
18
|
+
import type { InventorySkillEntry } from './inventory-types.js';
|
|
19
|
+
/**
|
|
20
|
+
* Collect every harness-installed skill on this device as inventory entries.
|
|
21
|
+
*
|
|
22
|
+
* Scans each harness in {@link CLIENT_IDS} order. Repo-local `./.claude/skills`
|
|
23
|
+
* is intentionally excluded — inventory tracks harness-installed skills only, and
|
|
24
|
+
* `harness` is always a {@link ClientId}, never `'local'`.
|
|
25
|
+
*
|
|
26
|
+
* The result is NOT truncated to `INVENTORY_LIMITS.MAX_SKILLS`. Exceeding
|
|
27
|
+
* the cap is a real condition the caller / edge function must enforce (returning
|
|
28
|
+
* a `too_many_skills` 400) — silently dropping skills here would corrupt the
|
|
29
|
+
* server-side reconcile by making present skills look absent.
|
|
30
|
+
*
|
|
31
|
+
* @returns One entry per (harness, skill), realpath-deduplicated across harnesses.
|
|
32
|
+
* @see SMI-5392
|
|
33
|
+
*/
|
|
34
|
+
export declare function collectDeviceSkills(): Promise<InventorySkillEntry[]>;
|
|
35
|
+
//# sourceMappingURL=inventory-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-collector.d.ts","sourceRoot":"","sources":["../../../src/sync/inventory-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAoH/D;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAO1E"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-harness skill collector (SMI-5392, umbrella SMI-5382).
|
|
3
|
+
*
|
|
4
|
+
* Walks every known harness skill directory (`CLIENT_NATIVE_PATHS`) and emits
|
|
5
|
+
* one {@link InventorySkillEntry} per (harness, skill) observed on disk. This is
|
|
6
|
+
* the shared scanner that both the CLI `inventory push` command (Wave 3) and the
|
|
7
|
+
* MCP inventory tool call before handing the snapshot to {@link uploadInventory}.
|
|
8
|
+
*
|
|
9
|
+
* Design parity with the CLI scanner at
|
|
10
|
+
* `packages/cli/src/utils/skills-directory.ts`:
|
|
11
|
+
* - Uses the SAME {@link SkillParser} to resolve `skill_id` / `version`.
|
|
12
|
+
* - Realpath-deduplicates ACROSS harnesses (collapses symlink aliases), but does
|
|
13
|
+
* NOT name-deduplicate — the same skill independently installed under two
|
|
14
|
+
* harnesses is two distinct rows (the `device_skills` PK is `(harness, skill_id)`).
|
|
15
|
+
*
|
|
16
|
+
* @module @skillsmith/core/sync/inventory-collector
|
|
17
|
+
*/
|
|
18
|
+
import { readdir, readFile, realpath, stat } from 'node:fs/promises';
|
|
19
|
+
import { createHash } from 'node:crypto';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { SkillParser } from '../indexer/SkillParser.js';
|
|
22
|
+
import { CLIENT_IDS, CLIENT_NATIVE_PATHS } from '../install/paths.js';
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a path through `realpath` defensively. Returns the resolved path on
|
|
25
|
+
* success, or the input path unchanged when the link is broken / unreadable —
|
|
26
|
+
* dedup keying still works either way (we just can't collapse a broken alias).
|
|
27
|
+
*/
|
|
28
|
+
async function safeRealpath(path) {
|
|
29
|
+
try {
|
|
30
|
+
return await realpath(path);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return path;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Return `true` when a directory entry resolves to a directory, following
|
|
38
|
+
* symlinks. `withFileTypes` reports a symlinked directory as a symlink (not a
|
|
39
|
+
* directory), so symlinked aliases must be `stat`-resolved to be collected —
|
|
40
|
+
* which is exactly what makes the cross-harness realpath dedup observable.
|
|
41
|
+
*/
|
|
42
|
+
async function resolvesToDirectory(entryPath, isDirectory, isSymbolicLink) {
|
|
43
|
+
if (isDirectory)
|
|
44
|
+
return true;
|
|
45
|
+
if (!isSymbolicLink)
|
|
46
|
+
return false;
|
|
47
|
+
try {
|
|
48
|
+
return (await stat(entryPath)).isDirectory();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false; // broken symlink
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read `<skillDir>/SKILL.md` and derive the inventory fields.
|
|
56
|
+
*
|
|
57
|
+
* - `content_hash` is the sha256 hex digest of the raw SKILL.md content. Wave 5
|
|
58
|
+
* validates that this hashing stays drift-aligned with the indexer's hashing.
|
|
59
|
+
* - `skill_id` is the parsed `id` front-matter field, falling back to the parsed
|
|
60
|
+
* `name`, then the directory name (same precedence as the CLI scanner).
|
|
61
|
+
* - A directory with no readable SKILL.md still counts as a skill: `skill_id` is
|
|
62
|
+
* the directory name, with `version` and `content_hash` both `null`.
|
|
63
|
+
*/
|
|
64
|
+
async function readSkillFields(skillDir, dirName) {
|
|
65
|
+
try {
|
|
66
|
+
const content = await readFile(join(skillDir, 'SKILL.md'), 'utf-8');
|
|
67
|
+
const contentHash = createHash('sha256').update(content, 'utf8').digest('hex');
|
|
68
|
+
const parsed = new SkillParser().parse(content);
|
|
69
|
+
if (!parsed) {
|
|
70
|
+
// SKILL.md is readable but has no valid frontmatter — hash still applies.
|
|
71
|
+
return { skillId: dirName, version: null, contentHash };
|
|
72
|
+
}
|
|
73
|
+
// Match the CLI scanner: read `id` off the parsed metadata, then `name`.
|
|
74
|
+
const parsedId = parsed['id'];
|
|
75
|
+
return {
|
|
76
|
+
skillId: parsedId ?? parsed.name ?? dirName,
|
|
77
|
+
version: parsed.version ?? null,
|
|
78
|
+
contentHash,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// No readable SKILL.md — still a skill, but version/hash are unknown.
|
|
83
|
+
return { skillId: dirName, version: null, contentHash: null };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Scan a single harness directory and append its skills to `entries`,
|
|
88
|
+
* deduplicating by realpath via the shared `seenRealpaths` set.
|
|
89
|
+
*/
|
|
90
|
+
async function collectHarness(harness, entries, seenRealpaths) {
|
|
91
|
+
const harnessDir = CLIENT_NATIVE_PATHS[harness];
|
|
92
|
+
let dirents;
|
|
93
|
+
try {
|
|
94
|
+
dirents = await readdir(harnessDir, { withFileTypes: true });
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const code = error.code;
|
|
98
|
+
// Absent harness dir is the common case (harness not installed) — skip it.
|
|
99
|
+
if (code === 'ENOENT' || code === 'ENOTDIR')
|
|
100
|
+
return;
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
for (const dirent of dirents) {
|
|
104
|
+
const entryPath = join(harnessDir, dirent.name);
|
|
105
|
+
if (!(await resolvesToDirectory(entryPath, dirent.isDirectory(), dirent.isSymbolicLink()))) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
// Realpath dedup ACROSS harnesses: the first harness in CLIENT_IDS order
|
|
109
|
+
// wins, so a symlinked alias under a later harness is collapsed away.
|
|
110
|
+
const realDir = await safeRealpath(entryPath);
|
|
111
|
+
if (seenRealpaths.has(realDir))
|
|
112
|
+
continue;
|
|
113
|
+
seenRealpaths.add(realDir);
|
|
114
|
+
const { skillId, version, contentHash } = await readSkillFields(entryPath, dirent.name);
|
|
115
|
+
entries.push({
|
|
116
|
+
harness,
|
|
117
|
+
skill_id: skillId,
|
|
118
|
+
version,
|
|
119
|
+
content_hash: contentHash,
|
|
120
|
+
source: null,
|
|
121
|
+
pinned_version: null,
|
|
122
|
+
update_policy: null,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Collect every harness-installed skill on this device as inventory entries.
|
|
128
|
+
*
|
|
129
|
+
* Scans each harness in {@link CLIENT_IDS} order. Repo-local `./.claude/skills`
|
|
130
|
+
* is intentionally excluded — inventory tracks harness-installed skills only, and
|
|
131
|
+
* `harness` is always a {@link ClientId}, never `'local'`.
|
|
132
|
+
*
|
|
133
|
+
* The result is NOT truncated to `INVENTORY_LIMITS.MAX_SKILLS`. Exceeding
|
|
134
|
+
* the cap is a real condition the caller / edge function must enforce (returning
|
|
135
|
+
* a `too_many_skills` 400) — silently dropping skills here would corrupt the
|
|
136
|
+
* server-side reconcile by making present skills look absent.
|
|
137
|
+
*
|
|
138
|
+
* @returns One entry per (harness, skill), realpath-deduplicated across harnesses.
|
|
139
|
+
* @see SMI-5392
|
|
140
|
+
*/
|
|
141
|
+
export async function collectDeviceSkills() {
|
|
142
|
+
const entries = [];
|
|
143
|
+
const seenRealpaths = new Set();
|
|
144
|
+
for (const harness of CLIENT_IDS) {
|
|
145
|
+
await collectHarness(harness, entries, seenRealpaths);
|
|
146
|
+
}
|
|
147
|
+
return entries;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=inventory-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-collector.js","sourceRoot":"","sources":["../../../src/sync/inventory-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAA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,CAAC;YAC3F,SAAQ;QACV,CAAC;QAED,yEAAyE;QACzE,sEAAsE;QACtE,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,CAAA;QAC7C,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,SAAQ;QACxC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAE1B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACvF,OAAO,CAAC,IAAI,CAAC;YACX,OAAO;YACP,QAAQ,EAAE,OAAO;YACjB,OAAO;YACP,YAAY,EAAE,WAAW;YACzB,MAAM,EAAE,IAAI;YACZ,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,IAAI;SACpB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,MAAM,OAAO,GAA0B,EAAE,CAAA;IACzC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;IACvC,KAAK,MAAM,OAAO,IAAI,UAAU,EAAE,CAAC;QACjC,MAAM,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC,CAAA;IACvD,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* inventory-collector tests (SMI-5392).
|
|
3
|
+
*
|
|
4
|
+
* Controls the harness directory table by mocking `../install/paths.js` so each
|
|
5
|
+
* `ClientId` points at a real tmp fixture. CLIENT_NATIVE_PATHS is a mutable
|
|
6
|
+
* object the collector reads at call time, so per-test fixtures are visible
|
|
7
|
+
* without re-importing the module.
|
|
8
|
+
*
|
|
9
|
+
* IC-1: same skill under two harnesses (distinct realpaths) -> two entries.
|
|
10
|
+
* IC-2: a symlinked alias across harnesses -> one entry (first ClientId wins).
|
|
11
|
+
* IC-3: readable SKILL.md -> content_hash + version; missing SKILL.md -> nulls.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=inventory-collector.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-collector.test.d.ts","sourceRoot":"","sources":["../../../src/sync/inventory-collector.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* inventory-collector tests (SMI-5392).
|
|
3
|
+
*
|
|
4
|
+
* Controls the harness directory table by mocking `../install/paths.js` so each
|
|
5
|
+
* `ClientId` points at a real tmp fixture. CLIENT_NATIVE_PATHS is a mutable
|
|
6
|
+
* object the collector reads at call time, so per-test fixtures are visible
|
|
7
|
+
* without re-importing the module.
|
|
8
|
+
*
|
|
9
|
+
* IC-1: same skill under two harnesses (distinct realpaths) -> two entries.
|
|
10
|
+
* IC-2: a symlinked alias across harnesses -> one entry (first ClientId wins).
|
|
11
|
+
* IC-3: readable SKILL.md -> content_hash + version; missing SKILL.md -> nulls.
|
|
12
|
+
*/
|
|
13
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
14
|
+
import { mkdtemp, mkdir, writeFile, symlink, rm } from 'node:fs/promises';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
const mockPaths = vi.hoisted(() => ({
|
|
18
|
+
CLIENT_IDS: ['claude-code', 'cursor', 'copilot', 'windsurf', 'agents'],
|
|
19
|
+
CLIENT_NATIVE_PATHS: {},
|
|
20
|
+
}));
|
|
21
|
+
vi.mock('../install/paths.js', () => ({
|
|
22
|
+
CLIENT_IDS: mockPaths.CLIENT_IDS,
|
|
23
|
+
CLIENT_NATIVE_PATHS: mockPaths.CLIENT_NATIVE_PATHS,
|
|
24
|
+
}));
|
|
25
|
+
import { collectDeviceSkills } from './inventory-collector.js';
|
|
26
|
+
import { INVENTORY_LIMITS } from './inventory-types.js';
|
|
27
|
+
function skillMd(name, version) {
|
|
28
|
+
const versionLine = version ? `\nversion: ${version}` : '';
|
|
29
|
+
return `---\nname: ${name}${versionLine}\n---\n\n# ${name}\n`;
|
|
30
|
+
}
|
|
31
|
+
async function createSkill(harness, name, opts = {}) {
|
|
32
|
+
const dir = join(mockPaths.CLIENT_NATIVE_PATHS[harness], name);
|
|
33
|
+
await mkdir(dir, { recursive: true });
|
|
34
|
+
if (opts.withSkillMd !== false) {
|
|
35
|
+
await writeFile(join(dir, 'SKILL.md'), skillMd(name, opts.version));
|
|
36
|
+
}
|
|
37
|
+
return dir;
|
|
38
|
+
}
|
|
39
|
+
let root;
|
|
40
|
+
describe('inventory-collector', () => {
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
root = await mkdtemp(join(tmpdir(), 'inv-collector-'));
|
|
43
|
+
// Point every harness at its own (initially absent) subdir under root.
|
|
44
|
+
for (const id of mockPaths.CLIENT_IDS) {
|
|
45
|
+
mockPaths.CLIENT_NATIVE_PATHS[id] = join(root, id);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
afterEach(async () => {
|
|
49
|
+
await rm(root, { recursive: true, force: true });
|
|
50
|
+
vi.restoreAllMocks();
|
|
51
|
+
});
|
|
52
|
+
it('IC-1: emits two entries for the same skill installed under two harnesses', async () => {
|
|
53
|
+
await createSkill('claude-code', 'foo', { version: '1.0.0' });
|
|
54
|
+
await createSkill('cursor', 'foo', { version: '2.0.0' });
|
|
55
|
+
const entries = await collectDeviceSkills();
|
|
56
|
+
const foo = entries.filter((e) => e.skill_id === 'foo');
|
|
57
|
+
expect(foo).toHaveLength(2);
|
|
58
|
+
expect(foo.map((e) => e.harness).sort()).toEqual(['claude-code', 'cursor']);
|
|
59
|
+
// Distinct realpaths -> distinct rows, each carrying its own version + hash.
|
|
60
|
+
expect(foo.every((e) => typeof e.content_hash === 'string')).toBe(true);
|
|
61
|
+
// Static fields are always null at the local-agent layer.
|
|
62
|
+
expect(foo.every((e) => e.source === null && e.pinned_version === null)).toBe(true);
|
|
63
|
+
expect(foo.every((e) => e.update_policy === null)).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
it('IC-2: collapses a symlinked alias across harnesses to one entry (first ClientId wins)', async () => {
|
|
66
|
+
const real = await createSkill('claude-code', 'bar', { version: '1.0.0' });
|
|
67
|
+
await mkdir(mockPaths.CLIENT_NATIVE_PATHS['agents'], { recursive: true });
|
|
68
|
+
await symlink(real, join(mockPaths.CLIENT_NATIVE_PATHS['agents'], 'bar'), 'dir');
|
|
69
|
+
const entries = await collectDeviceSkills();
|
|
70
|
+
const bar = entries.filter((e) => e.skill_id === 'bar');
|
|
71
|
+
expect(bar).toHaveLength(1);
|
|
72
|
+
// claude-code precedes agents in CLIENT_IDS, so it wins the dedup.
|
|
73
|
+
expect(bar[0]?.harness).toBe('claude-code');
|
|
74
|
+
});
|
|
75
|
+
// IC-4: No truncation at MAX_SKILLS boundary.
|
|
76
|
+
//
|
|
77
|
+
// The collector is intentionally uncapped — it returns EVERY on-disk entry.
|
|
78
|
+
// The >5000 ceiling is enforced server-side via the `too_many_skills` 400 error
|
|
79
|
+
// (see inventory-client tests) and will be covered end-to-end in Wave 5. This
|
|
80
|
+
// test verifies the guarantee cheaply using a small K so the suite stays fast.
|
|
81
|
+
it('IC-4: returned entry count equals the number of on-disk skills with no local cap applied', async () => {
|
|
82
|
+
const K = 4;
|
|
83
|
+
for (let i = 0; i < K; i++) {
|
|
84
|
+
await createSkill('claude-code', `skill-ic4-${i}`, { version: `1.0.${i}` });
|
|
85
|
+
}
|
|
86
|
+
const entries = await collectDeviceSkills();
|
|
87
|
+
const ic4 = entries.filter((e) => e.skill_id.startsWith('skill-ic4-'));
|
|
88
|
+
// The collector must not truncate: returned count must equal the on-disk count.
|
|
89
|
+
expect(ic4).toHaveLength(K);
|
|
90
|
+
// K is well below the server-enforced limit — no false ceiling here.
|
|
91
|
+
expect(K).toBeLessThan(INVENTORY_LIMITS.MAX_SKILLS);
|
|
92
|
+
});
|
|
93
|
+
it('IC-3: populates content_hash + version for readable SKILL.md, nulls for missing', async () => {
|
|
94
|
+
await createSkill('claude-code', 'withmd', { version: '3.1.4' });
|
|
95
|
+
await createSkill('cursor', 'nomd', { withSkillMd: false });
|
|
96
|
+
const entries = await collectDeviceSkills();
|
|
97
|
+
const withMd = entries.find((e) => e.skill_id === 'withmd');
|
|
98
|
+
const noMd = entries.find((e) => e.skill_id === 'nomd');
|
|
99
|
+
expect(withMd?.version).toBe('3.1.4');
|
|
100
|
+
expect(withMd?.content_hash).toMatch(/^[0-9a-f]{64}$/);
|
|
101
|
+
// A subdir with no readable SKILL.md still counts, keyed by its dir name.
|
|
102
|
+
expect(noMd).toBeDefined();
|
|
103
|
+
expect(noMd?.version).toBeNull();
|
|
104
|
+
expect(noMd?.content_hash).toBeNull();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=inventory-collector.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-collector.test.js","sourceRoot":"","sources":["../../../src/sync/inventory-collector.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,SAAS,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAClC,UAAU,EAAE,CAAC,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE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AAK,MAAM,CAAC,CAAA;QAEvD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACrC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;QAEtD,0EAA0E;QAC1E,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAA;QAC1B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAA;QAChC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAA;IACvC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device-identity builder for the cross-harness inventory payload
|
|
3
|
+
* (SMI-5392, umbrella SMI-5382).
|
|
4
|
+
*
|
|
5
|
+
* Produces the {@link InventoryDevice} half of an {@link InventoryUploadPayload}.
|
|
6
|
+
* Field minimization follows ADR-124: the raw hostname is NEVER sent by default
|
|
7
|
+
* (`hostname_display` is `null` this wave); only a salt-free sha256 `hostname_hash`
|
|
8
|
+
* is included as a soft duplicate-device hint. The hash is not trivially
|
|
9
|
+
* reversible, but a low-entropy hostname is dictionary-recoverable — this is
|
|
10
|
+
* acceptable per ADR-124 because the hash is scoped to the user's own
|
|
11
|
+
* authenticated account, never exposed cross-tenant.
|
|
12
|
+
*
|
|
13
|
+
* @module @skillsmith/core/sync/inventory-device
|
|
14
|
+
*/
|
|
15
|
+
import { type InventoryDevice } from './inventory-types.js';
|
|
16
|
+
/** Options accepted by {@link buildInventoryDevice}. */
|
|
17
|
+
export interface BuildInventoryDeviceOptions {
|
|
18
|
+
/** Skillsmith CLI version that produced the snapshot (defaults to `null`). */
|
|
19
|
+
cliVersion?: string | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build the {@link InventoryDevice} descriptor for this machine.
|
|
23
|
+
*
|
|
24
|
+
* - `device_id` is the stable client-generated UUID (created on first call).
|
|
25
|
+
* - `label` is the user's optional device label from `~/.skillsmith/config.json`
|
|
26
|
+
* (`inventory.deviceLabel`); there is no dedicated getter in `device-identity`,
|
|
27
|
+
* so it is read directly from config and capped to `LABEL_MAX`.
|
|
28
|
+
* - `hostname_display` is always `null` this wave (ADR-124 minimization).
|
|
29
|
+
* - `hostname_hash` is the sha256 hex of `os.hostname()` — a soft duplicate hint.
|
|
30
|
+
*
|
|
31
|
+
* @param opts - Optional CLI version to stamp on the snapshot.
|
|
32
|
+
* @returns A fully-minimized device descriptor.
|
|
33
|
+
* @see SMI-5392
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildInventoryDevice(opts?: BuildInventoryDeviceOptions): InventoryDevice;
|
|
36
|
+
//# sourceMappingURL=inventory-device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-device.d.ts","sourceRoot":"","sources":["../../../src/sync/inventory-device.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE7E,wDAAwD;AACxD,MAAM,WAAW,2BAA2B;IAC1C,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAYD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,CAAC,EAAE,2BAA2B,GAAG,eAAe,CAcxF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device-identity builder for the cross-harness inventory payload
|
|
3
|
+
* (SMI-5392, umbrella SMI-5382).
|
|
4
|
+
*
|
|
5
|
+
* Produces the {@link InventoryDevice} half of an {@link InventoryUploadPayload}.
|
|
6
|
+
* Field minimization follows ADR-124: the raw hostname is NEVER sent by default
|
|
7
|
+
* (`hostname_display` is `null` this wave); only a salt-free sha256 `hostname_hash`
|
|
8
|
+
* is included as a soft duplicate-device hint. The hash is not trivially
|
|
9
|
+
* reversible, but a low-entropy hostname is dictionary-recoverable — this is
|
|
10
|
+
* acceptable per ADR-124 because the hash is scoped to the user's own
|
|
11
|
+
* authenticated account, never exposed cross-tenant.
|
|
12
|
+
*
|
|
13
|
+
* @module @skillsmith/core/sync/inventory-device
|
|
14
|
+
*/
|
|
15
|
+
import { hostname } from 'node:os';
|
|
16
|
+
import { createHash } from 'node:crypto';
|
|
17
|
+
import { getOrCreateDeviceId } from '../config/device-identity.js';
|
|
18
|
+
import { loadConfig } from '../config/index.js';
|
|
19
|
+
import { INVENTORY_LIMITS } from './inventory-types.js';
|
|
20
|
+
/**
|
|
21
|
+
* Truncate `value` to at most `max` characters, returning `null` for nullish
|
|
22
|
+
* input. Guards every length-capped column so a malformed local value can't
|
|
23
|
+
* trip a DB CHECK constraint mid-reconcile.
|
|
24
|
+
*/
|
|
25
|
+
function capped(value, max) {
|
|
26
|
+
if (value == null)
|
|
27
|
+
return null;
|
|
28
|
+
return value.length > max ? value.slice(0, max) : value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build the {@link InventoryDevice} descriptor for this machine.
|
|
32
|
+
*
|
|
33
|
+
* - `device_id` is the stable client-generated UUID (created on first call).
|
|
34
|
+
* - `label` is the user's optional device label from `~/.skillsmith/config.json`
|
|
35
|
+
* (`inventory.deviceLabel`); there is no dedicated getter in `device-identity`,
|
|
36
|
+
* so it is read directly from config and capped to `LABEL_MAX`.
|
|
37
|
+
* - `hostname_display` is always `null` this wave (ADR-124 minimization).
|
|
38
|
+
* - `hostname_hash` is the sha256 hex of `os.hostname()` — a soft duplicate hint.
|
|
39
|
+
*
|
|
40
|
+
* @param opts - Optional CLI version to stamp on the snapshot.
|
|
41
|
+
* @returns A fully-minimized device descriptor.
|
|
42
|
+
* @see SMI-5392
|
|
43
|
+
*/
|
|
44
|
+
export function buildInventoryDevice(opts) {
|
|
45
|
+
const deviceId = getOrCreateDeviceId();
|
|
46
|
+
const deviceLabel = loadConfig().inventory?.deviceLabel;
|
|
47
|
+
const hostnameHash = createHash('sha256').update(hostname(), 'utf8').digest('hex');
|
|
48
|
+
return {
|
|
49
|
+
device_id: deviceId,
|
|
50
|
+
label: capped(deviceLabel, INVENTORY_LIMITS.LABEL_MAX),
|
|
51
|
+
hostname_display: null,
|
|
52
|
+
hostname_hash: capped(hostnameHash, INVENTORY_LIMITS.HOSTNAME_HASH_MAX),
|
|
53
|
+
platform: capped(process.platform, INVENTORY_LIMITS.PLATFORM_MAX),
|
|
54
|
+
arch: capped(process.arch, INVENTORY_LIMITS.ARCH_MAX),
|
|
55
|
+
cli_version: capped(opts?.cliVersion, INVENTORY_LIMITS.CLI_VERSION_MAX),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=inventory-device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-device.js","sourceRoot":"","sources":["../../../src/sync/inventory-device.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAwB,MAAM,sBAAsB,CAAA;AAQ7E;;;;GAIG;AACH,SAAS,MAAM,CAAC,KAAgC,EAAE,GAAW;IAC3D,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,IAAI,CAAA;IAC9B,OAAO,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AACzD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAkC;IACrE,MAAM,QAAQ,GAAG,mBAAmB,EAAE,CAAA;IACtC,MAAM,WAAW,GAAG,UAAU,EAAE,CAAC,SAAS,EAAE,WAAW,CAAA;IACvD,MAAM,YAAY,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAElF,OAAO;QACL,SAAS,EAAE,QAAQ;QACnB,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,SAAS,CAAC;QACtD,gBAAgB,EAAE,IAAI;QACtB,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,gBAAgB,CAAC,iBAAiB,CAAC;QACvE,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,gBAAgB,CAAC,YAAY,CAAC;QACjE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,gBAAgB,CAAC,QAAQ,CAAC;QACrD,WAAW,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,gBAAgB,CAAC,eAAe,CAAC;KACxE,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventory push orchestrator (SMI-5392, umbrella SMI-5382).
|
|
3
|
+
*
|
|
4
|
+
* The single entry point both the CLI command and the MCP tool call to push this
|
|
5
|
+
* device's inventory. Wires together the local opt-out gate, the payload builder,
|
|
6
|
+
* the upload client, and the auto-push throttle.
|
|
7
|
+
*
|
|
8
|
+
* @module @skillsmith/core/sync/inventory-push
|
|
9
|
+
*/
|
|
10
|
+
import type { BuildInventoryDeviceOptions } from './inventory-device.js';
|
|
11
|
+
import type { InventoryUploadResult } from './inventory-types.js';
|
|
12
|
+
/** Options accepted by {@link pushInventory}. */
|
|
13
|
+
export type PushInventoryOptions = BuildInventoryDeviceOptions;
|
|
14
|
+
/** Options accepted by {@link maybeAutoPush}. */
|
|
15
|
+
export interface MaybeAutoPushOptions extends BuildInventoryDeviceOptions {
|
|
16
|
+
/** Injectable clock for deterministic throttle tests (defaults to `Date.now()`). */
|
|
17
|
+
now?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build and upload this device's inventory snapshot.
|
|
21
|
+
*
|
|
22
|
+
* When the local opt-out flag (`SKILLSMITH_INVENTORY_DISABLE`) is set, this is a
|
|
23
|
+
* pure no-op: NO network call, and NO device-id creation. On a server-applied
|
|
24
|
+
* upload, the last-push timestamp is persisted for the auto-push throttle. A
|
|
25
|
+
* consent-off `{ applied: false, reason: 'consent_disabled' }` result is returned
|
|
26
|
+
* as-is and does NOT advance the throttle (so consent re-enablement pushes promptly).
|
|
27
|
+
*
|
|
28
|
+
* @param opts - Optional CLI version to stamp on the snapshot.
|
|
29
|
+
* @returns The upload result (or the local-disable no-op).
|
|
30
|
+
* @see SMI-5392
|
|
31
|
+
*/
|
|
32
|
+
export declare function pushInventory(opts?: PushInventoryOptions): Promise<InventoryUploadResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Auto-push entry point for the session-start hook.
|
|
35
|
+
*
|
|
36
|
+
* Returns `null` (without pushing) when sync is locally disabled or the throttle
|
|
37
|
+
* window has not elapsed. Upload errors are SWALLOWED — an auto-push must never
|
|
38
|
+
* throw into a session hook — logged to `console.error` and reported as `null`.
|
|
39
|
+
*
|
|
40
|
+
* @param opts - Optional CLI version + injectable clock.
|
|
41
|
+
* @returns The upload result, or `null` when skipped / throttled / errored.
|
|
42
|
+
* @see SMI-5392
|
|
43
|
+
*/
|
|
44
|
+
export declare function maybeAutoPush(opts?: MaybeAutoPushOptions): Promise<InventoryUploadResult | null>;
|
|
45
|
+
//# sourceMappingURL=inventory-push.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-push.d.ts","sourceRoot":"","sources":["../../../src/sync/inventory-push.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAEjE,iDAAiD;AACjD,MAAM,MAAM,oBAAoB,GAAG,2BAA2B,CAAA;AAE9D,iDAAiD;AACjD,MAAM,WAAW,oBAAqB,SAAQ,2BAA2B;IACvE,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CAAC,IAAI,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAa/F;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,IAAI,CAAC,EAAE,oBAAoB,GAC1B,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAYvC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventory push orchestrator (SMI-5392, umbrella SMI-5382).
|
|
3
|
+
*
|
|
4
|
+
* The single entry point both the CLI command and the MCP tool call to push this
|
|
5
|
+
* device's inventory. Wires together the local opt-out gate, the payload builder,
|
|
6
|
+
* the upload client, and the auto-push throttle.
|
|
7
|
+
*
|
|
8
|
+
* @module @skillsmith/core/sync/inventory-push
|
|
9
|
+
*/
|
|
10
|
+
import { getLastInventoryPushAt, isInventorySyncDisabledLocally, recordInventoryPush, shouldAutoPush, } from '../config/device-identity.js';
|
|
11
|
+
import { buildInventoryPayload } from './inventory-builder.js';
|
|
12
|
+
import { uploadInventory } from './inventory-client.js';
|
|
13
|
+
/**
|
|
14
|
+
* Build and upload this device's inventory snapshot.
|
|
15
|
+
*
|
|
16
|
+
* When the local opt-out flag (`SKILLSMITH_INVENTORY_DISABLE`) is set, this is a
|
|
17
|
+
* pure no-op: NO network call, and NO device-id creation. On a server-applied
|
|
18
|
+
* upload, the last-push timestamp is persisted for the auto-push throttle. A
|
|
19
|
+
* consent-off `{ applied: false, reason: 'consent_disabled' }` result is returned
|
|
20
|
+
* as-is and does NOT advance the throttle (so consent re-enablement pushes promptly).
|
|
21
|
+
*
|
|
22
|
+
* @param opts - Optional CLI version to stamp on the snapshot.
|
|
23
|
+
* @returns The upload result (or the local-disable no-op).
|
|
24
|
+
* @see SMI-5392
|
|
25
|
+
*/
|
|
26
|
+
export async function pushInventory(opts) {
|
|
27
|
+
if (isInventorySyncDisabledLocally()) {
|
|
28
|
+
return { ok: true, applied: false, reason: 'disabled_locally' };
|
|
29
|
+
}
|
|
30
|
+
const payload = await buildInventoryPayload(opts);
|
|
31
|
+
const result = await uploadInventory(payload);
|
|
32
|
+
if (result.applied) {
|
|
33
|
+
recordInventoryPush(new Date().toISOString());
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Auto-push entry point for the session-start hook.
|
|
39
|
+
*
|
|
40
|
+
* Returns `null` (without pushing) when sync is locally disabled or the throttle
|
|
41
|
+
* window has not elapsed. Upload errors are SWALLOWED — an auto-push must never
|
|
42
|
+
* throw into a session hook — logged to `console.error` and reported as `null`.
|
|
43
|
+
*
|
|
44
|
+
* @param opts - Optional CLI version + injectable clock.
|
|
45
|
+
* @returns The upload result, or `null` when skipped / throttled / errored.
|
|
46
|
+
* @see SMI-5392
|
|
47
|
+
*/
|
|
48
|
+
export async function maybeAutoPush(opts) {
|
|
49
|
+
if (isInventorySyncDisabledLocally())
|
|
50
|
+
return null;
|
|
51
|
+
const now = opts?.now ?? Date.now();
|
|
52
|
+
if (!shouldAutoPush(now, getLastInventoryPushAt()))
|
|
53
|
+
return null;
|
|
54
|
+
try {
|
|
55
|
+
return await pushInventory(opts);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('[skillsmith] inventory auto-push failed:', error);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=inventory-push.js.map
|
|
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CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAA;QAChE,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* inventory-push tests (SMI-5392).
|
|
3
|
+
*
|
|
4
|
+
* Mocks the payload builder and upload client; keeps the real (pure)
|
|
5
|
+
* `isInventorySyncDisabledLocally` + `shouldAutoPush` so the env-flag and
|
|
6
|
+
* throttle paths exercise production logic, while `recordInventoryPush` and
|
|
7
|
+
* `getLastInventoryPushAt` are stubbed for observation/control.
|
|
8
|
+
*
|
|
9
|
+
* IP-1: SKILLSMITH_INVENTORY_DISABLE set -> disabled_locally no-op, no upload.
|
|
10
|
+
* IP-2: applied result -> recordInventoryPush called.
|
|
11
|
+
* IP-3: consent-off result -> recordInventoryPush NOT called.
|
|
12
|
+
* IP-4: maybeAutoPush throttled (recent lastPushAt) -> null without pushing.
|
|
13
|
+
* IP-5: maybeAutoPush swallows an upload error and returns null.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=inventory-push.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory-push.test.d.ts","sourceRoot":"","sources":["../../../src/sync/inventory-push.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|