@sogni-ai/sogni-creative-agent-skill 3.71.1 → 3.72.1

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.
Files changed (32) hide show
  1. package/.agents/skills/sogni-creative-agent-skill/SKILL.md +1 -1
  2. package/.agents/skills/sogni-creative-agent-skill/references/h3-video-loras.md +3 -3
  3. package/.agents/skills/sogni-creative-agent-skill/references/hosted-api.md +2 -2
  4. package/.agents/skills/sogni-creative-agent-skill/references/image-prompting.md +1 -1
  5. package/.agents/skills/sogni-creative-agent-skill/references/long-jobs-and-queues.md +57 -0
  6. package/.agents/skills/sogni-creative-agent-skill/references/models.md +2 -2
  7. package/.agents/skills/sogni-creative-agent-skill/references/private-mature-video.md +1 -2
  8. package/.agents/skills/sogni-creative-agent-skill/references/video-prompting.md +10 -10
  9. package/.claude-plugin/plugin.json +1 -1
  10. package/.codex-plugin/plugin.json +1 -1
  11. package/CHANGELOG.md +13 -0
  12. package/README.md +8 -5
  13. package/SKILL.md +6 -6
  14. package/desktop-extension/manifest.json +1 -1
  15. package/generated/creative-agent-runtime.mjs +1 -1
  16. package/llm.txt +5 -0
  17. package/openclaw.plugin.json +1 -1
  18. package/package.json +5 -3
  19. package/plugin-skills/sogni-creative-agent/SKILL.md +2 -2
  20. package/progress-events.mjs +186 -0
  21. package/references/h3-video-loras.md +3 -3
  22. package/references/hosted-api.md +2 -2
  23. package/references/image-prompting.md +1 -1
  24. package/references/long-jobs-and-queues.md +57 -0
  25. package/references/models.md +2 -2
  26. package/references/private-mature-video.md +1 -2
  27. package/references/video-prompting.md +10 -10
  28. package/render-accounting.mjs +213 -0
  29. package/skill-package.json +1 -1
  30. package/sogni-agent.mjs +790 -54
  31. package/sogni-app-id.mjs +141 -45
  32. package/version.mjs +1 -1
package/sogni-app-id.mjs CHANGED
@@ -24,8 +24,10 @@ import {
24
24
  openSync,
25
25
  readFileSync,
26
26
  readdirSync,
27
+ statSync,
27
28
  unlinkSync,
28
29
  writeFileSync,
30
+ writeSync,
29
31
  } from 'node:fs';
30
32
  import { homedir } from 'node:os';
31
33
  import { basename, dirname, join } from 'node:path';
@@ -66,6 +68,86 @@ function readPersistedAppId(appIdPath) {
66
68
  return validateAppId(readFileSync(appIdPath, 'utf8'), `Sogni app-id file ${appIdPath}`);
67
69
  }
68
70
 
