@manifesto-ai/core 2.7.1 → 2.8.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/dist/index.d.ts CHANGED
@@ -775,16 +775,6 @@ declare const SystemState: z.ZodObject<{
775
775
  timestamp: z.ZodNumber;
776
776
  context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
777
777
  }, z.core.$strip>>;
778
- errors: z.ZodArray<z.ZodObject<{
779
- code: z.ZodString;
780
- message: z.ZodString;
781
- source: z.ZodObject<{
782
- actionId: z.ZodString;
783
- nodePath: z.ZodString;
784
- }, z.core.$strip>;
785
- timestamp: z.ZodNumber;
786
- context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
787
- }, z.core.$strip>>;
788
778
  pendingRequirements: z.ZodArray<z.ZodObject<{
789
779
  id: z.ZodString;
790
780
  type: z.ZodString;
@@ -833,16 +823,6 @@ declare const Snapshot: z.ZodObject<{
833
823
  timestamp: z.ZodNumber;
834
824
  context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
835
825
  }, z.core.$strip>>;
836
- errors: z.ZodArray<z.ZodObject<{
837
- code: z.ZodString;
838
- message: z.ZodString;
839
- source: z.ZodObject<{
840
- actionId: z.ZodString;
841
- nodePath: z.ZodString;
842
- }, z.core.$strip>;
843
- timestamp: z.ZodNumber;
844
- context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
845
- }, z.core.$strip>>;
846
826
  pendingRequirements: z.ZodArray<z.ZodObject<{
847
827
  id: z.ZodString;
848
828
  type: z.ZodString;
@@ -1139,16 +1119,6 @@ declare const SystemDelta: z.ZodObject<{
1139
1119
  timestamp: z.ZodNumber;
1140
1120
  context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1141
1121
  }, z.core.$strip>>>;
1142
- appendErrors: z.ZodArray<z.ZodObject<{
1143
- code: z.ZodString;
1144
- message: z.ZodString;
1145
- source: z.ZodObject<{
1146
- actionId: z.ZodString;
1147
- nodePath: z.ZodString;
1148
- }, z.core.$strip>;
1149
- timestamp: z.ZodNumber;
1150
- context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1151
- }, z.core.$strip>>;
1152
1122
  addRequirements: z.ZodArray<z.ZodObject<{
1153
1123
  id: z.ZodString;
1154
1124
  type: z.ZodString;
@@ -1215,16 +1185,6 @@ declare const ComputeResult: z.ZodObject<{
1215
1185
  timestamp: z.ZodNumber;
1216
1186
  context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1217
1187
  }, z.core.$strip>>>;
1218
- appendErrors: z.ZodArray<z.ZodObject<{
1219
- code: z.ZodString;
1220
- message: z.ZodString;
1221
- source: z.ZodObject<{
1222
- actionId: z.ZodString;
1223
- nodePath: z.ZodString;
1224
- }, z.core.$strip>;
1225
- timestamp: z.ZodNumber;
1226
- context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1227
- }, z.core.$strip>>;
1228
1188
  addRequirements: z.ZodArray<z.ZodObject<{
1229
1189
  id: z.ZodString;
1230
1190
  type: z.ZodString;
@@ -1365,6 +1325,15 @@ declare function validate(schema: unknown): ValidationResult;
1365
1325
  */
1366
1326
  declare function explain(schema: DomainSchema, snapshot: Snapshot, path: SemanticPath): ExplainResult;
1367
1327
 
1328
+ /**
1329
+ * Check whether an action is available for a new invocation.
1330
+ */
1331
+ declare function isActionAvailable(schema: DomainSchema, snapshot: Snapshot, actionName: string): boolean;
1332
+ /**
1333
+ * Return all currently dispatchable actions in schema key order.
1334
+ */
1335
+ declare function getAvailableActions(schema: DomainSchema, snapshot: Snapshot): readonly string[];
1336
+
1368
1337
  /**
1369
1338
  * ComputedFieldSpec - Definition of a single computed field
1370
1339
  */
@@ -1779,10 +1748,18 @@ interface ManifestoCore {
1779
1748
  * Explain why a value is what it is.
1780
1749
  */
1781
1750
  explain(schema: DomainSchema, snapshot: Snapshot, path: SemanticPath): ExplainResult;
1751
+ /**
1752
+ * Check whether an action is currently dispatchable.
1753
+ */
1754
+ isActionAvailable(schema: DomainSchema, snapshot: Snapshot, actionName: string): boolean;
1755
+ /**
1756
+ * Return all currently dispatchable action names.
1757
+ */
1758
+ getAvailableActions(schema: DomainSchema, snapshot: Snapshot): readonly string[];
1782
1759
  }
1783
1760
  /**
1784
1761
  * Create a ManifestoCore instance
1785
1762
  */
1786
1763
  declare function createCore(): ManifestoCore;
1787
1764
 
1788
- export { AbsExpr, ActionSpec, AddExpr, AndExpr, AppendExpr, AtExpr, CallFlow, CeilExpr, CoalesceExpr, ComputeResult, ComputeStatus, ComputedFieldSpec, ComputedSpec, ConcatExpr, CoreErrorCode, type DependencyGraph, DivExpr, DomainSchema, EffectFlow, EndsWithExpr, EntriesExpr, EnumFieldType, EqExpr, ErrorValue, type EvalContext, EveryExpr, ExplainResult, ExprKind, type ExprNode, ExprNodeSchema, type ExprResult, FailFlow, FieldExpr, FieldSpec, FieldType, FilterExpr, FindExpr, FirstExpr, FlatExpr, FloorExpr, FlowKind, type FlowNode, FlowNodeSchema, FlowPosition, type FlowResult, type FlowState, type FlowStatus, FromEntriesExpr, GetExpr, GtExpr, GteExpr, HaltFlow, HasKeyExpr, HostContext, IfExpr, IfFlow, IncludesExpr, IndexOfExpr, Intent, IsNullExpr, KeysExpr, LastExpr, LenExpr, LitExpr, LtExpr, LteExpr, type ManifestoCore, MapExpr, MaxArrayExpr, MaxExpr, MergeExpr, type MergePatch, MinArrayExpr, MinExpr, ModExpr, MulExpr, NegExpr, NeqExpr, NotExpr, ObjectExpr, OmitExpr, OrExpr, Patch, PatchFlow, PatchOp, PatchPath, PatchSegment, PickExpr, PowExpr, PrimitiveFieldType, ReplaceExpr, Requirement, Result, ReverseExpr, RoundExpr, type SchemaHashInput, type SchemaHashMode, SchemaMeta, SemanticPath, SeqFlow, type SetPatch, SliceExpr, Snapshot, SnapshotMeta, SomeExpr, SplitExpr, SqrtExpr, StartsWithExpr, StateSpec, StrIncludesExpr, StrLenExpr, SubExpr, SubstringExpr, SumArrayExpr, SystemDelta, SystemState, ToBooleanExpr, ToLowerCaseExpr, ToNumberExpr, ToStringExpr, ToUpperCaseExpr, type TraceContext, TraceGraph, TraceNode, TraceNodeKind, TraceTermination, TrimExpr, TypeDefinition, TypeSpec, TypeofExpr, UniqueExpr, type UnsetPatch, ValidationError, ValidationResult, ValuesExpr, apply, applySystemDelta, buildDependencyGraph, canonicalEqual, compareUnicodeCodePoints, compute, computeSync, createContext, createCore, createError, createFlowState, createInitialSystemState, createIntent, createSnapshot, createTraceContext, createTraceNode, detectCycles, err, evaluateComputed, evaluateExpr, evaluateFlow, evaluateFlowSync, evaluateSingleComputed, explain, extractDefaults, fromCanonical, generateRequirementId, generateRequirementIdSync, generateTraceId, getByPatchPath, getByPath, getTransitiveDeps, hasPath, hashSchema, hashSchemaEffective, hashSchemaEffectiveSync, hashSchemaSync, indexSegment, invalidResult, isErr, isErrorValue, isOk, isSafePatchPath, joinPath, lastSegment, mergeAtPatchPath, mergeAtPath, mergePatch, ok, parentPath, parsePath, patchPathToDisplayString, propSegment, semanticPathToPatchPath, setByPatchPath, setByPath, setPatch, sha256, sha256Sync, sortKeys, toCanonical, toJcs, topologicalSort, unsetByPatchPath, unsetByPath, unsetPatch, validResult, validate, withCollectionContext, withNodePath, withSnapshot };
1765
+ export { AbsExpr, ActionSpec, AddExpr, AndExpr, AppendExpr, AtExpr, CallFlow, CeilExpr, CoalesceExpr, ComputeResult, ComputeStatus, ComputedFieldSpec, ComputedSpec, ConcatExpr, CoreErrorCode, type DependencyGraph, DivExpr, DomainSchema, EffectFlow, EndsWithExpr, EntriesExpr, EnumFieldType, EqExpr, ErrorValue, type EvalContext, EveryExpr, ExplainResult, ExprKind, type ExprNode, ExprNodeSchema, type ExprResult, FailFlow, FieldExpr, FieldSpec, FieldType, FilterExpr, FindExpr, FirstExpr, FlatExpr, FloorExpr, FlowKind, type FlowNode, FlowNodeSchema, FlowPosition, type FlowResult, type FlowState, type FlowStatus, FromEntriesExpr, GetExpr, GtExpr, GteExpr, HaltFlow, HasKeyExpr, HostContext, IfExpr, IfFlow, IncludesExpr, IndexOfExpr, Intent, IsNullExpr, KeysExpr, LastExpr, LenExpr, LitExpr, LtExpr, LteExpr, type ManifestoCore, MapExpr, MaxArrayExpr, MaxExpr, MergeExpr, type MergePatch, MinArrayExpr, MinExpr, ModExpr, MulExpr, NegExpr, NeqExpr, NotExpr, ObjectExpr, OmitExpr, OrExpr, Patch, PatchFlow, PatchOp, PatchPath, PatchSegment, PickExpr, PowExpr, PrimitiveFieldType, ReplaceExpr, Requirement, Result, ReverseExpr, RoundExpr, type SchemaHashInput, type SchemaHashMode, SchemaMeta, SemanticPath, SeqFlow, type SetPatch, SliceExpr, Snapshot, SnapshotMeta, SomeExpr, SplitExpr, SqrtExpr, StartsWithExpr, StateSpec, StrIncludesExpr, StrLenExpr, SubExpr, SubstringExpr, SumArrayExpr, SystemDelta, SystemState, ToBooleanExpr, ToLowerCaseExpr, ToNumberExpr, ToStringExpr, ToUpperCaseExpr, type TraceContext, TraceGraph, TraceNode, TraceNodeKind, TraceTermination, TrimExpr, TypeDefinition, TypeSpec, TypeofExpr, UniqueExpr, type UnsetPatch, ValidationError, ValidationResult, ValuesExpr, apply, applySystemDelta, buildDependencyGraph, canonicalEqual, compareUnicodeCodePoints, compute, computeSync, createContext, createCore, createError, createFlowState, createInitialSystemState, createIntent, createSnapshot, createTraceContext, createTraceNode, detectCycles, err, evaluateComputed, evaluateExpr, evaluateFlow, evaluateFlowSync, evaluateSingleComputed, explain, extractDefaults, fromCanonical, generateRequirementId, generateRequirementIdSync, generateTraceId, getAvailableActions, getByPatchPath, getByPath, getTransitiveDeps, hasPath, hashSchema, hashSchemaEffective, hashSchemaEffectiveSync, hashSchemaSync, indexSegment, invalidResult, isActionAvailable, isErr, isErrorValue, isOk, isSafePatchPath, joinPath, lastSegment, mergeAtPatchPath, mergeAtPath, mergePatch, ok, parentPath, parsePath, patchPathToDisplayString, propSegment, semanticPathToPatchPath, setByPatchPath, setByPath, setPatch, sha256, sha256Sync, sortKeys, toCanonical, toJcs, topologicalSort, unsetByPatchPath, unsetByPath, unsetPatch, validResult, validate, withCollectionContext, withNodePath, withSnapshot };
package/dist/index.js CHANGED
@@ -14220,17 +14220,6 @@ function withNodePath(ctx, nodePath) {
14220
14220
  return { ...ctx, nodePath };
14221
14221
  }
14222
14222
 
14223
- // src/schema/common.ts
14224
- var SemanticPath = external_exports.string().min(1);
14225
- var Result = (valueSchema, errorSchema) => external_exports.discriminatedUnion("ok", [
14226
- external_exports.object({ ok: external_exports.literal(true), value: valueSchema }),
14227
- external_exports.object({ ok: external_exports.literal(false), error: errorSchema })
14228
- ]);
14229
- var ok = (value) => ({ ok: true, value });
14230
- var err = (error48) => ({ ok: false, error: error48 });
14231
- var isOk = (result) => result.ok;
14232
- var isErr = (result) => !result.ok;
14233
-
14234
14223
  // src/utils/path.ts
14235
14224
  function parsePath(path) {
14236
14225
  if (!path) return [];
@@ -14361,6 +14350,174 @@ function joinPathPreserveEmptySegments(...segments) {
14361
14350
  return segments.map(escapePathSegment).join(".");
14362
14351
  }
14363
14352
 
14353
+ // src/utils/patch-path.ts
14354
+ var UNSAFE_PROP_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
14355
+ function patchPathToDisplayString(path) {
14356
+ let output = "";
14357
+ for (let i = 0; i < path.length; i++) {
14358
+ const segment = path[i];
14359
+ if (segment.kind === "prop") {
14360
+ output += i === 0 ? segment.name : `.${segment.name}`;
14361
+ continue;
14362
+ }
14363
+ output += `[${segment.index}]`;
14364
+ }
14365
+ return output;
14366
+ }
14367
+ function semanticPathToPatchPath(path) {
14368
+ const segments = parsePath(path);
14369
+ if (segments.length === 0) {
14370
+ return [{ kind: "prop", name: path }];
14371
+ }
14372
+ const patchPath = [];
14373
+ for (const segment of segments) {
14374
+ const parsed = parseBracketIndexedSegment(segment);
14375
+ if (parsed) {
14376
+ patchPath.push(...parsed);
14377
+ continue;
14378
+ }
14379
+ patchPath.push({ kind: "prop", name: segment });
14380
+ }
14381
+ return patchPath.length > 0 ? patchPath : [{ kind: "prop", name: path }];
14382
+ }
14383
+ function isSafePatchPath(path) {
14384
+ return path.every((segment) => segment.kind !== "prop" || !UNSAFE_PROP_SEGMENTS.has(segment.name));
14385
+ }
14386
+ function getByPatchPath(obj, path) {
14387
+ let current = obj;
14388
+ for (const segment of path) {
14389
+ if (segment.kind === "prop") {
14390
+ if (current === null || typeof current !== "object" || Array.isArray(current)) {
14391
+ return void 0;
14392
+ }
14393
+ current = current[segment.name];
14394
+ continue;
14395
+ }
14396
+ if (!Array.isArray(current)) {
14397
+ return void 0;
14398
+ }
14399
+ current = current[segment.index];
14400
+ }
14401
+ return current;
14402
+ }
14403
+ function setByPatchPath(obj, path, value) {
14404
+ return setBySegments(obj, path, value);
14405
+ }
14406
+ function unsetByPatchPath(obj, path) {
14407
+ return unsetBySegments(obj, path);
14408
+ }
14409
+ function mergeAtPatchPath(obj, path, value) {
14410
+ const existing = getByPatchPath(obj, path);
14411
+ const merged = isRecord(existing) ? { ...existing, ...value } : value;
14412
+ return setByPatchPath(obj, path, merged);
14413
+ }
14414
+ function setBySegments(obj, segments, value) {
14415
+ if (segments.length === 0) {
14416
+ return value;
14417
+ }
14418
+ const [head, ...tail] = segments;
14419
+ if (head.kind === "prop") {
14420
+ const current2 = isRecord(obj) ? obj : {};
14421
+ const nextValue = setBySegments(current2[head.name], tail, value);
14422
+ return {
14423
+ ...current2,
14424
+ [head.name]: nextValue
14425
+ };
14426
+ }
14427
+ const current = Array.isArray(obj) ? [...obj] : [];
14428
+ current[head.index] = setBySegments(current[head.index], tail, value);
14429
+ return current;
14430
+ }
14431
+ function unsetBySegments(obj, segments) {
14432
+ if (segments.length === 0) {
14433
+ return obj;
14434
+ }
14435
+ const [head, ...tail] = segments;
14436
+ if (head.kind === "prop") {
14437
+ if (!isRecord(obj)) {
14438
+ return obj;
14439
+ }
14440
+ if (tail.length === 0) {
14441
+ const { [head.name]: _removed, ...rest } = obj;
14442
+ return rest;
14443
+ }
14444
+ return {
14445
+ ...obj,
14446
+ [head.name]: unsetBySegments(obj[head.name], tail)
14447
+ };
14448
+ }
14449
+ if (!Array.isArray(obj)) {
14450
+ return obj;
14451
+ }
14452
+ const next = [...obj];
14453
+ if (tail.length === 0) {
14454
+ if (head.index >= 0 && head.index < next.length) {
14455
+ delete next[head.index];
14456
+ }
14457
+ return next;
14458
+ }
14459
+ next[head.index] = unsetBySegments(next[head.index], tail);
14460
+ return next;
14461
+ }
14462
+ function isRecord(value) {
14463
+ return value !== null && typeof value === "object" && !Array.isArray(value);
14464
+ }
14465
+ function parseBracketIndexedSegment(segment) {
14466
+ if (!segment.includes("[")) {
14467
+ return null;
14468
+ }
14469
+ if (segment.includes("\\[") || segment.includes("\\]")) {
14470
+ return null;
14471
+ }
14472
+ const parsed = [];
14473
+ let cursor = 0;
14474
+ let sawIndex = false;
14475
+ while (cursor < segment.length) {
14476
+ const open = segment.indexOf("[", cursor);
14477
+ if (open === -1) {
14478
+ const tail = segment.slice(cursor);
14479
+ if (tail.length === 0) {
14480
+ break;
14481
+ }
14482
+ if (sawIndex) {
14483
+ return null;
14484
+ }
14485
+ parsed.push({ kind: "prop", name: tail });
14486
+ break;
14487
+ }
14488
+ const prefix = segment.slice(cursor, open);
14489
+ if (prefix.length > 0) {
14490
+ if (sawIndex) {
14491
+ return null;
14492
+ }
14493
+ parsed.push({ kind: "prop", name: prefix });
14494
+ }
14495
+ const close = segment.indexOf("]", open + 1);
14496
+ if (close === -1) {
14497
+ return null;
14498
+ }
14499
+ const indexText = segment.slice(open + 1, close);
14500
+ if (!/^[0-9]+$/.test(indexText)) {
14501
+ return null;
14502
+ }
14503
+ parsed.push({ kind: "index", index: Number(indexText) });
14504
+ sawIndex = true;
14505
+ cursor = close + 1;
14506
+ }
14507
+ return parsed.length > 0 ? parsed : null;
14508
+ }
14509
+
14510
+ // src/schema/common.ts
14511
+ var SemanticPath = external_exports.string().min(1);
14512
+ var Result = (valueSchema, errorSchema) => external_exports.discriminatedUnion("ok", [
14513
+ external_exports.object({ ok: external_exports.literal(true), value: valueSchema }),
14514
+ external_exports.object({ ok: external_exports.literal(false), error: errorSchema })
14515
+ ]);
14516
+ var ok = (value) => ({ ok: true, value });
14517
+ var err = (error48) => ({ ok: false, error: error48 });
14518
+ var isOk = (result) => result.ok;
14519
+ var isErr = (result) => !result.ok;
14520
+
14364
14521
  // src/evaluator/expr.ts
14365
14522
  function evaluateExpr(expr, ctx) {
14366
14523
  switch (expr.kind) {
@@ -15208,163 +15365,6 @@ function evaluateToBoolean(arg, ctx) {
15208
15365
  return ok(toBoolean(result.value));
15209
15366
  }
15210
15367
 
15211
- // src/utils/patch-path.ts
15212
- var UNSAFE_PROP_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
15213
- function patchPathToDisplayString(path) {
15214
- let output = "";
15215
- for (let i = 0; i < path.length; i++) {
15216
- const segment = path[i];
15217
- if (segment.kind === "prop") {
15218
- output += i === 0 ? segment.name : `.${segment.name}`;
15219
- continue;
15220
- }
15221
- output += `[${segment.index}]`;
15222
- }
15223
- return output;
15224
- }
15225
- function semanticPathToPatchPath(path) {
15226
- const segments = parsePath(path);
15227
- if (segments.length === 0) {
15228
- return [{ kind: "prop", name: path }];
15229
- }
15230
- const patchPath = [];
15231
- for (const segment of segments) {
15232
- const parsed = parseBracketIndexedSegment(segment);
15233
- if (parsed) {
15234
- patchPath.push(...parsed);
15235
- continue;
15236
- }
15237
- patchPath.push({ kind: "prop", name: segment });
15238
- }
15239
- return patchPath.length > 0 ? patchPath : [{ kind: "prop", name: path }];
15240
- }
15241
- function isSafePatchPath(path) {
15242
- return path.every((segment) => segment.kind !== "prop" || !UNSAFE_PROP_SEGMENTS.has(segment.name));
15243
- }
15244
- function getByPatchPath(obj, path) {
15245
- let current = obj;
15246
- for (const segment of path) {
15247
- if (segment.kind === "prop") {
15248
- if (current === null || typeof current !== "object" || Array.isArray(current)) {
15249
- return void 0;
15250
- }
15251
- current = current[segment.name];
15252
- continue;
15253
- }
15254
- if (!Array.isArray(current)) {
15255
- return void 0;
15256
- }
15257
- current = current[segment.index];
15258
- }
15259
- return current;
15260
- }
15261
- function setByPatchPath(obj, path, value) {
15262
- return setBySegments(obj, path, value);
15263
- }
15264
- function unsetByPatchPath(obj, path) {
15265
- return unsetBySegments(obj, path);
15266
- }
15267
- function mergeAtPatchPath(obj, path, value) {
15268
- const existing = getByPatchPath(obj, path);
15269
- const merged = isRecord(existing) ? { ...existing, ...value } : value;
15270
- return setByPatchPath(obj, path, merged);
15271
- }
15272
- function setBySegments(obj, segments, value) {
15273
- if (segments.length === 0) {
15274
- return value;
15275
- }
15276
- const [head, ...tail] = segments;
15277
- if (head.kind === "prop") {
15278
- const current2 = isRecord(obj) ? obj : {};
15279
- const nextValue = setBySegments(current2[head.name], tail, value);
15280
- return {
15281
- ...current2,
15282
- [head.name]: nextValue
15283
- };
15284
- }
15285
- const current = Array.isArray(obj) ? [...obj] : [];
15286
- current[head.index] = setBySegments(current[head.index], tail, value);
15287
- return current;
15288
- }
15289
- function unsetBySegments(obj, segments) {
15290
- if (segments.length === 0) {
15291
- return obj;
15292
- }
15293
- const [head, ...tail] = segments;
15294
- if (head.kind === "prop") {
15295
- if (!isRecord(obj)) {
15296
- return obj;
15297
- }
15298
- if (tail.length === 0) {
15299
- const { [head.name]: _removed, ...rest } = obj;
15300
- return rest;
15301
- }
15302
- return {
15303
- ...obj,
15304
- [head.name]: unsetBySegments(obj[head.name], tail)
15305
- };
15306
- }
15307
- if (!Array.isArray(obj)) {
15308
- return obj;
15309
- }
15310
- const next = [...obj];
15311
- if (tail.length === 0) {
15312
- if (head.index >= 0 && head.index < next.length) {
15313
- delete next[head.index];
15314
- }
15315
- return next;
15316
- }
15317
- next[head.index] = unsetBySegments(next[head.index], tail);
15318
- return next;
15319
- }
15320
- function isRecord(value) {
15321
- return value !== null && typeof value === "object" && !Array.isArray(value);
15322
- }
15323
- function parseBracketIndexedSegment(segment) {
15324
- if (!segment.includes("[")) {
15325
- return null;
15326
- }
15327
- if (segment.includes("\\[") || segment.includes("\\]")) {
15328
- return null;
15329
- }
15330
- const parsed = [];
15331
- let cursor = 0;
15332
- let sawIndex = false;
15333
- while (cursor < segment.length) {
15334
- const open = segment.indexOf("[", cursor);
15335
- if (open === -1) {
15336
- const tail = segment.slice(cursor);
15337
- if (tail.length === 0) {
15338
- break;
15339
- }
15340
- if (sawIndex) {
15341
- return null;
15342
- }
15343
- parsed.push({ kind: "prop", name: tail });
15344
- break;
15345
- }
15346
- const prefix = segment.slice(cursor, open);
15347
- if (prefix.length > 0) {
15348
- if (sawIndex) {
15349
- return null;
15350
- }
15351
- parsed.push({ kind: "prop", name: prefix });
15352
- }
15353
- const close = segment.indexOf("]", open + 1);
15354
- if (close === -1) {
15355
- return null;
15356
- }
15357
- const indexText = segment.slice(open + 1, close);
15358
- if (!/^[0-9]+$/.test(indexText)) {
15359
- return null;
15360
- }
15361
- parsed.push({ kind: "index", index: Number(indexText) });
15362
- sawIndex = true;
15363
- cursor = close + 1;
15364
- }
15365
- return parsed.length > 0 ? parsed : null;
15366
- }
15367
-
15368
15368
  // src/core/validation-utils.ts
15369
15369
  var SEMVER_REGEX = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
15370
15370
  var URI_SCHEME_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
@@ -16274,6 +16274,57 @@ function evaluateSingleComputed(schema, snapshot, path) {
16274
16274
  return evaluateExpr(spec.expr, ctx);
16275
16275
  }
16276
16276
 
16277
+ // src/core/action-availability.ts
16278
+ function evaluateActionAvailability(schema, snapshot, actionName, timestamp = snapshot.meta.timestamp) {
16279
+ const action = schema.actions[actionName];
16280
+ if (!action) {
16281
+ return {
16282
+ kind: "error",
16283
+ code: "UNKNOWN_ACTION",
16284
+ message: `Unknown action: ${actionName}`
16285
+ };
16286
+ }
16287
+ if (!action.available) {
16288
+ return { kind: "ok", available: true };
16289
+ }
16290
+ const ctx = createContext(
16291
+ snapshot,
16292
+ schema,
16293
+ null,
16294
+ `actions.${actionName}.available`,
16295
+ void 0,
16296
+ timestamp
16297
+ );
16298
+ const result = evaluateExpr(action.available, ctx);
16299
+ if (isErr(result)) {
16300
+ return {
16301
+ kind: "error",
16302
+ code: "INTERNAL_ERROR",
16303
+ message: `Error evaluating availability: ${result.error.message}`
16304
+ };
16305
+ }
16306
+ if (typeof result.value !== "boolean") {
16307
+ return {
16308
+ kind: "error",
16309
+ code: "TYPE_MISMATCH",
16310
+ message: `Availability condition must return boolean, got ${typeof result.value}`
16311
+ };
16312
+ }
16313
+ return { kind: "ok", available: result.value };
16314
+ }
16315
+ function isActionAvailable(schema, snapshot, actionName) {
16316
+ const result = evaluateActionAvailability(schema, snapshot, actionName);
16317
+ if (result.kind === "error") {
16318
+ throw new Error(result.message);
16319
+ }
16320
+ return result.available;
16321
+ }
16322
+ function getAvailableActions(schema, snapshot) {
16323
+ return Object.keys(schema.actions).filter(
16324
+ (actionName) => isActionAvailable(schema, snapshot, actionName)
16325
+ );
16326
+ }
16327
+
16277
16328
  // src/core/system-delta.ts
16278
16329
  function applySystemDelta(snapshot, delta) {
16279
16330
  const hasStatus = hasOwn(delta, "status");
@@ -16281,7 +16332,6 @@ function applySystemDelta(snapshot, delta) {
16281
16332
  const hasLastError = hasOwn(delta, "lastError");
16282
16333
  const removeRequirementIds = new Set(delta.removeRequirementIds ?? []);
16283
16334
  const addRequirements = delta.addRequirements ?? [];
16284
- const appendErrors = delta.appendErrors ?? [];
16285
16335
  const nextPending = applyRequirementDelta(
16286
16336
  snapshot.system.pendingRequirements,
16287
16337
  removeRequirementIds,
@@ -16292,7 +16342,6 @@ function applySystemDelta(snapshot, delta) {
16292
16342
  status: hasStatus ? delta.status : snapshot.system.status,
16293
16343
  currentAction: hasCurrentAction ? delta.currentAction ?? null : snapshot.system.currentAction,
16294
16344
  lastError: hasLastError ? delta.lastError ?? null : snapshot.system.lastError,
16295
- errors: appendErrors.length > 0 ? [...snapshot.system.errors, ...appendErrors] : snapshot.system.errors,
16296
16345
  pendingRequirements: nextPending
16297
16346
  };
16298
16347
  if (!hasSystemChanged(snapshot.system, nextSystem)) {
@@ -16324,25 +16373,11 @@ function hasSystemChanged(previous, next) {
16324
16373
  if (!isErrorValueEqual(previous.lastError, next.lastError)) {
16325
16374
  return true;
16326
16375
  }
16327
- if (!areErrorArraysEqual(previous.errors, next.errors)) {
16328
- return true;
16329
- }
16330
16376
  if (!areRequirementArraysEqual(previous.pendingRequirements, next.pendingRequirements)) {
16331
16377
  return true;
16332
16378
  }
16333
16379
  return false;
16334
16380
  }
16335
- function areErrorArraysEqual(a, b) {
16336
- if (a.length !== b.length) {
16337
- return false;
16338
- }
16339
- for (let i = 0; i < a.length; i++) {
16340
- if (!isErrorValueEqual(a[i], b[i])) {
16341
- return false;
16342
- }
16343
- }
16344
- return true;
16345
- }
16346
16381
  function areRequirementArraysEqual(a, b) {
16347
16382
  if (a.length !== b.length) {
16348
16383
  return false;
@@ -16421,27 +16456,17 @@ function computeSync(schema, snapshot, intent, context) {
16421
16456
  }
16422
16457
  const isReEntry = currentSnapshot.system.currentAction === intent.type;
16423
16458
  if (action.available && !isReEntry) {
16424
- const ctx2 = createContext(currentSnapshot, schema, intent.type, "available", intent.intentId, context.now);
16425
- const availResult = evaluateExpr(action.available, ctx2);
16426
- if (isErr(availResult)) {
16459
+ const availability = evaluateActionAvailability(schema, currentSnapshot, intent.type, context.now);
16460
+ if (availability.kind === "error") {
16427
16461
  return createErrorResult(
16428
16462
  currentSnapshot,
16429
16463
  intent,
16430
- "INTERNAL_ERROR",
16431
- `Error evaluating availability: ${availResult.error.message}`,
16464
+ availability.code,
16465
+ availability.message,
16432
16466
  context
16433
16467
  );
16434
16468
  }
16435
- if (typeof availResult.value !== "boolean") {
16436
- return createErrorResult(
16437
- currentSnapshot,
16438
- intent,
16439
- "TYPE_MISMATCH",
16440
- `Availability condition must return boolean, got ${typeof availResult.value}`,
16441
- context
16442
- );
16443
- }
16444
- if (!availResult.value) {
16469
+ if (!availability.available) {
16445
16470
  return createErrorResult(
16446
16471
  currentSnapshot,
16447
16472
  intent,
@@ -16539,7 +16564,6 @@ function createErrorResult(snapshot, intent, code, message, context) {
16539
16564
  status: "error",
16540
16565
  currentAction: null,
16541
16566
  lastError: error48,
16542
- appendErrors: [error48],
16543
16567
  addRequirements: [],
16544
16568
  removeRequirementIds: []
16545
16569
  };
@@ -16574,7 +16598,6 @@ function createSystemDeltaForFlow(snapshot, intent, status, flowError, requireme
16574
16598
  status: systemStatus,
16575
16599
  currentAction: status === "pending" ? intent.type : null,
16576
16600
  lastError: flowError,
16577
- appendErrors: flowError && isError ? [flowError] : [],
16578
16601
  addRequirements: [...requirements],
16579
16602
  removeRequirementIds: snapshot.system.pendingRequirements.map((requirement) => requirement.id)
16580
16603
  };
@@ -16758,8 +16781,7 @@ function apply(schema, snapshot, patches, context) {
16758
16781
  newSystem = {
16759
16782
  ...newSystem,
16760
16783
  status: "error",
16761
- lastError,
16762
- errors: [...newSystem.errors, ...validationErrors]
16784
+ lastError
16763
16785
  };
16764
16786
  }
16765
16787
  const intermediateSnapshot = {
@@ -16778,8 +16800,7 @@ function apply(schema, snapshot, patches, context) {
16778
16800
  newSystem = {
16779
16801
  ...newSystem,
16780
16802
  status: "error",
16781
- lastError: error48,
16782
- errors: [...newSystem.errors, error48]
16803
+ lastError: error48
16783
16804
  };
16784
16805
  }
16785
16806
  return {
@@ -17667,10 +17688,6 @@ var SystemState = external_exports.object({
17667
17688
  * Last error (null if none)
17668
17689
  */
17669
17690
  lastError: ErrorValue.nullable(),
17670
- /**
17671
- * Error history
17672
- */
17673
- errors: external_exports.array(ErrorValue),
17674
17691
  /**
17675
17692
  * Pending requirements waiting for Host
17676
17693
  */
@@ -17726,7 +17743,6 @@ function createInitialSystemState() {
17726
17743
  return {
17727
17744
  status: "idle",
17728
17745
  lastError: null,
17729
- errors: [],
17730
17746
  pendingRequirements: [],
17731
17747
  currentAction: null
17732
17748
  };
@@ -17747,7 +17763,6 @@ var SystemDelta = external_exports.object({
17747
17763
  status: SystemState.shape.status.optional(),
17748
17764
  currentAction: external_exports.string().nullable().optional(),
17749
17765
  lastError: ErrorValue.nullable().optional(),
17750
- appendErrors: external_exports.array(ErrorValue),
17751
17766
  addRequirements: external_exports.array(Requirement),
17752
17767
  removeRequirementIds: external_exports.array(external_exports.string())
17753
17768
  });
@@ -18282,7 +18297,9 @@ function createCore() {
18282
18297
  apply,
18283
18298
  applySystemDelta,
18284
18299
  validate,
18285
- explain
18300
+ explain,
18301
+ isActionAvailable,
18302
+ getAvailableActions
18286
18303
  };
18287
18304
  }
18288
18305
  export {
@@ -18435,6 +18452,7 @@ export {
18435
18452
  generateRequirementId,
18436
18453
  generateRequirementIdSync,
18437
18454
  generateTraceId,
18455
+ getAvailableActions,
18438
18456
  getByPatchPath,
18439
18457
  getByPath,
18440
18458
  getTransitiveDeps,
@@ -18445,6 +18463,7 @@ export {
18445
18463
  hashSchemaSync,
18446
18464
  indexSegment,
18447
18465
  invalidResult,
18466
+ isActionAvailable,
18448
18467
  isErr,
18449
18468
  isErrorValue,
18450
18469
  isOk,