castle-web-cli 0.4.195 → 0.4.196

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 (2) hide show
  1. package/dist/agent.js +46 -1
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -1858,10 +1858,55 @@ function writeTaskIndex(tasksDir, tasks) {
1858
1858
  // persisted "blocked" task is left as-is: it is not "waiting", so maybeStart
1859
1859
  // never reconsiders it and it can't wedge or auto-start; it just sits on the
1860
1860
  // board (blockedBy intact) until the router stops it, same as before restart.
1861
+ const TASK_STATUSES = ['waiting', 'running', 'blocked', 'done', 'failed', 'interrupted'];
1862
+ const TASK_OPTIONAL_STRINGS = [
1863
+ 'item', 'startedAt', 'finishedAt', 'originMessageId', 'resultSummary', 'errorCopy',
1864
+ 'errorDetail', 'avatar', 'phase', 'durable', 'what',
1865
+ ];
1866
+ const TASK_OPTIONAL_BOOLEANS = ['acknowledged', 'rejected', 'durablePending'];
1867
+ const TASK_OPTIONAL_STRING_LISTS = ['playtestFrames', 'files', 'knobs', 'blockedBy'];
1868
+ const isStringList = (v) => Array.isArray(v) && v.every((s) => typeof s === 'string');
1869
+ // tasks/ sits in the deck, where the agent (or anything else) can write, and a
1870
+ // record the store can't handle used to throw inside createTaskStore and take
1871
+ // the whole serve down -- the deck then couldn't be opened at all. A record
1872
+ // without its identity (id matching its directory, title, createdAt, a known
1873
+ // status) is skipped; anything else that is missing or the wrong type falls
1874
+ // back to its default or is dropped, which also keeps older minimal records.
1875
+ function normalizeLoadedTask(entry, raw) {
1876
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
1877
+ return null;
1878
+ const r = raw;
1879
+ if (r.id !== entry ||
1880
+ typeof r.title !== 'string' ||
1881
+ typeof r.createdAt !== 'string' ||
1882
+ !TASK_STATUSES.includes(r.status)) {
1883
+ return null;
1884
+ }
1885
+ const task = {
1886
+ ...r,
1887
+ prompt: typeof r.prompt === 'string' ? r.prompt : '',
1888
+ after: isStringList(r.after) ? r.after : [],
1889
+ progress: typeof r.progress === 'number' && Number.isFinite(r.progress) ? r.progress : 0,
1890
+ notes: typeof r.notes === 'string' ? r.notes : '',
1891
+ updatedAt: typeof r.updatedAt === 'string' ? r.updatedAt : r.createdAt,
1892
+ };
1893
+ if (typeof r.pid !== 'number')
1894
+ delete task.pid;
1895
+ for (const k of TASK_OPTIONAL_STRINGS)
1896
+ if (typeof r[k] !== 'string')
1897
+ delete task[k];
1898
+ for (const k of TASK_OPTIONAL_BOOLEANS)
1899
+ if (typeof r[k] !== 'boolean')
1900
+ delete task[k];
1901
+ for (const k of TASK_OPTIONAL_STRING_LISTS)
1902
+ if (!isStringList(r[k]))
1903
+ delete task[k];
1904
+ return task;
1905
+ }
1861
1906
  function loadTasks(tasksDir) {
1862
1907
  const tasks = new Map();
1863
1908
  for (const entry of fs.existsSync(tasksDir) ? fs.readdirSync(tasksDir) : []) {
1864
- const rec = readJsonFile(path.join(tasksDir, entry, 'task.json'));
1909
+ const rec = normalizeLoadedTask(entry, readJsonFile(path.join(tasksDir, entry, 'task.json')));
1865
1910
  if (!rec)
1866
1911
  continue;
1867
1912
  if (rec.status === 'running' || rec.status === 'waiting') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.195",
3
+ "version": "0.4.196",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"