71
+ // Filesystems without hard links (FAT/exFAT, ReFS, some SMB/NFS/FUSE homes) refuse
72
+ // linkSync with one of these codes. There, a file is published the old way, an
73
+ // exclusive create followed by a write, so it is empty for a moment: a reader
74
+ // treats an empty or unparsable file younger than CREATE_GRACE_MS as still
75
+ // being written, never as corrupt or stale.
76
+ const NO_HARD_LINK_CODES = new Set(['EPERM', 'ENOTSUP', 'EOPNOTSUPP', 'ENOSYS', 'EXDEV']);
77
+ const CREATE_GRACE_MS = 5_000;
78
+ const READ_RETRY_MS = 25;
79
+
80
+ function sleepSync(ms) {
81
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
82
+ }
83
+
84
+ // A future mtime (clock skew on network or FUSE homes) is never fresh: it would
85
+ // otherwise stay "being written" for as long as the skew lasts. A file written
86
+ // a moment ago can still read a little ahead of Date.now(), which drops the
87
+ // fraction of the current millisecond that mtimeMs keeps (CI, 2026-11-20), so
88
+ // up to MTIME_AHEAD_TOLERANCE_MS ahead still counts as fresh.
89
+ const MTIME_AHEAD_TOLERANCE_MS = 1_000;
90
+
91
+ function isFreshlyCreated(path) {
92
+ try {
93
+ const age = Date.now() - statSync(path).mtimeMs;
94
+ return age > -MTIME_AHEAD_TOLERANCE_MS && age < CREATE_GRACE_MS;
95
+ } catch {
96
+ return false;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Create `path` holding `contents` unless it already exists; true when this call
102
+ * created it. Complete bytes appear at once through a hard link; where the
103
+ * filesystem has none, an exclusive create plus write (see NO_HARD_LINK_CODES).
104
+ */
105
+ function publishExclusive(path, contents) {
106
+ const temporaryPath = `${path}.${process.pid}.${randomUUID()}.tmp`;
107
+ writeFileSync(temporaryPath, contents, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
108
+ try {
109
+ linkSync(temporaryPath, path);
110
+ return true;
111
+ } catch (error) {
112
+ if (error?.code === 'EEXIST') return false;
113
+ if (!NO_HARD_LINK_CODES.has(error?.code)) throw error;
114
+ } finally {
115
+ try { unlinkSync(temporaryPath); } catch { /* best effort: only our temporary file */ }
116
+ }
117
+ let descriptor;
118
+ try {
119
+ descriptor = openSync(path, 'wx', 0o600);
120
+ } catch (error) {
121
+ if (error?.code === 'EEXIST') return false;
122
+ throw error;
123
+ }
124
+ try {
125
+ writeSync(descriptor, contents);
126
+ } catch (error) {
127
+ try { unlinkSync(path); } catch { /* best effort: our own empty file */ }
128
+ throw error;
129
+ } finally {
130
+ closeSync(descriptor);
131
+ }
132
+ return true;
133
+ }
134
+
135
+ /**
136
+ * Read an identity file, waiting out another process's create-then-write, but
137
+ * never longer than the grace period plus a second from when the wait began.
138
+ */
139
+ function readPersistedAppIdWhenWritten(appIdPath) {
140
+ const deadline = Date.now() + CREATE_GRACE_MS + 1_000;
141
+ for (;;) {
142
+ try {
143
+ return readPersistedAppId(appIdPath);
144
+ } catch (error) {
145
+ if (error?.code !== 'INVALID_APP_ID' || !isFreshlyCreated(appIdPath) || Date.now() >= deadline) throw error;
146
+ }
147
+ sleepSync(READ_RETRY_MS);
148
+ }
149
+ }
150
+
69
151
  function appIdPersistenceError(error, appIdPath) {
70
152
  if (error?.code === 'INVALID_APP_ID' || error?.code === 'APP_ID_POOL_EXHAUSTED') return error;
71
153
  const wrapped = new Error(`Could not persist the Sogni app ID at ${appIdPath}: ${error?.message || error}`);
@@ -80,7 +162,7 @@ function appIdPersistenceError(error, appIdPath) {
80
162
  */
81
163
  function getOrCreateAppIdFile(resolvedPath, generateUuid) {
82
164
  try {
83
- return readPersistedAppId(resolvedPath);
165
+ return readPersistedAppIdWhenWritten(resolvedPath);
84
166
  } catch (error) {
85
167
  if (error?.code !== 'ENOENT') throw error;
86
168
  }
@@ -90,21 +172,9 @@ function getOrCreateAppIdFile(resolvedPath, generateUuid) {
90
172
  `${GENERATED_APP_ID_PREFIX}${generateUuid()}`,
91
173
  'Generated Sogni app ID',
92
174
  );
93
- const temporaryPath = `${resolvedPath}.${process.pid}.${randomUUID()}.tmp`;
94
- try {
95
- writeFileSync(temporaryPath, `${candidate}\n`, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
96
- try {
97
- // A hard link publishes complete bytes atomically without replacing an
98
- // existing identity. Concurrent readers never see an empty first write.
99
- linkSync(temporaryPath, resolvedPath);
100
- return candidate;
101
- } catch (error) {
102
- if (error?.code !== 'EEXIST') throw error;
103
- return readPersistedAppId(resolvedPath);
104
- }
105
- } finally {
106
- try { unlinkSync(temporaryPath); } catch { /* best effort: only our temporary file */ }
107
- }
175
+ // Never replaces an existing identity; a loser reuses the winner's value.
176
+ if (publishExclusive(resolvedPath, `${candidate}\n`)) return candidate;
177
+ return readPersistedAppIdWhenWritten(resolvedPath);
108
178
  }
109
179
 
110
180
  function defaultIsPidAlive(pid) {
@@ -123,32 +193,67 @@ function leaseIsStale(leasePath, { isPidAlive, ownPid }) {
123
193
  record = JSON.parse(readFileSync(leasePath, 'utf8'));
124
194
  } catch (error) {
125
195
  if (error?.code === 'ENOENT') return false; // released while we looked
126
- return true; // unreadable/corrupt lease can never be released by its owner
196
+ // Empty or partial: still being written (no-hard-link create + write) while
197
+ // fresh; after that, a corrupt lease its owner can never release.
198
+ return !isFreshlyCreated(leasePath);
127
199
  }
128
200
  const pid = record?.pid;
129
- if (!Number.isInteger(pid) || pid <= 0) return true;
201
+ if (!Number.isInteger(pid) || pid <= 0) return !isFreshlyCreated(leasePath);
130
202
  // A lease naming our own pid cannot be live: this process acquires at most
131
203
  // one lease and caches it, so this is a leftover from a recycled pid.
132
204
  if (pid === ownPid) return true;
133
205
  return !isPidAlive(pid);
134
206
  }
135
207
 
208
+ // A lease appears with its record already inside: the record is written to a
209
+ // private temporary file and hard-linked into place, which fails with EEXIST
210
+ // while the slot is held. Creating the lease file first and writing it after
211
+ // left an empty file that a process starting at the same moment read as
212
+ // corrupt, judged stale, deleted and took, so two processes shared one app ID
213
+ // and the socket kicked the first mid-render with SWITCH_CONNECTION (six
214
+ // simultaneous starts gave three shared pairs in 30 of 30 rounds, 2026-11-19).
136
215
  function tryCreateLease(leasePath, ownPid) {
137
- let descriptor;
216
+ const record = {
217
+ pid: ownPid,
218
+ tool: basename(process.argv[1] || 'sogni-agent'),
219
+ acquiredAt: new Date().toISOString(),
220
+ };
221
+ return publishExclusive(leasePath, `${JSON.stringify(record)}\n`);
222
+ }
223
+
224
+ // A reclaim holds this lock only between re-checking a lease and replacing it.
225
+ // A lock older than this was left by a process that died mid-reclaim.
226
+ const RECLAIM_LOCK_STALE_MS = 30_000;
227
+
228
+ function tryCreateReclaimLock(lockPath) {
138
229
  try {
139
- descriptor = openSync(leasePath, 'wx', 0o600);
140
- const record = {
141
- pid: ownPid,
142
- tool: basename(process.argv[1] || 'sogni-agent'),
143
- acquiredAt: new Date().toISOString(),
144
- };
145
- writeFileSync(descriptor, `${JSON.stringify(record)}\n`, 'utf8');
230
+ closeSync(openSync(lockPath, 'wx', 0o600));
146
231
  return true;
147
232
  } catch (error) {
148
- if (error?.code === 'EEXIST') return false;
149
- throw error;
233
+ if (error?.code !== 'EEXIST') throw error;
234
+ }
235
+ try {
236
+ if (Date.now() - statSync(lockPath).mtimeMs < RECLAIM_LOCK_STALE_MS) return false;
237
+ unlinkSync(lockPath);
238
+ closeSync(openSync(lockPath, 'wx', 0o600));
239
+ return true;
240
+ } catch {
241
+ return false; // released, or another process took it first
242
+ }
243
+ }
244
+
245
+ // Replace a stale lease with ours. Only the process holding the slot's reclaim
246
+ // lock may delete a lease: without it, two starters that both judged the same
247
+ // dead lease stale could each delete the other's fresh lease and share the slot.
248
+ function reclaimStaleLease(leasePath, { isPidAlive, ownPid }) {
249
+ const lockPath = `${leasePath}.reclaim`;
250
+ if (!tryCreateReclaimLock(lockPath)) return false;
251
+ try {
252
+ if (!leaseIsStale(leasePath, { isPidAlive, ownPid })) return tryCreateLease(leasePath, ownPid);
253
+ try { unlinkSync(leasePath); } catch { /* already gone */ }
254
+ return tryCreateLease(leasePath, ownPid);
150
255
  } finally {
151
- if (descriptor !== undefined) closeSync(descriptor);
256
+ try { unlinkSync(lockPath); } catch { /* best effort */ }
152
257
  }
153
258
  }
154
259
 
@@ -166,16 +271,10 @@ function migrateLegacyAppId(poolDir, legacyAppIdPath) {
166
271
  } catch {
167
272
  return; // absent or corrupt legacy identity: nothing worth migrating
168
273
  }
169
- let descriptor;
170
- try {
171
- descriptor = openSync(join(poolDir, 'slot-0'), 'wx', 0o600);
172
- writeFileSync(descriptor, `${legacyValue}\n`, 'utf8');
173
- } catch (error) {
174
- if (error?.code !== 'EEXIST') throw error;
175
- return; // pool already initialized; leave the legacy file alone
176
- } finally {
177
- if (descriptor !== undefined) closeSync(descriptor);
178
- }
274
+ // Published by hard link, like every identity file, so a process starting at
275
+ // the same moment never reads an empty slot-0.
276
+ const slotPath = join(poolDir, 'slot-0');
277
+ if (!publishExclusive(slotPath, `${legacyValue}\n`)) return; // pool already initialized; leave the legacy file alone
179
278
  try { unlinkSync(legacyAppIdPath); } catch { /* best effort */ }
180
279
  }
181
280
 
@@ -208,10 +307,8 @@ function acquireSlotLease({ poolDir, poolMax, generateUuid, isPidAlive, ownPid,
208
307
  const appId = getOrCreateAppIdFile(slotPath, generateUuid);
209
308
  const leasePath = `${slotPath}.lease`;
210
309
  if (tryCreateLease(leasePath, ownPid)) return { appId, leasePath };
211
- if (leaseIsStale(leasePath, { isPidAlive, ownPid })) {
212
- try { unlinkSync(leasePath); } catch { /* another reclaimer won */ }
213
- if (tryCreateLease(leasePath, ownPid)) return { appId, leasePath };
214
- }
310
+ if (leaseIsStale(leasePath, { isPidAlive, ownPid })
311
+ && reclaimStaleLease(leasePath, { isPidAlive, ownPid })) return { appId, leasePath };
215
312
  }
216
313
  const error = new Error(`All ${poolMax} Sogni app-ID slots in ${poolDir} are leased by live processes.`);
217
314
  error.code = 'APP_ID_POOL_EXHAUSTED';
@@ -311,8 +408,7 @@ export function claimSogniAppIdSlot(appId, {
311
408
  try { pid = JSON.parse(readFileSync(leasePath, 'utf8'))?.pid ?? null; } catch { /* unreadable: still held */ }
312
409
  return { heldByPid: pid };
313
410
  }
314
- try { unlinkSync(leasePath); } catch { /* another reclaimer won */ }
315
- if (!tryCreateLease(leasePath, ownPid)) return { heldByPid: null };
411
+ if (!reclaimStaleLease(leasePath, { isPidAlive, ownPid })) return { heldByPid: null };
316
412
  }
317
413
  let released = false;
318
414
  const release = () => {
package/version.mjs CHANGED
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = '3.71.1';
1
+ export const PACKAGE_VERSION = '3.72.1';