@solidactions/cli 1.29.0 → 1.31.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.
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sha256Hex = sha256Hex;
7
+ exports.hashFileOrNull = hashFileOrNull;
8
+ exports.readManifest = readManifest;
9
+ exports.onDiskHashes = onDiskHashes;
10
+ exports.writeFileAtomic = writeFileAtomic;
11
+ exports.applyCachePlan = applyCachePlan;
12
+ exports.withCacheLock = withCacheLock;
13
+ /**
14
+ * Filesystem side of the host skill cache: hashing, atomic writes, the
15
+ * per-cache-key lock, and plan application. Kept separate from the pure
16
+ * planner (skill-cache.ts) so planning stays unit-testable without fs.
17
+ *
18
+ * Write protocol: every managed file is written via temp-file + rename in the
19
+ * same directory (atomic on POSIX); the manifest is written LAST, so a crash
20
+ * mid-refresh leaves a manifest that simply mismatches on the next run and
21
+ * triggers a clean re-refresh. Per-file renames also mean a concurrently
22
+ * RUNNING exec keeps its already-open scripts.
23
+ *
24
+ * Lock ownership: the lock dir carries an `owner` token file written right
25
+ * after `mkdirSync` succeeds. A stale-lock takeover removes the whole dir
26
+ * (token included) before re-acquiring, and release only removes the lock
27
+ * dir when its `owner` file still matches our token — so a holder that ran
28
+ * past the staleness window and had its lock stolen can't rm the new
29
+ * holder's lock out from under it. If a concurrent stale-takeover `rmSync`
30
+ * lands between our `mkdirSync` and the `owner` write, that write sees
31
+ * ENOENT — treated as having lost the race, so acquisition retries.
32
+ */
33
+ const crypto_1 = __importDefault(require("crypto"));
34
+ const fs_1 = __importDefault(require("fs"));
35
+ const path_1 = __importDefault(require("path"));
36
+ const skill_cache_1 = require("./skill-cache");
37
+ function sha256Hex(data) {
38
+ return crypto_1.default.createHash('sha256').update(data).digest('hex');
39
+ }
40
+ function hashFileOrNull(filePath) {
41
+ try {
42
+ return sha256Hex(fs_1.default.readFileSync(filePath));
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ function readManifest(cacheDir) {
49
+ try {
50
+ const parsed = JSON.parse(fs_1.default.readFileSync(path_1.default.join(cacheDir, skill_cache_1.CACHE_MANIFEST), 'utf8'));
51
+ if (parsed?.schema_version !== 1 || typeof parsed?.files !== 'object' || parsed.files === null || Array.isArray(parsed.files))
52
+ return null;
53
+ return parsed;
54
+ }
55
+ catch {
56
+ return null;
57
+ }
58
+ }
59
+ function onDiskHashes(cacheDir, paths) {
60
+ const out = {};
61
+ for (const p of paths) {
62
+ out[p] = hashFileOrNull(path_1.default.join(cacheDir, p));
63
+ }
64
+ return out;
65
+ }
66
+ function writeFileAtomic(target, data) {
67
+ fs_1.default.mkdirSync(path_1.default.dirname(target), { recursive: true });
68
+ const tmp = path_1.default.join(path_1.default.dirname(target), `.tmp-${process.pid}-${crypto_1.default.randomBytes(4).toString('hex')}`);
69
+ fs_1.default.writeFileSync(tmp, data);
70
+ fs_1.default.renameSync(tmp, target);
71
+ }
72
+ function applyCachePlan(cacheDir, plan, contents, manifest) {
73
+ fs_1.default.mkdirSync(cacheDir, { recursive: true, mode: 0o700 });
74
+ for (const rel of plan.writes) {
75
+ if (!(rel in contents)) {
76
+ throw new Error(`applyCachePlan: no content provided for planned write '${rel}'`);
77
+ }
78
+ writeFileAtomic(path_1.default.join(cacheDir, rel), contents[rel]);
79
+ }
80
+ for (const rel of plan.deletes) {
81
+ fs_1.default.rmSync(path_1.default.join(cacheDir, rel), { force: true });
82
+ }
83
+ writeFileAtomic(path_1.default.join(cacheDir, skill_cache_1.CACHE_MANIFEST), JSON.stringify(manifest, null, 2) + '\n');
84
+ }
85
+ const LOCK_STALE_MS = 120_000;
86
+ const LOCK_TIMEOUT_MS = 20_000;
87
+ const LOCK_POLL_MS = 100;
88
+ async function withCacheLock(cacheDir, fn) {
89
+ const lockDir = cacheDir + '.lock';
90
+ fs_1.default.mkdirSync(path_1.default.dirname(lockDir), { recursive: true });
91
+ const deadline = Date.now() + LOCK_TIMEOUT_MS;
92
+ const token = `${process.pid}-${crypto_1.default.randomBytes(8).toString('hex')}`;
93
+ for (;;) {
94
+ if (Date.now() > deadline) {
95
+ throw new Error(`timed out waiting for skill cache lock: ${lockDir} (another exec running? delete it if stale)`);
96
+ }
97
+ try {
98
+ fs_1.default.mkdirSync(lockDir);
99
+ fs_1.default.writeFileSync(path_1.default.join(lockDir, 'owner'), token);
100
+ break;
101
+ }
102
+ catch (e) {
103
+ if (e?.code !== 'EEXIST' && e?.code !== 'ENOENT')
104
+ throw e;
105
+ let stale = false;
106
+ try {
107
+ stale = Date.now() - fs_1.default.statSync(lockDir).mtimeMs > LOCK_STALE_MS;
108
+ }
109
+ catch {
110
+ continue; // holder just released — retry immediately
111
+ }
112
+ if (stale) {
113
+ try {
114
+ fs_1.default.rmSync(lockDir, { recursive: true, force: true });
115
+ }
116
+ catch { /* raced another taker */ }
117
+ continue;
118
+ }
119
+ await new Promise((r) => setTimeout(r, LOCK_POLL_MS));
120
+ }
121
+ }
122
+ try {
123
+ return await fn();
124
+ }
125
+ finally {
126
+ try {
127
+ if (fs_1.default.readFileSync(path_1.default.join(lockDir, 'owner'), 'utf8') === token) {
128
+ fs_1.default.rmSync(lockDir, { recursive: true, force: true });
129
+ }
130
+ }
131
+ catch { /* lock missing or owned by someone else — best-effort, do nothing */ }
132
+ }
133
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CACHE_MANIFEST = void 0;
7
+ exports.artifactIdentity = artifactIdentity;
8
+ exports.sanitizeSegment = sanitizeSegment;
9
+ exports.cacheOrigin = cacheOrigin;
10
+ exports.cacheDirFor = cacheDirFor;
11
+ exports.planCacheRefresh = planCacheRefresh;
12
+ /**
13
+ * Pure cache-planning core for `skill exec --target host`.
14
+ *
15
+ * The executed artifact is identified by {doc_id, published, execution_revision_id}:
16
+ * reads serve ACTIVE-SNAPSHOT content when published (head may be newer), so the
17
+ * execution revision is active_snapshot_revision_id when published and
18
+ * head_revision_id only for unpublished drafts. Comparing head alone would run
19
+ * stale cached content after a publish that promotes without moving head.
20
+ *
21
+ * planCacheRefresh() is deliberately pure (no fs, no network) so cache
22
+ * correctness — noop detection, per-file skip, upstream deletions, local
23
+ * drift — is unit-testable. The fs side lives in skill-cache-fs.ts.
24
+ */
25
+ const os_1 = __importDefault(require("os"));
26
+ const path_1 = __importDefault(require("path"));
27
+ const url_1 = require("url");
28
+ exports.CACHE_MANIFEST = '.sa-cache-manifest.json';
29
+ function toNum(v) {
30
+ if (v === null || v === undefined)
31
+ return null;
32
+ const n = typeof v === 'string' ? parseInt(v, 10) : v;
33
+ return Number.isNaN(n) ? null : n;
34
+ }
35
+ function artifactIdentity(bundle) {
36
+ const published = bundle.published !== false;
37
+ const executionRevisionId = published
38
+ // The `?? toNum(bundle.head_revision_id)` fallback guards a domain-unreachable
39
+ // state: a published doc without an active snapshot revision.
40
+ ? (toNum(bundle.active_snapshot_revision_id) ?? toNum(bundle.head_revision_id))
41
+ : toNum(bundle.head_revision_id);
42
+ return { docId: toNum(bundle.doc_id), published, executionRevisionId };
43
+ }
44
+ function sanitizeSegment(s) {
45
+ return s.replace(/[^a-zA-Z0-9._-]/g, '_');
46
+ }
47
+ /**
48
+ * Cache identity for "which server + which workspace": host authority (host:port)
49
+ * plus the canonical workspace id. NOT the workspace slug — Config distinguishes
50
+ * cosmetic `workspace` from canonical `workspaceId`, and custom hosts may collide
51
+ * on ids alone.
52
+ */
53
+ function cacheOrigin(config) {
54
+ const authority = new url_1.URL(config.host).host; // host[:port]
55
+ return `${sanitizeSegment(authority)}__${sanitizeSegment(config.workspaceId ?? 'default')}`;
56
+ }
57
+ function cacheDirFor(config, scope, skillName) {
58
+ const base = path_1.default.join(os_1.default.homedir(), '.solidactions', 'cache', 'skills', cacheOrigin(config));
59
+ const scopeSegs = scope.kind === 'shared'
60
+ ? ['shared']
61
+ : [sanitizeSegment(scope.crewPath), sanitizeSegment(scope.role)];
62
+ return path_1.default.join(base, ...scopeSegs, sanitizeSegment(skillName));
63
+ }
64
+ function planCacheRefresh(args) {
65
+ const { manifest, origin, identity, desired, onDisk } = args;
66
+ const mfiles = manifest?.files ?? {};
67
+ const identityOk = !!manifest
68
+ && manifest.schema_version === 1
69
+ && manifest.origin === origin
70
+ && manifest.doc_id === identity.docId
71
+ && manifest.published === identity.published
72
+ && manifest.execution_revision_id === identity.executionRevisionId;
73
+ const writes = [];
74
+ for (const [p, spec] of Object.entries(desired)) {
75
+ const m = mfiles[p];
76
+ const upstreamSame = !!m && (spec.kind === 'text' ? m.sha256 === spec.sha256 : m.blob_sha === spec.blobSha);
77
+ const diskSame = !!m && onDisk[p] !== null && onDisk[p] !== undefined && onDisk[p] === m.sha256;
78
+ if (!upstreamSame || !diskSame)
79
+ writes.push(p);
80
+ }
81
+ const deletes = Object.keys(mfiles).filter((p) => !(p in desired));
82
+ const action = !identityOk || writes.length > 0 || deletes.length > 0 ? 'refresh' : 'noop';
83
+ return { action, writes: action === 'noop' ? [] : writes, deletes: action === 'noop' ? [] : deletes };
84
+ }
@@ -16,6 +16,7 @@ const SKILL_NAMES = [
16
16
  'solidactions-workflow-coding',
17
17
  'solidactions-deploy-and-config',
18
18
  'solidactions-oauth-actions',
19
+ 'solidactions-crew-skills',
19
20
  ];
20
21
  const EXAMPLES_OWNER = 'SolidActions';
21
22
  const EXAMPLES_REPO = 'solidactions-examples';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidactions/cli",
3
- "version": "1.29.0",
3
+ "version": "1.31.0",
4
4
  "description": "SolidActions CLI - Deploy and manage workflow automation",
5
5
  "main": "dist/index.js",
6
6
  "bin": {