@wairon/cli 5.1.1-dev.7 → 5.1.1-dev.8

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.js CHANGED
@@ -8,6 +8,9 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __esm = (fn, res) => function __init() {
9
9
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
10
  };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
11
14
  var __export = (target, all) => {
12
15
  for (var name in all)
13
16
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -1211,7 +1214,7 @@ var init_defaults = __esm({
1211
1214
  copilot: ".github/prompts",
1212
1215
  codex: ".codex/agents"
1213
1216
  };
1214
- WAIRON_VERSION = "5.1.1-dev.7";
1217
+ WAIRON_VERSION = "5.1.1-dev.8";
1215
1218
  GITHUB_REPO = "SYW-Apps/Waffle-AIron";
1216
1219
  ARCHITECT_AGENT_ID = "agent-architect";
1217
1220
  ARCHITECT_TEMPLATE_ID = "architect";
@@ -3700,10 +3703,10 @@ function stepGraph(steps) {
3700
3703
  const s = byNum.get(n);
3701
3704
  if (s.type !== "parallel" || s.endStep === void 0 || !s.branches?.length) continue;
3702
3705
  const entries = s.branches.map((b) => b.step).sort((a, b) => a - b);
3703
- const join16 = fallNext(s.endStep);
3706
+ const join17 = fallNext(s.endStep);
3704
3707
  for (let i = 0; i < entries.length; i++) {
3705
3708
  const armEnd = i + 1 < entries.length ? prevOf(entries[i + 1]) : s.endStep;
3706
- if (armEnd !== void 0 && armEnd >= entries[i]) armEndJoin.set(armEnd, join16);
3709
+ if (armEnd !== void 0 && armEnd >= entries[i]) armEndJoin.set(armEnd, join17);
3707
3710
  }
3708
3711
  }
3709
3712
  const successorsOf = (n) => {
@@ -7029,11 +7032,11 @@ var init_narrative_antipatterns = __esm({
7029
7032
  const memberEdges = keys.flatMap((k) => (adjacency.get(k) ?? []).filter((e) => inScc.has(e.toKey)));
7030
7033
  if (memberEdges.length === 0) continue;
7031
7034
  const anchor = [...memberEdges].sort((a, b) => a.fromKey.localeCompare(b.fromKey))[0];
7032
- const path26 = [...keys].sort().join(" \u2192 ");
7035
+ const path27 = [...keys].sort().join(" \u2192 ");
7033
7036
  ctx.addIssue(
7034
7037
  "warning",
7035
7038
  "UNCONDITIONAL_CALL_CYCLE",
7036
- `Call cycle with no guard: ${path26} \u2014 every call edge in this cycle is unavoidable on all paths of its narrative (e.g. step ${anchor.stepNumber} of "${anchor.methodName}" in "${anchor.impl.id}" always calls ${anchor.toLabel}). This recurses without a base case, by construction. Guard at least one edge with a branch/return before the call, or lint.allow with the termination argument.`,
7039
+ `Call cycle with no guard: ${path27} \u2014 every call edge in this cycle is unavoidable on all paths of its narrative (e.g. step ${anchor.stepNumber} of "${anchor.methodName}" in "${anchor.impl.id}" always calls ${anchor.toLabel}). This recurses without a base case, by construction. Guard at least one edge with a branch/return before the call, or lint.allow with the termination argument.`,
7037
7040
  anchor.impl.id,
7038
7041
  memberEdges.some((e) => ctx.isImplementationDraft(e.impl))
7039
7042
  );
@@ -14936,6 +14939,41 @@ function findChainingParent(childRoot) {
14936
14939
  }
14937
14940
  return null;
14938
14941
  }
14942
+ function listChainedRoots(rootDir = getProjectRoot()) {
14943
+ const root = path15.resolve(rootDir);
14944
+ const found = [];
14945
+ const visited = /* @__PURE__ */ new Set([root]);
14946
+ const walk = (projectDir, depth) => {
14947
+ if (depth > 32) return;
14948
+ const specsDir = aiPathsAt(projectDir).specsDir();
14949
+ if (!pathExists(specsDir)) return;
14950
+ for (const file of listFilesRecursive(specsDir, ".yaml")) {
14951
+ let raw;
14952
+ try {
14953
+ raw = readYamlFile(file);
14954
+ } catch {
14955
+ continue;
14956
+ }
14957
+ if (!raw || typeof raw !== "object" || !("parentSystem" in raw)) continue;
14958
+ const projectPath = raw.projectPath;
14959
+ if (typeof projectPath !== "string" || projectPath.trim() === "") continue;
14960
+ let childDir;
14961
+ try {
14962
+ childDir = path15.resolve(projectDir, projectPath);
14963
+ } catch {
14964
+ continue;
14965
+ }
14966
+ if (projectPathEscapesRoot(root, projectPath, childDir)) continue;
14967
+ if (visited.has(childDir)) continue;
14968
+ if (!fs10.existsSync(childDir)) continue;
14969
+ visited.add(childDir);
14970
+ found.push(path15.relative(root, childDir).split(path15.sep).join("/"));
14971
+ walk(childDir, depth + 1);
14972
+ }
14973
+ };
14974
+ walk(root, 0);
14975
+ return found;
14976
+ }
14939
14977
  function mergeMountRealizations(subs) {
14940
14978
  const result = [];
14941
14979
  const indexById = /* @__PURE__ */ new Map();
@@ -15952,7 +15990,7 @@ var init_specs2 = __esm({
15952
15990
  }
15953
15991
  return issues;
15954
15992
  }
15955
- saveSubsystemSpec(spec) {
15993
+ saveSubsystemSpec(spec, opts) {
15956
15994
  const p = this.getSubsystemPath(spec.id);
15957
15995
  ensureDir(path15.dirname(p));
15958
15996
  const { prefix } = splitNamespace(spec.id);
@@ -15979,7 +16017,7 @@ var init_specs2 = __esm({
15979
16017
  if (existing) {
15980
16018
  specToWrite.createdAt = existing.createdAt;
15981
16019
  }
15982
- specToWrite.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
16020
+ specToWrite.updatedAt = opts?.preserveUpdatedAt && existing?.updatedAt ? existing.updatedAt : (/* @__PURE__ */ new Date()).toISOString();
15983
16021
  writeYamlFile(p, parseOrThrow(SubsystemSpecSchema, specToWrite, "subsystem", spec.id));
15984
16022
  invalidateSpecCache();
15985
16023
  }
@@ -16040,7 +16078,7 @@ var init_specs2 = __esm({
16040
16078
  `component "${spec.id}" already exists at ${path15.relative(this.rootDir, p)} \u2014 the flat layout re-saves in place and never relocates the file. The subsystem field is now "${spec.subsystem}" (was "${existing.subsystem}").`
16041
16079
  );
16042
16080
  }
16043
- specToWrite.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
16081
+ specToWrite.updatedAt = opts?.preserveUpdatedAt && existing?.updatedAt ? existing.updatedAt : (/* @__PURE__ */ new Date()).toISOString();
16044
16082
  writeYamlFile(p, parseOrThrow(ComponentSpecSchema, specToWrite, "component", spec.id));
16045
16083
  invalidateSpecCache();
16046
16084
  this.normalizeComponentLayout();
@@ -16169,7 +16207,7 @@ var init_specs2 = __esm({
16169
16207
  }
16170
16208
  }
16171
16209
  }
16172
- specToWrite.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
16210
+ specToWrite.updatedAt = opts?.preserveUpdatedAt && existing?.updatedAt ? existing.updatedAt : (/* @__PURE__ */ new Date()).toISOString();
16173
16211
  writeYamlFile(p, parseOrThrow(InterfaceSpecSchema, specToWrite, "interface", spec.id));
16174
16212
  invalidateSpecCache();
16175
16213
  return notices;
@@ -16226,7 +16264,7 @@ var init_specs2 = __esm({
16226
16264
  specToWrite.status = existing.status;
16227
16265
  }
16228
16266
  }
16229
- specToWrite.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
16267
+ specToWrite.updatedAt = opts?.preserveUpdatedAt && existing?.updatedAt ? existing.updatedAt : (/* @__PURE__ */ new Date()).toISOString();
16230
16268
  writeYamlFile(p, parseOrThrow(ImplementationSpecSchema, specToWrite, "implementation", spec.id));
16231
16269
  invalidateSpecCache();
16232
16270
  return notices;
@@ -16255,7 +16293,7 @@ var init_specs2 = __esm({
16255
16293
  * relocates an existing file — both are by design, but silent they read as
16256
16294
  * "the subsystem parameter was ignored".
16257
16295
  */
16258
- saveTypeSpec(spec) {
16296
+ saveTypeSpec(spec, opts) {
16259
16297
  const notices = [];
16260
16298
  const existing = this.loadTypeSpec(spec.id);
16261
16299
  const group = spec.group || (existing ? existing.group : void 0);
@@ -16279,7 +16317,7 @@ var init_specs2 = __esm({
16279
16317
  specToWrite.group = relativizeId(existing.group, this.writePrefixFor(spec.id));
16280
16318
  }
16281
16319
  }
16282
- specToWrite.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
16320
+ specToWrite.updatedAt = opts?.preserveUpdatedAt && existing?.updatedAt ? existing.updatedAt : (/* @__PURE__ */ new Date()).toISOString();
16283
16321
  writeYamlFile(p, parseOrThrow(TypeSpecSchema, specToWrite, "type", spec.id));
16284
16322
  invalidateSpecCache();
16285
16323
  return notices;
@@ -16302,7 +16340,7 @@ var init_specs2 = __esm({
16302
16340
  loadGroupSpec(id) {
16303
16341
  return this.scanAll().groups.find((g) => g.id === id) ?? null;
16304
16342
  }
16305
- saveGroupSpec(spec) {
16343
+ saveGroupSpec(spec, opts) {
16306
16344
  const p = this.getGroupPath(spec.id);
16307
16345
  ensureDir(path15.dirname(p));
16308
16346
  const specToWrite = this.prepareGroupForWrite(spec);
@@ -16310,7 +16348,7 @@ var init_specs2 = __esm({
16310
16348
  if (existing) {
16311
16349
  specToWrite.createdAt = existing.createdAt;
16312
16350
  }
16313
- specToWrite.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
16351
+ specToWrite.updatedAt = opts?.preserveUpdatedAt && existing?.updatedAt ? existing.updatedAt : (/* @__PURE__ */ new Date()).toISOString();
16314
16352
  writeYamlFile(p, parseOrThrow(GroupSpecSchema, specToWrite, "group", spec.id));
16315
16353
  invalidateSpecCache();
16316
16354
  }
@@ -16411,26 +16449,34 @@ var init_specs2 = __esm({
16411
16449
  return [...out];
16412
16450
  }
16413
16451
  /** Set a single spec's status (bumps updatedAt). Caller invalidates the cache. */
16452
+ /**
16453
+ * Flip one spec's lifecycle status, changing nothing else — the lock's freeze.
16454
+ *
16455
+ * `preserveUpdatedAt` because this is MECHANICAL: no authored content moves,
16456
+ * so re-stamping updatedAt would claim an edit that never happened and make a
16457
+ * freeze read like a design change in review.
16458
+ */
16414
16459
  applySpecStatus(kind, id, status) {
16460
+ const keepStamp = { preserveUpdatedAt: true };
16415
16461
  switch (kind) {
16416
16462
  case "subsystem": {
16417
16463
  const s = this.loadSubsystemSpec(id);
16418
- if (s) this.saveSubsystemSpec({ ...s, status });
16464
+ if (s) this.saveSubsystemSpec({ ...s, status }, keepStamp);
16419
16465
  break;
16420
16466
  }
16421
16467
  case "component": {
16422
16468
  const s = this.loadComponentSpec(id);
16423
- if (s) this.saveComponentSpec({ ...s, status });
16469
+ if (s) this.saveComponentSpec({ ...s, status }, keepStamp);
16424
16470
  break;
16425
16471
  }
16426
16472
  case "interface": {
16427
16473
  const s = this.loadInterfaceSpec(id);
16428
- if (s) this.saveInterfaceSpec({ ...s, status });
16474
+ if (s) this.saveInterfaceSpec({ ...s, status }, keepStamp);
16429
16475
  break;
16430
16476
  }
16431
16477
  case "implementation": {
16432
16478
  const s = this.loadImplementationSpec(id);
16433
- if (s) this.saveImplementationSpec({ ...s, status });
16479
+ if (s) this.saveImplementationSpec({ ...s, status }, keepStamp);
16434
16480
  break;
16435
16481
  }
16436
16482
  }
@@ -17507,243 +17553,3606 @@ var init_domains = __esm({
17507
17553
  }
17508
17554
  });
17509
17555
 
17510
- // src/index.ts
17511
- var src_exports = {};
17512
- __export(src_exports, {
17513
- AI_PATHS: () => AI_PATHS,
17514
- ARCHITECT_AGENT_ID: () => ARCHITECT_AGENT_ID,
17515
- ARCHITECT_TEMPLATE_ID: () => ARCHITECT_TEMPLATE_ID,
17516
- AgentBriefSchema: () => AgentBriefSchema,
17517
- AgentRecordSchema: () => AgentRecordSchema,
17518
- AgentStatusSchema: () => AgentStatusSchema,
17519
- AgentTemplateSchema: () => AgentTemplateSchema,
17520
- AssertionSelectorSchema: () => AssertionSelectorSchema,
17521
- BACKEND_COMMANDS: () => BACKEND_COMMANDS,
17522
- BUILTIN_PROFILES: () => BUILTIN_PROFILES,
17523
- BUILTIN_TYPES: () => BUILTIN_TYPES,
17524
- BoundaryItemSchema: () => BoundaryItemSchema,
17525
- BuiltinTargetConfigSchema: () => BuiltinTargetConfigSchema,
17526
- BuiltinTargetSchema: () => BuiltinTargetSchema,
17527
- BundleNotFoundError: () => BundleNotFoundError,
17528
- CONTEXT_PATHS: () => CONTEXT_PATHS,
17529
- CatchClauseSchema: () => CatchClauseSchema,
17530
- ClaudeExporter: () => ClaudeExporter,
17531
- ComplexityRuleConfigSchema: () => ComplexityRuleConfigSchema,
17532
- ComponentSpecSchema: () => ComponentSpecSchema,
17533
- ComponentTypeSchema: () => ComponentTypeSchema,
17534
- ConfigValidationError: () => ConfigValidationError,
17535
- ConformanceTierSchema: () => ConformanceTierSchema,
17536
- CustomExporter: () => CustomExporter,
17537
- CustomTargetConfigSchema: () => CustomTargetConfigSchema,
17538
- CustomTargetSchema: () => CustomTargetSchema,
17539
- DEFAULT_TARGET_DIRS: () => DEFAULT_TARGET_DIRS,
17540
- DatabaseSpecSchema: () => DatabaseSpecSchema,
17541
- DeclarativePackSchema: () => DeclarativePackSchema,
17542
- DesignDepthSchema: () => DesignDepthSchema,
17543
- DiagramConfigSchema: () => DiagramConfigSchema,
17544
- DispatchBindingSchema: () => DispatchBindingSchema,
17545
- DocumentationRuleConfigSchema: () => DocumentationRuleConfigSchema,
17546
- DomainSchema: () => DomainSchema,
17547
- DomainTypeSchema: () => DomainTypeSchema,
17548
- DurabilitySchema: () => DurabilitySchema,
17549
- EndpointSchema: () => EndpointSchema,
17550
- EventBindingSchema: () => EventBindingSchema,
17551
- ExtDataSchema: () => ExtDataSchema,
17552
- ExternalLinkSchema: () => ExternalLinkSchema,
17553
- ExternalLinkTypeSchema: () => ExternalLinkTypeSchema,
17554
- GITHUB_REPO: () => GITHUB_REPO,
17555
- GLOBAL_PACKS_DEFAULT: () => GLOBAL_PACKS_DEFAULT,
17556
- GeminiExporter: () => GeminiExporter,
17557
- GroupSpecSchema: () => GroupSpecSchema,
17558
- GuaranteeSchema: () => GuaranteeSchema,
17559
- HttpMethodSchema: () => HttpMethodSchema,
17560
- ImplementationSpecSchema: () => ImplementationSpecSchema,
17561
- InterfaceSpecSchema: () => InterfaceSpecSchema,
17562
- InvariantSchema: () => InvariantSchema,
17563
- LANGUAGE_MARKERS: () => LANGUAGE_MARKERS,
17564
- LanguagePackDefSchema: () => LanguagePackDefSchema,
17565
- LifecycleEntrypointSchema: () => LifecycleEntrypointSchema,
17566
- LintAllowSchema: () => LintAllowSchema,
17567
- LintConfigSchema: () => LintConfigSchema,
17568
- LoopKindSchema: () => LoopKindSchema,
17569
- MethodImplementationSchema: () => MethodImplementationSchema,
17570
- MethodParamSchema: () => MethodParamSchema,
17571
- MethodSignatureSchema: () => MethodSignatureSchema,
17572
- NamedOpenApiSpecSchema: () => NamedOpenApiSpecSchema,
17573
- NamingRuleConfigSchema: () => NamingRuleConfigSchema,
17574
- NarrativeDetailSchema: () => NarrativeDetailSchema,
17575
- NarrativeStepSchema: () => NarrativeStepSchema,
17576
- NarrativeStepTypeSchema: () => NarrativeStepTypeSchema,
17577
- OutputTargetSchema: () => OutputTargetSchema,
17578
- PACK_DIR_ENTRIES: () => PACK_DIR_ENTRIES,
17579
- PATTERN_TYPES: () => PATTERN_TYPES,
17580
- PROJECT_KINDS: () => PROJECT_KINDS,
17581
- PackAssertionSchema: () => PackAssertionSchema,
17582
- PackInstructionBlockSchema: () => PackInstructionBlockSchema,
17583
- PackSelectionSchema: () => PackSelectionSchema,
17584
- PackSkillSchema: () => PackSkillSchema,
17585
- ParallelBranchSchema: () => ParallelBranchSchema,
17586
- PathsConfigSchema: () => PathsConfigSchema,
17587
- PatternDefSchema: () => PatternDefSchema,
17588
- PatternRefSchema: () => PatternRefSchema,
17589
- PortalAuthSchema: () => PortalAuthSchema,
17590
- PortalAuthSchemeSchema: () => PortalAuthSchemeSchema,
17591
- PortalTypeSchema: () => PortalTypeSchema,
17592
- ProfileDefSchema: () => ProfileDefSchema,
17593
- ProfileSelectionSubjectSchema: () => ProfileSelectionSubjectSchema,
17594
- ProjectConfigSchema: () => ProjectConfigSchema,
17595
- ProjectNotInitializedError: () => ProjectNotInitializedError,
17596
- ProjectProfileSelectionSchema: () => ProjectProfileSelectionSchema,
17597
- PublicInterfaceSchema: () => PublicInterfaceSchema,
17598
- PublicInterfaceTypeSchema: () => PublicInterfaceTypeSchema,
17599
- RegistrySchema: () => RegistrySchema,
17600
- RequirementItemSchema: () => RequirementItemSchema,
17601
- RulesConfigSchema: () => RulesConfigSchema,
17602
- SCAN_EXCLUDE_DIRS: () => SCAN_EXCLUDE_DIRS,
17603
- SDD_RULES: () => SDD_RULES,
17604
- SEMANTIC_GUARANTEES: () => SEMANTIC_GUARANTEES,
17605
- SUPPORTED_ALIASES: () => SUPPORTED_ALIASES,
17606
- SURFACE_AUDIENCES: () => SURFACE_AUDIENCES,
17607
- SkillResourceNotFoundError: () => SkillResourceNotFoundError,
17608
- SpecIdSchema: () => SpecIdSchema,
17609
- SpecStatusSchema: () => SpecStatusSchema,
17610
- SpecWorkspace: () => SpecWorkspace,
17611
- SubsystemSpecSchema: () => SubsystemSpecSchema,
17612
- SurfaceAudienceSchema: () => SurfaceAudienceSchema,
17613
- SurfaceContractEntrySchema: () => SurfaceContractEntrySchema,
17614
- SurfaceOriginSchema: () => SurfaceOriginSchema,
17615
- SurfaceSnapshotSchema: () => SurfaceSnapshotSchema,
17616
- SurfaceTypeDefSchema: () => SurfaceTypeDefSchema,
17617
- SwitchCaseSchema: () => SwitchCaseSchema,
17618
- SystemPublicInterfaceSchema: () => SystemPublicInterfaceSchema,
17619
- SystemSpecSchema: () => SystemSpecSchema,
17620
- TargetConfigSchema: () => TargetConfigSchema,
17621
- TemplateNotFoundError: () => TemplateNotFoundError,
17622
- TemplateSchema: () => TemplateSchema,
17623
- TopologyConfigSchema: () => TopologyConfigSchema,
17624
- TransportSchema: () => TransportSchema,
17625
- TrustedLinkSchema: () => TrustedLinkSchema,
17626
- TypeFieldSchema: () => TypeFieldSchema,
17627
- TypeKindSchema: () => TypeKindSchema,
17628
- TypeMethodSchema: () => TypeMethodSchema,
17629
- TypeSpecSchema: () => TypeSpecSchema,
17630
- UNVERSIONED: () => UNVERSIONED,
17631
- UnknownAgentError: () => UnknownAgentError,
17632
- VariantDefSchema: () => VariantDefSchema,
17633
- WAIRON_MANAGED_BANNER: () => WAIRON_MANAGED_BANNER,
17634
- WAIRON_MANAGED_MARKER: () => WAIRON_MANAGED_MARKER,
17635
- WAIRON_VERSION: () => WAIRON_VERSION,
17636
- WaironError: () => WaironError,
17637
- activeTargetTypes: () => activeTargetTypes,
17638
- addFreeStandingDomain: () => addFreeStandingDomain,
17639
- aiDir: () => aiDir,
17640
- aiPathsAt: () => aiPathsAt,
17641
- applySpecStatus: () => applySpecStatus,
17642
- assertContainedProjectPath: () => assertContainedProjectPath,
17643
- assertProjectInitialized: () => assertProjectInitialized,
17644
- assertionFullCode: () => assertionFullCode,
17645
- audienceRank: () => audienceRank,
17646
- backendCommand: () => backendCommand,
17647
- backfillChainedSubprojectConfigs: () => backfillChainedSubprojectConfigs,
17648
- buildCanvasDataModel: () => buildCanvasDataModel,
17649
- buildGraphModel: () => buildGraphModel,
17650
- buildProjectGraph: () => buildProjectGraph,
17651
- buildRuleContext: () => buildRuleContext,
17652
- buildServerInstructions: () => buildServerInstructions2,
17653
- checkChildSurfaceFreshness: () => checkChildSurfaceFreshness,
17654
- checkSkillFreshness: () => checkSkillFreshness,
17655
- clearLoaderIssues: () => clearLoaderIssues,
17656
- collectPromotableSpecs: () => collectPromotableSpecs,
17657
- composeAgentBrief: () => composeAgentBrief,
17658
- composeRuleSequence: () => composeRuleSequence,
17659
- composeVariantGuidance: () => composeVariantGuidance,
17660
- computeGateStateId: () => computeGateStateId,
17661
- computePackDigest: () => computePackDigest,
17662
- computeParentStateId: () => computeParentStateId,
17663
- computeStateId: () => computeStateId,
17664
- computeStateIdAt: () => computeStateIdAt,
17665
- contextDir: () => contextDir,
17666
- createAgentRecord: () => createAgentRecord,
17667
- createChainedSubsystem: () => createChainedSubsystem,
17668
- createEmptyRegistry: () => createEmptyRegistry,
17669
- createEmptyTopologyConfig: () => createEmptyTopologyConfig,
17670
- defaultPackSelections: () => defaultPackSelections,
17671
- defaultTargetConfig: () => defaultTargetConfig,
17672
- deleteComponentSpec: () => deleteComponentSpec,
17673
- deleteGroupSpec: () => deleteGroupSpec,
17674
- deleteImplementationSpec: () => deleteImplementationSpec,
17675
- deleteInterfaceSpec: () => deleteInterfaceSpec,
17676
- deleteSubsystemSpec: () => deleteSubsystemSpec,
17677
- deleteTypeSpec: () => deleteTypeSpec,
17678
- deriveSubsystemDomains: () => deriveSubsystemDomains,
17679
- detectDomainCandidates: () => detectDomainCandidates,
17680
- diagnoseProjectPacks: () => diagnoseProjectPacks,
17681
- diagramSetIndex: () => diagramSetIndex,
17682
- discoverPacks: () => discoverPacks,
17683
- dryRunSerializeSpecs: () => dryRunSerializeSpecs,
17684
- emptyExtensions: () => emptyExtensions,
17685
- ensureDir: () => ensureDir,
17686
- ensureProjectInitialized: () => ensureProjectInitialized,
17687
- exportSddSkills: () => exportSddSkills,
17688
- exportSurface: () => exportSurface,
17689
- externalizeSubsystem: () => externalizeSubsystem,
17690
- extractGenericTypeVariables: () => extractGenericTypeVariables,
17691
- extractTypeGenerics: () => extractTypeGenerics,
17692
- extractTypeIdentifiers: () => extractTypeIdentifiers,
17693
- extractTypesFromSignature: () => extractTypesFromSignature,
17694
- findChainingParent: () => findChainingParent,
17695
- findChainingSubprojectsMissingConfig: () => findChainingSubprojectsMissingConfig,
17696
- findDomain: () => findDomain,
17697
- findLegacySpecFiles: () => findLegacySpecFiles,
17698
- findProjectRoot: () => findProjectRoot,
17699
- findSystemRoot: () => findSystemRoot,
17700
- fromOpenApi: () => fromOpenApi,
17701
- fromProjectRoot: () => fromProjectRoot,
17702
- generateAgent: () => generateAgent,
17703
- generateAll: () => generateAll,
17704
- generateChildSnapshots: () => generateChildSnapshots,
17705
- generateComponentDiagram: () => generateComponentDiagram,
17706
- generateDiagramSet: () => generateDiagramSet,
17707
- generateSequenceDiagram: () => generateSequenceDiagram,
17708
- getComponentPath: () => getComponentPath,
17709
- getExporter: () => getExporter,
17710
- getGroupPath: () => getGroupPath,
17711
- getImplementationPath: () => getImplementationPath,
17712
- getInterfacePath: () => getInterfacePath,
17713
- getLoaderIssues: () => getLoaderIssues,
17714
- getProjectRoot: () => getProjectRoot,
17715
- getProjectRootOverride: () => getProjectRootOverride,
17716
- getRequestProjectRoot: () => getRequestProjectRoot,
17717
- getSnapshot: () => getSnapshot,
17718
- getSubprojectPrefix: () => getSubprojectPrefix,
17719
- getSubsystemPath: () => getSubsystemPath,
17720
- getTypePath: () => getTypePath,
17721
- globalPacksDir: () => globalPacksDir,
17722
- globalPacksEnabled: () => globalPacksEnabled,
17723
- globalTemplatesDir: () => globalTemplatesDir,
17724
- globalVariantsDir: () => globalVariantsDir,
17725
- hasArchitectureContext: () => hasArchitectureContext,
17726
- hasContext: () => hasContext,
17727
- hashGateState: () => hashGateState,
17728
- importSurface: () => importSurface,
17729
- installPackFromDirectory: () => installPackFromDirectory,
17730
- internalizeSubsystem: () => internalizeSubsystem,
17731
- invalidateSpecCache: () => invalidateSpecCache,
17732
- isOpenApiDocument: () => isOpenApiDocument,
17733
- isProjectInitialized: () => isProjectInitialized,
17734
- listDirectChainedSubprojects: () => listDirectChainedSubprojects,
17735
- listExternalInterfaces: () => listExternalInterfaces,
17736
- listFiles: () => listFiles,
17737
- listFilesRecursive: () => listFilesRecursive,
17738
- listFreeStandingDomains: () => listFreeStandingDomains,
17739
- listInstalledPacks: () => listInstalledPacks,
17740
- listResources: () => listResources,
17741
- listRules: () => listRules,
17742
- listSkillNames: () => listSkillNames,
17743
- listSkillResources: () => listSkillResources,
17744
- listSnapshots: () => listSnapshots,
17745
- listTemplateIds: () => listTemplateIds,
17746
- loadAgentOverride: () => loadAgentOverride,
17556
+ // node_modules/fflate/lib/node.cjs
17557
+ var require_node = __commonJS({
17558
+ "node_modules/fflate/lib/node.cjs"(exports2) {
17559
+ "use strict";
17560
+ exports2.deflate = deflate;
17561
+ exports2.deflateSync = deflateSync;
17562
+ exports2.inflate = inflate;
17563
+ exports2.inflateSync = inflateSync;
17564
+ exports2.gzip = gzip;
17565
+ exports2.compress = gzip;
17566
+ exports2.gzipSync = gzipSync;
17567
+ exports2.compressSync = gzipSync;
17568
+ exports2.gunzip = gunzip;
17569
+ exports2.gunzipSync = gunzipSync;
17570
+ exports2.zlib = zlib;
17571
+ exports2.zlibSync = zlibSync;
17572
+ exports2.unzlib = unzlib;
17573
+ exports2.unzlibSync = unzlibSync;
17574
+ exports2.gzip = gzip;
17575
+ exports2.compress = gzip;
17576
+ exports2.decompress = decompress;
17577
+ exports2.decompressSync = decompressSync;
17578
+ exports2.strToU8 = strToU8;
17579
+ exports2.strFromU8 = strFromU8;
17580
+ exports2.zip = zip;
17581
+ exports2.zipSync = zipSync;
17582
+ exports2.unzip = unzip;
17583
+ exports2.unzipSync = unzipSync;
17584
+ var _a;
17585
+ var Worker;
17586
+ var isMarkedAsUntransferable;
17587
+ var workerAdd = ";var __w=require('worker_threads');__w.parentPort.on('message',function(m){onmessage({data:m})}),postMessage=function(m,t){__w.parentPort.postMessage(m,t)},close=process.exit;self=global";
17588
+ try {
17589
+ _a = require("worker_threads"), Worker = _a.Worker, isMarkedAsUntransferable = _a.isMarkedAsUntransferable;
17590
+ } catch (e) {
17591
+ }
17592
+ var node_worker_1 = {};
17593
+ node_worker_1["default"] = Worker ? function(c, _, msg, transfer, cb) {
17594
+ var done = false;
17595
+ var w = new Worker(c + workerAdd, { eval: true }).on("error", function(e) {
17596
+ return cb(e, null);
17597
+ }).on("message", function(m) {
17598
+ return cb(null, m);
17599
+ }).on("exit", function(c2) {
17600
+ if (c2 && !done)
17601
+ cb(new Error("exited with code " + c2), null);
17602
+ });
17603
+ if (isMarkedAsUntransferable)
17604
+ transfer = transfer.filter(function(t) {
17605
+ return !isMarkedAsUntransferable(t);
17606
+ });
17607
+ w.postMessage(msg, transfer);
17608
+ w.terminate = function() {
17609
+ done = true;
17610
+ return Worker.prototype.terminate.call(w);
17611
+ };
17612
+ return w;
17613
+ } : function(_, __, ___, ____, cb) {
17614
+ setImmediate(function() {
17615
+ return cb(new Error("async operations unsupported - update to Node 12+ (or Node 10-11 with the --experimental-worker CLI flag)"), null);
17616
+ });
17617
+ var NOP = function() {
17618
+ };
17619
+ return {
17620
+ terminate: NOP,
17621
+ postMessage: NOP
17622
+ };
17623
+ };
17624
+ var u8 = Uint8Array;
17625
+ var u16 = Uint16Array;
17626
+ var i32 = Int32Array;
17627
+ var fleb = new u8([
17628
+ 0,
17629
+ 0,
17630
+ 0,
17631
+ 0,
17632
+ 0,
17633
+ 0,
17634
+ 0,
17635
+ 0,
17636
+ 1,
17637
+ 1,
17638
+ 1,
17639
+ 1,
17640
+ 2,
17641
+ 2,
17642
+ 2,
17643
+ 2,
17644
+ 3,
17645
+ 3,
17646
+ 3,
17647
+ 3,
17648
+ 4,
17649
+ 4,
17650
+ 4,
17651
+ 4,
17652
+ 5,
17653
+ 5,
17654
+ 5,
17655
+ 5,
17656
+ 0,
17657
+ /* unused */
17658
+ 0,
17659
+ 0,
17660
+ /* impossible */
17661
+ 0
17662
+ ]);
17663
+ var fdeb = new u8([
17664
+ 0,
17665
+ 0,
17666
+ 0,
17667
+ 0,
17668
+ 1,
17669
+ 1,
17670
+ 2,
17671
+ 2,
17672
+ 3,
17673
+ 3,
17674
+ 4,
17675
+ 4,
17676
+ 5,
17677
+ 5,
17678
+ 6,
17679
+ 6,
17680
+ 7,
17681
+ 7,
17682
+ 8,
17683
+ 8,
17684
+ 9,
17685
+ 9,
17686
+ 10,
17687
+ 10,
17688
+ 11,
17689
+ 11,
17690
+ 12,
17691
+ 12,
17692
+ 13,
17693
+ 13,
17694
+ /* unused */
17695
+ 0,
17696
+ 0
17697
+ ]);
17698
+ var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
17699
+ var freb = function(eb, start) {
17700
+ var b = new u16(31);
17701
+ for (var i2 = 0; i2 < 31; ++i2) {
17702
+ b[i2] = start += 1 << eb[i2 - 1];
17703
+ }
17704
+ var r = new i32(b[30]);
17705
+ for (var i2 = 1; i2 < 30; ++i2) {
17706
+ for (var j = b[i2]; j < b[i2 + 1]; ++j) {
17707
+ r[j] = j - b[i2] << 5 | i2;
17708
+ }
17709
+ }
17710
+ return { b, r };
17711
+ };
17712
+ var _a = freb(fleb, 2);
17713
+ var fl = _a.b;
17714
+ var revfl = _a.r;
17715
+ fl[28] = 258, revfl[258] = 28;
17716
+ var _b = freb(fdeb, 0);
17717
+ var fd = _b.b;
17718
+ var revfd = _b.r;
17719
+ var rev = new u16(32768);
17720
+ for (i = 0; i < 32768; ++i) {
17721
+ x = (i & 43690) >> 1 | (i & 21845) << 1;
17722
+ x = (x & 52428) >> 2 | (x & 13107) << 2;
17723
+ x = (x & 61680) >> 4 | (x & 3855) << 4;
17724
+ rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
17725
+ }
17726
+ var x;
17727
+ var i;
17728
+ var hMap = (function(cd, mb, r) {
17729
+ var s = cd.length;
17730
+ var i2 = 0;
17731
+ var l = new u16(mb);
17732
+ for (; i2 < s; ++i2) {
17733
+ if (cd[i2])
17734
+ ++l[cd[i2] - 1];
17735
+ }
17736
+ var le = new u16(mb);
17737
+ for (i2 = 1; i2 < mb; ++i2) {
17738
+ le[i2] = le[i2 - 1] + l[i2 - 1] << 1;
17739
+ }
17740
+ var co;
17741
+ if (r) {
17742
+ co = new u16(1 << mb);
17743
+ var rvb = 15 - mb;
17744
+ for (i2 = 0; i2 < s; ++i2) {
17745
+ if (cd[i2]) {
17746
+ var sv = i2 << 4 | cd[i2];
17747
+ var r_1 = mb - cd[i2];
17748
+ var v = le[cd[i2] - 1]++ << r_1;
17749
+ for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
17750
+ co[rev[v] >> rvb] = sv;
17751
+ }
17752
+ }
17753
+ }
17754
+ } else {
17755
+ co = new u16(s);
17756
+ for (i2 = 0; i2 < s; ++i2) {
17757
+ if (cd[i2]) {
17758
+ co[i2] = rev[le[cd[i2] - 1]++] >> 15 - cd[i2];
17759
+ }
17760
+ }
17761
+ }
17762
+ return co;
17763
+ });
17764
+ var flt = new u8(288);
17765
+ for (i = 0; i < 144; ++i)
17766
+ flt[i] = 8;
17767
+ var i;
17768
+ for (i = 144; i < 256; ++i)
17769
+ flt[i] = 9;
17770
+ var i;
17771
+ for (i = 256; i < 280; ++i)
17772
+ flt[i] = 7;
17773
+ var i;
17774
+ for (i = 280; i < 288; ++i)
17775
+ flt[i] = 8;
17776
+ var i;
17777
+ var fdt = new u8(32);
17778
+ for (i = 0; i < 32; ++i)
17779
+ fdt[i] = 5;
17780
+ var i;
17781
+ var flm = /* @__PURE__ */ hMap(flt, 9, 0);
17782
+ var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
17783
+ var fdm = /* @__PURE__ */ hMap(fdt, 5, 0);
17784
+ var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
17785
+ var max = function(a) {
17786
+ var m = a[0];
17787
+ for (var i2 = 1; i2 < a.length; ++i2) {
17788
+ if (a[i2] > m)
17789
+ m = a[i2];
17790
+ }
17791
+ return m;
17792
+ };
17793
+ var bits = function(d, p, m) {
17794
+ var o = p / 8 | 0;
17795
+ return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
17796
+ };
17797
+ var bits16 = function(d, p) {
17798
+ var o = p / 8 | 0;
17799
+ return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
17800
+ };
17801
+ var shft = function(p) {
17802
+ return (p + 7) / 8 | 0;
17803
+ };
17804
+ var slc = function(v, s, e) {
17805
+ if (s == null || s < 0)
17806
+ s = 0;
17807
+ if (e == null || e > v.length)
17808
+ e = v.length;
17809
+ return new u8(v.subarray(s, e));
17810
+ };
17811
+ exports2.FlateErrorCode = {
17812
+ UnexpectedEOF: 0,
17813
+ InvalidBlockType: 1,
17814
+ InvalidLengthLiteral: 2,
17815
+ InvalidDistance: 3,
17816
+ StreamFinished: 4,
17817
+ NoStreamHandler: 5,
17818
+ InvalidHeader: 6,
17819
+ NoCallback: 7,
17820
+ InvalidUTF8: 8,
17821
+ ExtraFieldTooLong: 9,
17822
+ InvalidDate: 10,
17823
+ FilenameTooLong: 11,
17824
+ StreamFinishing: 12,
17825
+ InvalidZipData: 13,
17826
+ UnknownCompressionMethod: 14
17827
+ };
17828
+ var ec = [
17829
+ "unexpected EOF",
17830
+ "invalid block type",
17831
+ "invalid length/literal",
17832
+ "invalid distance",
17833
+ "stream finished",
17834
+ "no stream handler",
17835
+ ,
17836
+ // determined by compression function
17837
+ "no callback",
17838
+ "invalid UTF-8 data",
17839
+ "extra field too long",
17840
+ "date not in range 1980-2099",
17841
+ "filename too long",
17842
+ "stream finishing",
17843
+ "invalid zip data"
17844
+ // determined by unknown compression method
17845
+ ];
17846
+ var err = function(ind, msg, nt) {
17847
+ var e = new Error(msg || ec[ind]);
17848
+ e.code = ind;
17849
+ if (Error.captureStackTrace)
17850
+ Error.captureStackTrace(e, err);
17851
+ if (!nt)
17852
+ throw e;
17853
+ return e;
17854
+ };
17855
+ var inflt = function(dat, st, buf, dict) {
17856
+ var sl = dat.length, dl = dict ? dict.length : 0;
17857
+ if (!sl || st.f && !st.l)
17858
+ return buf || new u8(0);
17859
+ var noBuf = !buf;
17860
+ var resize = noBuf || st.i != 2;
17861
+ var noSt = st.i;
17862
+ if (noBuf)
17863
+ buf = new u8(sl * 3);
17864
+ var cbuf = function(l2) {
17865
+ var bl = buf.length;
17866
+ if (l2 > bl) {
17867
+ var nbuf = new u8(Math.max(bl * 2, l2));
17868
+ nbuf.set(buf);
17869
+ buf = nbuf;
17870
+ }
17871
+ };
17872
+ var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
17873
+ var tbts = sl * 8;
17874
+ do {
17875
+ if (!lm) {
17876
+ final = bits(dat, pos, 1);
17877
+ var type = bits(dat, pos + 1, 3);
17878
+ pos += 3;
17879
+ if (!type) {
17880
+ var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
17881
+ if (t > sl) {
17882
+ if (noSt)
17883
+ err(0);
17884
+ break;
17885
+ }
17886
+ if (resize)
17887
+ cbuf(bt + l);
17888
+ buf.set(dat.subarray(s, t), bt);
17889
+ st.b = bt += l, st.p = pos = t * 8, st.f = final;
17890
+ continue;
17891
+ } else if (type == 1)
17892
+ lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
17893
+ else if (type == 2) {
17894
+ var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
17895
+ var tl = hLit + bits(dat, pos + 5, 31) + 1;
17896
+ pos += 14;
17897
+ var ldt = new u8(tl);
17898
+ var clt = new u8(19);
17899
+ for (var i2 = 0; i2 < hcLen; ++i2) {
17900
+ clt[clim[i2]] = bits(dat, pos + i2 * 3, 7);
17901
+ }
17902
+ pos += hcLen * 3;
17903
+ var clb = max(clt), clbmsk = (1 << clb) - 1;
17904
+ var clm = hMap(clt, clb, 1);
17905
+ for (var i2 = 0; i2 < tl; ) {
17906
+ var r = clm[bits(dat, pos, clbmsk)];
17907
+ pos += r & 15;
17908
+ var s = r >> 4;
17909
+ if (s < 16) {
17910
+ ldt[i2++] = s;
17911
+ } else {
17912
+ var c = 0, n = 0;
17913
+ if (s == 16)
17914
+ n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i2 - 1];
17915
+ else if (s == 17)
17916
+ n = 3 + bits(dat, pos, 7), pos += 3;
17917
+ else if (s == 18)
17918
+ n = 11 + bits(dat, pos, 127), pos += 7;
17919
+ while (n--)
17920
+ ldt[i2++] = c;
17921
+ }
17922
+ }
17923
+ var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
17924
+ lbt = max(lt);
17925
+ dbt = max(dt);
17926
+ lm = hMap(lt, lbt, 1);
17927
+ dm = hMap(dt, dbt, 1);
17928
+ } else
17929
+ err(1);
17930
+ if (pos > tbts) {
17931
+ if (noSt)
17932
+ err(0);
17933
+ break;
17934
+ }
17935
+ }
17936
+ if (resize)
17937
+ cbuf(bt + 131072);
17938
+ var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
17939
+ var lpos = pos;
17940
+ for (; ; lpos = pos) {
17941
+ var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
17942
+ pos += c & 15;
17943
+ if (pos > tbts) {
17944
+ if (noSt)
17945
+ err(0);
17946
+ break;
17947
+ }
17948
+ if (!c)
17949
+ err(2);
17950
+ if (sym < 256)
17951
+ buf[bt++] = sym;
17952
+ else if (sym == 256) {
17953
+ lpos = pos, lm = null;
17954
+ break;
17955
+ } else {
17956
+ var add = sym - 254;
17957
+ if (sym > 264) {
17958
+ var i2 = sym - 257, b = fleb[i2];
17959
+ add = bits(dat, pos, (1 << b) - 1) + fl[i2];
17960
+ pos += b;
17961
+ }
17962
+ var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
17963
+ if (!d)
17964
+ err(3);
17965
+ pos += d & 15;
17966
+ var dt = fd[dsym];
17967
+ if (dsym > 3) {
17968
+ var b = fdeb[dsym];
17969
+ dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
17970
+ }
17971
+ if (pos > tbts) {
17972
+ if (noSt)
17973
+ err(0);
17974
+ break;
17975
+ }
17976
+ if (resize)
17977
+ cbuf(bt + 131072);
17978
+ var end = bt + add;
17979
+ if (bt < dt) {
17980
+ var shift = dl - dt, dend = Math.min(dt, end);
17981
+ if (shift + bt < 0)
17982
+ err(3);
17983
+ for (; bt < dend; ++bt)
17984
+ buf[bt] = dict[shift + bt];
17985
+ }
17986
+ for (; bt < end; ++bt)
17987
+ buf[bt] = buf[bt - dt];
17988
+ }
17989
+ }
17990
+ st.l = lm, st.p = lpos, st.b = bt, st.f = final;
17991
+ if (lm)
17992
+ final = 1, st.m = lbt, st.d = dm, st.n = dbt;
17993
+ } while (!final);
17994
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
17995
+ };
17996
+ var wbits = function(d, p, v) {
17997
+ v <<= p & 7;
17998
+ var o = p / 8 | 0;
17999
+ d[o] |= v;
18000
+ d[o + 1] |= v >> 8;
18001
+ };
18002
+ var wbits16 = function(d, p, v) {
18003
+ v <<= p & 7;
18004
+ var o = p / 8 | 0;
18005
+ d[o] |= v;
18006
+ d[o + 1] |= v >> 8;
18007
+ d[o + 2] |= v >> 16;
18008
+ };
18009
+ var hTree = function(d, mb) {
18010
+ var t = [];
18011
+ for (var i2 = 0; i2 < d.length; ++i2) {
18012
+ if (d[i2])
18013
+ t.push({ s: i2, f: d[i2] });
18014
+ }
18015
+ var s = t.length;
18016
+ var t2 = t.slice();
18017
+ if (!s)
18018
+ return { t: et, l: 0 };
18019
+ if (s == 1) {
18020
+ var v = new u8(t[0].s + 1);
18021
+ v[t[0].s] = 1;
18022
+ return { t: v, l: 1 };
18023
+ }
18024
+ t.sort(function(a, b) {
18025
+ return a.f - b.f;
18026
+ });
18027
+ t.push({ s: -1, f: 25001 });
18028
+ var l = t[0], r = t[1], i0 = 0, i1 = 1, i22 = 2;
18029
+ t[0] = { s: -1, f: l.f + r.f, l, r };
18030
+ while (i1 != s - 1) {
18031
+ l = t[t[i0].f < t[i22].f ? i0++ : i22++];
18032
+ r = t[i0 != i1 && t[i0].f < t[i22].f ? i0++ : i22++];
18033
+ t[i1++] = { s: -1, f: l.f + r.f, l, r };
18034
+ }
18035
+ var maxSym = t2[0].s;
18036
+ for (var i2 = 1; i2 < s; ++i2) {
18037
+ if (t2[i2].s > maxSym)
18038
+ maxSym = t2[i2].s;
18039
+ }
18040
+ var tr = new u16(maxSym + 1);
18041
+ var mbt = ln(t[i1 - 1], tr, 0);
18042
+ if (mbt > mb) {
18043
+ var i2 = 0, dt = 0;
18044
+ var lft = mbt - mb, cst = 1 << lft;
18045
+ t2.sort(function(a, b) {
18046
+ return tr[b.s] - tr[a.s] || a.f - b.f;
18047
+ });
18048
+ for (; i2 < s; ++i2) {
18049
+ var i2_1 = t2[i2].s;
18050
+ if (tr[i2_1] > mb) {
18051
+ dt += cst - (1 << mbt - tr[i2_1]);
18052
+ tr[i2_1] = mb;
18053
+ } else
18054
+ break;
18055
+ }
18056
+ dt >>= lft;
18057
+ while (dt > 0) {
18058
+ var i2_2 = t2[i2].s;
18059
+ if (tr[i2_2] < mb)
18060
+ dt -= 1 << mb - tr[i2_2]++ - 1;
18061
+ else
18062
+ ++i2;
18063
+ }
18064
+ for (; i2 >= 0 && dt; --i2) {
18065
+ var i2_3 = t2[i2].s;
18066
+ if (tr[i2_3] == mb) {
18067
+ --tr[i2_3];
18068
+ ++dt;
18069
+ }
18070
+ }
18071
+ mbt = mb;
18072
+ }
18073
+ return { t: new u8(tr), l: mbt };
18074
+ };
18075
+ var ln = function(n, l, d) {
18076
+ return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : l[n.s] = d;
18077
+ };
18078
+ var lc = function(c) {
18079
+ var s = c.length;
18080
+ while (s && !c[--s])
18081
+ ;
18082
+ var cl = new u16(++s);
18083
+ var cli = 0, cln = c[0], cls = 1;
18084
+ var w = function(v) {
18085
+ cl[cli++] = v;
18086
+ };
18087
+ for (var i2 = 1; i2 <= s; ++i2) {
18088
+ if (c[i2] == cln && i2 != s)
18089
+ ++cls;
18090
+ else {
18091
+ if (!cln && cls > 2) {
18092
+ for (; cls > 138; cls -= 138)
18093
+ w(32754);
18094
+ if (cls > 2) {
18095
+ w(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305);
18096
+ cls = 0;
18097
+ }
18098
+ } else if (cls > 3) {
18099
+ w(cln), --cls;
18100
+ for (; cls > 6; cls -= 6)
18101
+ w(8304);
18102
+ if (cls > 2)
18103
+ w(cls - 3 << 5 | 8208), cls = 0;
18104
+ }
18105
+ while (cls--)
18106
+ w(cln);
18107
+ cls = 1;
18108
+ cln = c[i2];
18109
+ }
18110
+ }
18111
+ return { c: cl.subarray(0, cli), n: s };
18112
+ };
18113
+ var clen = function(cf, cl) {
18114
+ var l = 0;
18115
+ for (var i2 = 0; i2 < cl.length; ++i2)
18116
+ l += cf[i2] * cl[i2];
18117
+ return l;
18118
+ };
18119
+ var wfblk = function(out, pos, dat) {
18120
+ var s = dat.length;
18121
+ var o = shft(pos + 2);
18122
+ out[o] = s & 255;
18123
+ out[o + 1] = s >> 8;
18124
+ out[o + 2] = out[o] ^ 255;
18125
+ out[o + 3] = out[o + 1] ^ 255;
18126
+ for (var i2 = 0; i2 < s; ++i2)
18127
+ out[o + i2 + 4] = dat[i2];
18128
+ return (o + 4 + s) * 8;
18129
+ };
18130
+ var wblk = function(dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
18131
+ wbits(out, p++, final);
18132
+ ++lf[256];
18133
+ var _a2 = hTree(lf, 15), dlt = _a2.t, mlb = _a2.l;
18134
+ var _b2 = hTree(df, 15), ddt = _b2.t, mdb = _b2.l;
18135
+ var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
18136
+ var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
18137
+ var lcfreq = new u16(19);
18138
+ for (var i2 = 0; i2 < lclt.length; ++i2)
18139
+ ++lcfreq[lclt[i2] & 31];
18140
+ for (var i2 = 0; i2 < lcdt.length; ++i2)
18141
+ ++lcfreq[lcdt[i2] & 31];
18142
+ var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
18143
+ var nlcc = 19;
18144
+ for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
18145
+ ;
18146
+ var flen = bl + 5 << 3;
18147
+ var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
18148
+ var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
18149
+ if (bs >= 0 && flen <= ftlen && flen <= dtlen)
18150
+ return wfblk(out, p, dat.subarray(bs, bs + bl));
18151
+ var lm, ll, dm, dl;
18152
+ wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
18153
+ if (dtlen < ftlen) {
18154
+ lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
18155
+ var llm = hMap(lct, mlcb, 0);
18156
+ wbits(out, p, nlc - 257);
18157
+ wbits(out, p + 5, ndc - 1);
18158
+ wbits(out, p + 10, nlcc - 4);
18159
+ p += 14;
18160
+ for (var i2 = 0; i2 < nlcc; ++i2)
18161
+ wbits(out, p + 3 * i2, lct[clim[i2]]);
18162
+ p += 3 * nlcc;
18163
+ var lcts = [lclt, lcdt];
18164
+ for (var it = 0; it < 2; ++it) {
18165
+ var clct = lcts[it];
18166
+ for (var i2 = 0; i2 < clct.length; ++i2) {
18167
+ var len = clct[i2] & 31;
18168
+ wbits(out, p, llm[len]), p += lct[len];
18169
+ if (len > 15)
18170
+ wbits(out, p, clct[i2] >> 5 & 127), p += clct[i2] >> 12;
18171
+ }
18172
+ }
18173
+ } else {
18174
+ lm = flm, ll = flt, dm = fdm, dl = fdt;
18175
+ }
18176
+ for (var i2 = 0; i2 < li; ++i2) {
18177
+ var sym = syms[i2];
18178
+ if (sym > 255) {
18179
+ var len = sym >> 18 & 31;
18180
+ wbits16(out, p, lm[len + 257]), p += ll[len + 257];
18181
+ if (len > 7)
18182
+ wbits(out, p, sym >> 23 & 31), p += fleb[len];
18183
+ var dst = sym & 31;
18184
+ wbits16(out, p, dm[dst]), p += dl[dst];
18185
+ if (dst > 3)
18186
+ wbits16(out, p, sym >> 5 & 8191), p += fdeb[dst];
18187
+ } else {
18188
+ wbits16(out, p, lm[sym]), p += ll[sym];
18189
+ }
18190
+ }
18191
+ wbits16(out, p, lm[256]);
18192
+ return p + ll[256];
18193
+ };
18194
+ var deo = /* @__PURE__ */ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
18195
+ var et = /* @__PURE__ */ new u8(0);
18196
+ var dflt = function(dat, lvl, plvl, pre, post, st) {
18197
+ var s = st.z || dat.length;
18198
+ var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7e3)) + post);
18199
+ var w = o.subarray(pre, o.length - post);
18200
+ var lst = st.l;
18201
+ var pos = (st.r || 0) & 7;
18202
+ if (lvl) {
18203
+ if (pos)
18204
+ w[0] = st.r >> 3;
18205
+ var opt = deo[lvl - 1];
18206
+ var n = opt >> 13, c = opt & 8191;
18207
+ var msk_1 = (1 << plvl) - 1;
18208
+ var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
18209
+ var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
18210
+ var hsh = function(i3) {
18211
+ return (dat[i3] ^ dat[i3 + 1] << bs1_1 ^ dat[i3 + 2] << bs2_1) & msk_1;
18212
+ };
18213
+ var syms = new i32(25e3);
18214
+ var lf = new u16(288), df = new u16(32);
18215
+ var lc_1 = 0, eb = 0, i2 = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
18216
+ for (; i2 + 2 < s; ++i2) {
18217
+ var hv = hsh(i2);
18218
+ var imod = i2 & 32767, pimod = head[hv];
18219
+ prev[imod] = pimod;
18220
+ head[hv] = imod;
18221
+ if (wi <= i2) {
18222
+ var rem = s - i2;
18223
+ if ((lc_1 > 7e3 || li > 24576) && (rem > 423 || !lst)) {
18224
+ pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i2 - bs, pos);
18225
+ li = lc_1 = eb = 0, bs = i2;
18226
+ for (var j = 0; j < 286; ++j)
18227
+ lf[j] = 0;
18228
+ for (var j = 0; j < 30; ++j)
18229
+ df[j] = 0;
18230
+ }
18231
+ var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
18232
+ if (rem > 2 && hv == hsh(i2 - dif)) {
18233
+ var maxn = Math.min(n, rem) - 1;
18234
+ var maxd = Math.min(32767, i2);
18235
+ var ml = Math.min(258, rem);
18236
+ while (dif <= maxd && --ch_1 && imod != pimod) {
18237
+ if (dat[i2 + l] == dat[i2 + l - dif]) {
18238
+ var nl = 0;
18239
+ for (; nl < ml && dat[i2 + nl] == dat[i2 + nl - dif]; ++nl)
18240
+ ;
18241
+ if (nl > l) {
18242
+ l = nl, d = dif;
18243
+ if (nl > maxn)
18244
+ break;
18245
+ var mmd = Math.min(dif, nl - 2);
18246
+ var md = 0;
18247
+ for (var j = 0; j < mmd; ++j) {
18248
+ var ti = i2 - dif + j & 32767;
18249
+ var pti = prev[ti];
18250
+ var cd = ti - pti & 32767;
18251
+ if (cd > md)
18252
+ md = cd, pimod = ti;
18253
+ }
18254
+ }
18255
+ }
18256
+ imod = pimod, pimod = prev[imod];
18257
+ dif += imod - pimod & 32767;
18258
+ }
18259
+ }
18260
+ if (d) {
18261
+ syms[li++] = 268435456 | revfl[l] << 18 | revfd[d];
18262
+ var lin = revfl[l] & 31, din = revfd[d] & 31;
18263
+ eb += fleb[lin] + fdeb[din];
18264
+ ++lf[257 + lin];
18265
+ ++df[din];
18266
+ wi = i2 + l;
18267
+ ++lc_1;
18268
+ } else {
18269
+ syms[li++] = dat[i2];
18270
+ ++lf[dat[i2]];
18271
+ }
18272
+ }
18273
+ }
18274
+ for (i2 = Math.max(i2, wi); i2 < s; ++i2) {
18275
+ syms[li++] = dat[i2];
18276
+ ++lf[dat[i2]];
18277
+ }
18278
+ pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i2 - bs, pos);
18279
+ if (!lst) {
18280
+ st.r = pos & 7 | w[pos / 8 | 0] << 3;
18281
+ pos -= 7;
18282
+ st.h = head, st.p = prev, st.i = i2, st.w = wi;
18283
+ }
18284
+ } else {
18285
+ for (var i2 = st.w || 0; i2 < s + lst; i2 += 65535) {
18286
+ var e = i2 + 65535;
18287
+ if (e >= s) {
18288
+ w[pos / 8 | 0] = lst;
18289
+ e = s;
18290
+ }
18291
+ pos = wfblk(w, pos + 1, dat.subarray(i2, e));
18292
+ }
18293
+ st.i = s;
18294
+ }
18295
+ return slc(o, 0, pre + shft(pos) + post);
18296
+ };
18297
+ var crct = /* @__PURE__ */ (function() {
18298
+ var t = new Int32Array(256);
18299
+ for (var i2 = 0; i2 < 256; ++i2) {
18300
+ var c = i2, k = 9;
18301
+ while (--k)
18302
+ c = (c & 1 && -306674912) ^ c >>> 1;
18303
+ t[i2] = c;
18304
+ }
18305
+ return t;
18306
+ })();
18307
+ var crc = function() {
18308
+ var c = -1;
18309
+ return {
18310
+ p: function(d) {
18311
+ var cr = c;
18312
+ for (var i2 = 0; i2 < d.length; ++i2)
18313
+ cr = crct[cr & 255 ^ d[i2]] ^ cr >>> 8;
18314
+ c = cr;
18315
+ },
18316
+ d: function() {
18317
+ return ~c;
18318
+ }
18319
+ };
18320
+ };
18321
+ var adler = function() {
18322
+ var a = 1, b = 0;
18323
+ return {
18324
+ p: function(d) {
18325
+ var n = a, m = b;
18326
+ var l = d.length | 0;
18327
+ for (var i2 = 0; i2 != l; ) {
18328
+ var e = Math.min(i2 + 2655, l);
18329
+ for (; i2 < e; ++i2)
18330
+ m += n += d[i2];
18331
+ n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);
18332
+ }
18333
+ a = n, b = m;
18334
+ },
18335
+ d: function() {
18336
+ a %= 65521, b %= 65521;
18337
+ return (a & 255) << 24 | (a & 65280) << 8 | (b & 255) << 8 | b >> 8;
18338
+ }
18339
+ };
18340
+ };
18341
+ var dopt = function(dat, opt, pre, post, st) {
18342
+ if (!st) {
18343
+ st = { l: 1 };
18344
+ if (opt.dictionary) {
18345
+ var dict = opt.dictionary.subarray(-32768);
18346
+ var newDat = new u8(dict.length + dat.length);
18347
+ newDat.set(dict);
18348
+ newDat.set(dat, dict.length);
18349
+ dat = newDat;
18350
+ st.w = dict.length;
18351
+ }
18352
+ }
18353
+ return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st);
18354
+ };
18355
+ var mrg = function(a, b) {
18356
+ var o = {};
18357
+ for (var k in a)
18358
+ o[k] = a[k];
18359
+ for (var k in b)
18360
+ o[k] = b[k];
18361
+ return o;
18362
+ };
18363
+ var wcln = function(fn, fnStr, td2) {
18364
+ var dt = fn();
18365
+ var st = fn.toString();
18366
+ var ks = st.slice(st.indexOf("[") + 1, st.lastIndexOf("]")).replace(/\s+/g, "").split(",");
18367
+ for (var i2 = 0; i2 < dt.length; ++i2) {
18368
+ var v = dt[i2], k = ks[i2];
18369
+ if (typeof v == "function") {
18370
+ fnStr += ";" + k + "=";
18371
+ var st_1 = v.toString();
18372
+ if (v.prototype) {
18373
+ if (st_1.indexOf("[native code]") != -1) {
18374
+ var spInd = st_1.indexOf(" ", 8) + 1;
18375
+ fnStr += st_1.slice(spInd, st_1.indexOf("(", spInd));
18376
+ } else {
18377
+ fnStr += st_1;
18378
+ for (var t in v.prototype)
18379
+ fnStr += ";" + k + ".prototype." + t + "=" + v.prototype[t].toString();
18380
+ }
18381
+ } else
18382
+ fnStr += st_1;
18383
+ } else
18384
+ td2[k] = v;
18385
+ }
18386
+ return fnStr;
18387
+ };
18388
+ var ch = [];
18389
+ var cbfs = function(v) {
18390
+ var tl = [];
18391
+ for (var k in v) {
18392
+ if (v[k].buffer) {
18393
+ tl.push((v[k] = new v[k].constructor(v[k])).buffer);
18394
+ }
18395
+ }
18396
+ return tl;
18397
+ };
18398
+ var wrkr = function(fns, init, id, cb) {
18399
+ if (!ch[id]) {
18400
+ var fnStr = "", td_1 = {}, m = fns.length - 1;
18401
+ for (var i2 = 0; i2 < m; ++i2)
18402
+ fnStr = wcln(fns[i2], fnStr, td_1);
18403
+ ch[id] = { c: wcln(fns[m], fnStr, td_1), e: td_1 };
18404
+ }
18405
+ var td2 = mrg({}, ch[id].e);
18406
+ return (0, node_worker_1.default)(ch[id].c + ";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=" + init.toString() + "}", id, td2, cbfs(td2), cb);
18407
+ };
18408
+ var bInflt = function() {
18409
+ return [u8, u16, i32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err, inflt, inflateSync, pbf, gopt];
18410
+ };
18411
+ var bDflt = function() {
18412
+ return [u8, u16, i32, fleb, fdeb, clim, revfl, revfd, flm, flt, fdm, fdt, rev, deo, et, hMap, wbits, wbits16, hTree, ln, lc, clen, wfblk, wblk, shft, slc, dflt, dopt, deflateSync, pbf];
18413
+ };
18414
+ var gze = function() {
18415
+ return [gzh, gzhl, wbytes, crc, crct];
18416
+ };
18417
+ var guze = function() {
18418
+ return [gzs, gzl];
18419
+ };
18420
+ var zle = function() {
18421
+ return [zlh, wbytes, adler];
18422
+ };
18423
+ var zule = function() {
18424
+ return [zls];
18425
+ };
18426
+ var pbf = function(msg) {
18427
+ return postMessage(msg, [msg.buffer]);
18428
+ };
18429
+ var gopt = function(o) {
18430
+ return o && {
18431
+ out: o.size && new u8(o.size),
18432
+ dictionary: o.dictionary
18433
+ };
18434
+ };
18435
+ var cbify = function(dat, opts, fns, init, id, cb) {
18436
+ var w = wrkr(fns, init, id, function(err2, dat2) {
18437
+ w.terminate();
18438
+ cb(err2, dat2);
18439
+ });
18440
+ w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);
18441
+ return function() {
18442
+ w.terminate();
18443
+ };
18444
+ };
18445
+ var astrm = function(strm) {
18446
+ strm.ondata = function(dat, final) {
18447
+ return postMessage([dat, final], [dat.buffer]);
18448
+ };
18449
+ return function(ev) {
18450
+ if (ev.data[0]) {
18451
+ strm.push(ev.data[0], ev.data[1]);
18452
+ postMessage([ev.data[0].length]);
18453
+ } else
18454
+ strm.flush(ev.data[1]);
18455
+ };
18456
+ };
18457
+ var astrmify = function(fns, strm, opts, init, id, flush, ext) {
18458
+ var t;
18459
+ var w = wrkr(fns, init, id, function(err2, dat) {
18460
+ if (err2)
18461
+ w.terminate(), strm.ondata.call(strm, err2);
18462
+ else if (!Array.isArray(dat))
18463
+ ext(dat);
18464
+ else if (dat.length == 1) {
18465
+ strm.queuedSize -= dat[0];
18466
+ if (strm.ondrain)
18467
+ strm.ondrain(dat[0]);
18468
+ } else {
18469
+ if (dat[1])
18470
+ w.terminate();
18471
+ strm.ondata.call(strm, err2, dat[0], dat[1]);
18472
+ }
18473
+ });
18474
+ w.postMessage(opts);
18475
+ strm.queuedSize = 0;
18476
+ strm.push = function(d, f) {
18477
+ if (!strm.ondata)
18478
+ err(5);
18479
+ if (t)
18480
+ strm.ondata(err(4, 0, 1), null, !!f);
18481
+ strm.queuedSize += d.length;
18482
+ w.postMessage([d, t = f], d.buffer instanceof ArrayBuffer ? [d.buffer] : []);
18483
+ };
18484
+ strm.terminate = function() {
18485
+ w.terminate();
18486
+ };
18487
+ if (flush) {
18488
+ strm.flush = function(sync) {
18489
+ w.postMessage([0, sync]);
18490
+ };
18491
+ }
18492
+ };
18493
+ var b2 = function(d, b) {
18494
+ return d[b] | d[b + 1] << 8;
18495
+ };
18496
+ var b4 = function(d, b) {
18497
+ return (d[b] | d[b + 1] << 8 | d[b + 2] << 16 | d[b + 3] << 24) >>> 0;
18498
+ };
18499
+ var b8 = function(d, b) {
18500
+ return b4(d, b) + b4(d, b + 4) * 4294967296;
18501
+ };
18502
+ var wbytes = function(d, b, v) {
18503
+ for (; v; ++b)
18504
+ d[b] = v, v >>>= 8;
18505
+ };
18506
+ var gzh = function(c, o) {
18507
+ var fn = o.filename;
18508
+ c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3;
18509
+ if (o.mtime != 0)
18510
+ wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1e3));
18511
+ if (fn) {
18512
+ c[3] = 8;
18513
+ for (var i2 = 0; i2 <= fn.length; ++i2)
18514
+ c[i2 + 10] = fn.charCodeAt(i2);
18515
+ }
18516
+ };
18517
+ var gzs = function(d) {
18518
+ if (d[0] != 31 || d[1] != 139 || d[2] != 8)
18519
+ err(6, "invalid gzip data");
18520
+ var flg = d[3];
18521
+ var st = 10;
18522
+ if (flg & 4)
18523
+ st += (d[10] | d[11] << 8) + 2;
18524
+ for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])
18525
+ ;
18526
+ return st + (flg & 2);
18527
+ };
18528
+ var gzl = function(d) {
18529
+ var l = d.length;
18530
+ return (d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16 | d[l - 1] << 24) >>> 0;
18531
+ };
18532
+ var gzhl = function(o) {
18533
+ return 10 + (o.filename ? o.filename.length + 1 : 0);
18534
+ };
18535
+ var zlh = function(c, o) {
18536
+ var lv = o.level, fl2 = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;
18537
+ c[0] = 120, c[1] = fl2 << 6 | (o.dictionary && 32);
18538
+ c[1] |= 31 - (c[0] << 8 | c[1]) % 31;
18539
+ if (o.dictionary) {
18540
+ var h = adler();
18541
+ h.p(o.dictionary);
18542
+ wbytes(c, 2, h.d());
18543
+ }
18544
+ };
18545
+ var zls = function(d, dict) {
18546
+ if ((d[0] & 15) != 8 || d[0] >> 4 > 7 || (d[0] << 8 | d[1]) % 31)
18547
+ err(6, "invalid zlib data");
18548
+ if ((d[1] >> 5 & 1) == +!dict)
18549
+ err(6, "invalid zlib data: " + (d[1] & 32 ? "need" : "unexpected") + " dictionary");
18550
+ return (d[1] >> 3 & 4) + 2;
18551
+ };
18552
+ function StrmOpt(opts, cb) {
18553
+ if (typeof opts == "function")
18554
+ cb = opts, opts = {};
18555
+ this.ondata = cb;
18556
+ return opts;
18557
+ }
18558
+ var Deflate = /* @__PURE__ */ (function() {
18559
+ function Deflate2(opts, cb) {
18560
+ if (typeof opts == "function")
18561
+ cb = opts, opts = {};
18562
+ this.ondata = cb;
18563
+ this.o = opts || {};
18564
+ this.s = { l: 0, i: 32768, w: 32768, z: 32768 };
18565
+ this.b = new u8(98304);
18566
+ if (this.o.dictionary) {
18567
+ var dict = this.o.dictionary.subarray(-32768);
18568
+ this.b.set(dict, 32768 - dict.length);
18569
+ this.s.i = 32768 - dict.length;
18570
+ }
18571
+ }
18572
+ Deflate2.prototype.p = function(c, f) {
18573
+ this.ondata(dopt(c, this.o, 0, 0, this.s), f);
18574
+ };
18575
+ Deflate2.prototype.push = function(chunk, final) {
18576
+ if (!this.ondata)
18577
+ err(5);
18578
+ if (this.s.l)
18579
+ err(4);
18580
+ var endLen = chunk.length + this.s.z;
18581
+ if (endLen > this.b.length) {
18582
+ if (endLen > 2 * this.b.length - 32768) {
18583
+ var newBuf = new u8(endLen & -32768);
18584
+ newBuf.set(this.b.subarray(0, this.s.z));
18585
+ this.b = newBuf;
18586
+ }
18587
+ var split = this.b.length - this.s.z;
18588
+ this.b.set(chunk.subarray(0, split), this.s.z);
18589
+ this.s.z = this.b.length;
18590
+ this.p(this.b, false);
18591
+ this.b.set(this.b.subarray(-32768));
18592
+ this.b.set(chunk.subarray(split), 32768);
18593
+ this.s.z = chunk.length - split + 32768;
18594
+ this.s.i = 32766, this.s.w = 32768;
18595
+ } else {
18596
+ this.b.set(chunk, this.s.z);
18597
+ this.s.z += chunk.length;
18598
+ }
18599
+ this.s.l = final & 1;
18600
+ if (this.s.z > this.s.w + 8191 || final) {
18601
+ this.p(this.b, final || false);
18602
+ this.s.w = this.s.i, this.s.i -= 2;
18603
+ }
18604
+ if (final) {
18605
+ this.s = this.o = {};
18606
+ this.b = et;
18607
+ }
18608
+ };
18609
+ Deflate2.prototype.flush = function(sync) {
18610
+ if (!this.ondata)
18611
+ err(5);
18612
+ if (this.s.l)
18613
+ err(4);
18614
+ this.p(this.b, false);
18615
+ this.s.w = this.s.i, this.s.i -= 2;
18616
+ if (sync) {
18617
+ var c = new u8(6);
18618
+ c[0] = this.s.r >> 3;
18619
+ var ep = wfblk(c, this.s.r, et);
18620
+ this.s.r = 0;
18621
+ this.ondata(c.subarray(0, ep >> 3), false);
18622
+ }
18623
+ };
18624
+ return Deflate2;
18625
+ })();
18626
+ exports2.Deflate = Deflate;
18627
+ var AsyncDeflate = /* @__PURE__ */ (function() {
18628
+ function AsyncDeflate2(opts, cb) {
18629
+ astrmify([
18630
+ bDflt,
18631
+ function() {
18632
+ return [astrm, Deflate];
18633
+ }
18634
+ ], this, StrmOpt.call(this, opts, cb), function(ev) {
18635
+ var strm = new Deflate(ev.data);
18636
+ onmessage = astrm(strm);
18637
+ }, 6, 1);
18638
+ }
18639
+ return AsyncDeflate2;
18640
+ })();
18641
+ exports2.AsyncDeflate = AsyncDeflate;
18642
+ function deflate(data, opts, cb) {
18643
+ if (!cb)
18644
+ cb = opts, opts = {};
18645
+ if (typeof cb != "function")
18646
+ err(7);
18647
+ return cbify(data, opts, [
18648
+ bDflt
18649
+ ], function(ev) {
18650
+ return pbf(deflateSync(ev.data[0], ev.data[1]));
18651
+ }, 0, cb);
18652
+ }
18653
+ function deflateSync(data, opts) {
18654
+ return dopt(data, opts || {}, 0, 0);
18655
+ }
18656
+ var Inflate = /* @__PURE__ */ (function() {
18657
+ function Inflate2(opts, cb) {
18658
+ if (typeof opts == "function")
18659
+ cb = opts, opts = {};
18660
+ this.ondata = cb;
18661
+ var dict = opts && opts.dictionary && opts.dictionary.subarray(-32768);
18662
+ this.s = { i: 0, b: dict ? dict.length : 0 };
18663
+ this.o = new u8(32768);
18664
+ this.p = new u8(0);
18665
+ if (dict)
18666
+ this.o.set(dict);
18667
+ }
18668
+ Inflate2.prototype.e = function(c) {
18669
+ if (!this.ondata)
18670
+ err(5);
18671
+ if (this.d)
18672
+ err(4);
18673
+ if (!this.p.length)
18674
+ this.p = c;
18675
+ else if (c.length) {
18676
+ var n = new u8(this.p.length + c.length);
18677
+ n.set(this.p), n.set(c, this.p.length), this.p = n;
18678
+ }
18679
+ };
18680
+ Inflate2.prototype.c = function(final) {
18681
+ this.s.i = +(this.d = final || false);
18682
+ var bts = this.s.b;
18683
+ var dt = inflt(this.p, this.s, this.o);
18684
+ this.ondata(slc(dt, bts, this.s.b), this.d);
18685
+ this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;
18686
+ this.p = slc(this.p, this.s.p / 8 | 0), this.s.p &= 7;
18687
+ };
18688
+ Inflate2.prototype.push = function(chunk, final) {
18689
+ this.e(chunk), this.c(final);
18690
+ };
18691
+ return Inflate2;
18692
+ })();
18693
+ exports2.Inflate = Inflate;
18694
+ var AsyncInflate = /* @__PURE__ */ (function() {
18695
+ function AsyncInflate2(opts, cb) {
18696
+ astrmify([
18697
+ bInflt,
18698
+ function() {
18699
+ return [astrm, Inflate];
18700
+ }
18701
+ ], this, StrmOpt.call(this, opts, cb), function(ev) {
18702
+ var strm = new Inflate(ev.data);
18703
+ onmessage = astrm(strm);
18704
+ }, 7, 0);
18705
+ }
18706
+ return AsyncInflate2;
18707
+ })();
18708
+ exports2.AsyncInflate = AsyncInflate;
18709
+ function inflate(data, opts, cb) {
18710
+ if (!cb)
18711
+ cb = opts, opts = {};
18712
+ if (typeof cb != "function")
18713
+ err(7);
18714
+ return cbify(data, opts, [
18715
+ bInflt
18716
+ ], function(ev) {
18717
+ return pbf(inflateSync(ev.data[0], gopt(ev.data[1])));
18718
+ }, 1, cb);
18719
+ }
18720
+ function inflateSync(data, opts) {
18721
+ return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
18722
+ }
18723
+ var Gzip = /* @__PURE__ */ (function() {
18724
+ function Gzip2(opts, cb) {
18725
+ this.c = crc();
18726
+ this.l = 0;
18727
+ this.v = 1;
18728
+ Deflate.call(this, opts, cb);
18729
+ }
18730
+ Gzip2.prototype.push = function(chunk, final) {
18731
+ this.c.p(chunk);
18732
+ this.l += chunk.length;
18733
+ Deflate.prototype.push.call(this, chunk, final);
18734
+ };
18735
+ Gzip2.prototype.p = function(c, f) {
18736
+ var raw = dopt(c, this.o, this.v && gzhl(this.o), f && 8, this.s);
18737
+ if (this.v)
18738
+ gzh(raw, this.o), this.v = 0;
18739
+ if (f)
18740
+ wbytes(raw, raw.length - 8, this.c.d()), wbytes(raw, raw.length - 4, this.l);
18741
+ this.ondata(raw, f);
18742
+ };
18743
+ Gzip2.prototype.flush = function(sync) {
18744
+ Deflate.prototype.flush.call(this, sync);
18745
+ };
18746
+ return Gzip2;
18747
+ })();
18748
+ exports2.Gzip = Gzip;
18749
+ exports2.Compress = Gzip;
18750
+ var AsyncGzip = /* @__PURE__ */ (function() {
18751
+ function AsyncGzip2(opts, cb) {
18752
+ astrmify([
18753
+ bDflt,
18754
+ gze,
18755
+ function() {
18756
+ return [astrm, Deflate, Gzip];
18757
+ }
18758
+ ], this, StrmOpt.call(this, opts, cb), function(ev) {
18759
+ var strm = new Gzip(ev.data);
18760
+ onmessage = astrm(strm);
18761
+ }, 8, 1);
18762
+ }
18763
+ return AsyncGzip2;
18764
+ })();
18765
+ exports2.AsyncGzip = AsyncGzip;
18766
+ exports2.AsyncCompress = AsyncGzip;
18767
+ function gzip(data, opts, cb) {
18768
+ if (!cb)
18769
+ cb = opts, opts = {};
18770
+ if (typeof cb != "function")
18771
+ err(7);
18772
+ return cbify(data, opts, [
18773
+ bDflt,
18774
+ gze,
18775
+ function() {
18776
+ return [gzipSync];
18777
+ }
18778
+ ], function(ev) {
18779
+ return pbf(gzipSync(ev.data[0], ev.data[1]));
18780
+ }, 2, cb);
18781
+ }
18782
+ function gzipSync(data, opts) {
18783
+ if (!opts)
18784
+ opts = {};
18785
+ var c = crc(), l = data.length;
18786
+ c.p(data);
18787
+ var d = dopt(data, opts, gzhl(opts), 8), s = d.length;
18788
+ return gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d;
18789
+ }
18790
+ var Gunzip = /* @__PURE__ */ (function() {
18791
+ function Gunzip2(opts, cb) {
18792
+ this.v = 1;
18793
+ this.r = 0;
18794
+ Inflate.call(this, opts, cb);
18795
+ }
18796
+ Gunzip2.prototype.push = function(chunk, final) {
18797
+ Inflate.prototype.e.call(this, chunk);
18798
+ this.r += chunk.length;
18799
+ if (this.v) {
18800
+ var p = this.p.subarray(this.v - 1);
18801
+ var s = p.length > 3 ? gzs(p) : 4;
18802
+ if (s > p.length) {
18803
+ if (!final)
18804
+ return;
18805
+ } else if (this.v > 1 && this.onmember) {
18806
+ this.onmember(this.r - p.length);
18807
+ }
18808
+ this.p = p.subarray(s), this.v = 0;
18809
+ }
18810
+ Inflate.prototype.c.call(this, 0);
18811
+ if (this.s.f && !this.s.l) {
18812
+ this.v = shft(this.s.p) + 9;
18813
+ this.s = { i: 0 };
18814
+ this.o = new u8(0);
18815
+ this.push(new u8(0), final);
18816
+ } else if (final) {
18817
+ Inflate.prototype.c.call(this, final);
18818
+ }
18819
+ };
18820
+ return Gunzip2;
18821
+ })();
18822
+ exports2.Gunzip = Gunzip;
18823
+ var AsyncGunzip = /* @__PURE__ */ (function() {
18824
+ function AsyncGunzip2(opts, cb) {
18825
+ var _this = this;
18826
+ astrmify([
18827
+ bInflt,
18828
+ guze,
18829
+ function() {
18830
+ return [astrm, Inflate, Gunzip];
18831
+ }
18832
+ ], this, StrmOpt.call(this, opts, cb), function(ev) {
18833
+ var strm = new Gunzip(ev.data);
18834
+ strm.onmember = function(offset) {
18835
+ return postMessage(offset);
18836
+ };
18837
+ onmessage = astrm(strm);
18838
+ }, 9, 0, function(offset) {
18839
+ return _this.onmember && _this.onmember(offset);
18840
+ });
18841
+ }
18842
+ return AsyncGunzip2;
18843
+ })();
18844
+ exports2.AsyncGunzip = AsyncGunzip;
18845
+ function gunzip(data, opts, cb) {
18846
+ if (!cb)
18847
+ cb = opts, opts = {};
18848
+ if (typeof cb != "function")
18849
+ err(7);
18850
+ return cbify(data, opts, [
18851
+ bInflt,
18852
+ guze,
18853
+ function() {
18854
+ return [gunzipSync];
18855
+ }
18856
+ ], function(ev) {
18857
+ return pbf(gunzipSync(ev.data[0], ev.data[1]));
18858
+ }, 3, cb);
18859
+ }
18860
+ function gunzipSync(data, opts) {
18861
+ var st = gzs(data);
18862
+ if (st + 8 > data.length)
18863
+ err(6, "invalid gzip data");
18864
+ return inflt(data.subarray(st, -8), { i: 2 }, opts && opts.out || new u8(gzl(data)), opts && opts.dictionary);
18865
+ }
18866
+ var Zlib = /* @__PURE__ */ (function() {
18867
+ function Zlib2(opts, cb) {
18868
+ this.c = adler();
18869
+ this.v = 1;
18870
+ Deflate.call(this, opts, cb);
18871
+ }
18872
+ Zlib2.prototype.push = function(chunk, final) {
18873
+ this.c.p(chunk);
18874
+ Deflate.prototype.push.call(this, chunk, final);
18875
+ };
18876
+ Zlib2.prototype.p = function(c, f) {
18877
+ var raw = dopt(c, this.o, this.v && (this.o.dictionary ? 6 : 2), f && 4, this.s);
18878
+ if (this.v)
18879
+ zlh(raw, this.o), this.v = 0;
18880
+ if (f)
18881
+ wbytes(raw, raw.length - 4, this.c.d());
18882
+ this.ondata(raw, f);
18883
+ };
18884
+ Zlib2.prototype.flush = function(sync) {
18885
+ Deflate.prototype.flush.call(this, sync);
18886
+ };
18887
+ return Zlib2;
18888
+ })();
18889
+ exports2.Zlib = Zlib;
18890
+ var AsyncZlib = /* @__PURE__ */ (function() {
18891
+ function AsyncZlib2(opts, cb) {
18892
+ astrmify([
18893
+ bDflt,
18894
+ zle,
18895
+ function() {
18896
+ return [astrm, Deflate, Zlib];
18897
+ }
18898
+ ], this, StrmOpt.call(this, opts, cb), function(ev) {
18899
+ var strm = new Zlib(ev.data);
18900
+ onmessage = astrm(strm);
18901
+ }, 10, 1);
18902
+ }
18903
+ return AsyncZlib2;
18904
+ })();
18905
+ exports2.AsyncZlib = AsyncZlib;
18906
+ function zlib(data, opts, cb) {
18907
+ if (!cb)
18908
+ cb = opts, opts = {};
18909
+ if (typeof cb != "function")
18910
+ err(7);
18911
+ return cbify(data, opts, [
18912
+ bDflt,
18913
+ zle,
18914
+ function() {
18915
+ return [zlibSync];
18916
+ }
18917
+ ], function(ev) {
18918
+ return pbf(zlibSync(ev.data[0], ev.data[1]));
18919
+ }, 4, cb);
18920
+ }
18921
+ function zlibSync(data, opts) {
18922
+ if (!opts)
18923
+ opts = {};
18924
+ var a = adler();
18925
+ a.p(data);
18926
+ var d = dopt(data, opts, opts.dictionary ? 6 : 2, 4);
18927
+ return zlh(d, opts), wbytes(d, d.length - 4, a.d()), d;
18928
+ }
18929
+ var Unzlib = /* @__PURE__ */ (function() {
18930
+ function Unzlib2(opts, cb) {
18931
+ Inflate.call(this, opts, cb);
18932
+ this.v = opts && opts.dictionary ? 2 : 1;
18933
+ }
18934
+ Unzlib2.prototype.push = function(chunk, final) {
18935
+ Inflate.prototype.e.call(this, chunk);
18936
+ if (this.v) {
18937
+ if (this.p.length < 6 && !final)
18938
+ return;
18939
+ this.p = this.p.subarray(zls(this.p, this.v - 1)), this.v = 0;
18940
+ }
18941
+ if (final) {
18942
+ if (this.p.length < 4)
18943
+ err(6, "invalid zlib data");
18944
+ this.p = this.p.subarray(0, -4);
18945
+ }
18946
+ Inflate.prototype.c.call(this, final);
18947
+ };
18948
+ return Unzlib2;
18949
+ })();
18950
+ exports2.Unzlib = Unzlib;
18951
+ var AsyncUnzlib = /* @__PURE__ */ (function() {
18952
+ function AsyncUnzlib2(opts, cb) {
18953
+ astrmify([
18954
+ bInflt,
18955
+ zule,
18956
+ function() {
18957
+ return [astrm, Inflate, Unzlib];
18958
+ }
18959
+ ], this, StrmOpt.call(this, opts, cb), function(ev) {
18960
+ var strm = new Unzlib(ev.data);
18961
+ onmessage = astrm(strm);
18962
+ }, 11, 0);
18963
+ }
18964
+ return AsyncUnzlib2;
18965
+ })();
18966
+ exports2.AsyncUnzlib = AsyncUnzlib;
18967
+ function unzlib(data, opts, cb) {
18968
+ if (!cb)
18969
+ cb = opts, opts = {};
18970
+ if (typeof cb != "function")
18971
+ err(7);
18972
+ return cbify(data, opts, [
18973
+ bInflt,
18974
+ zule,
18975
+ function() {
18976
+ return [unzlibSync];
18977
+ }
18978
+ ], function(ev) {
18979
+ return pbf(unzlibSync(ev.data[0], gopt(ev.data[1])));
18980
+ }, 5, cb);
18981
+ }
18982
+ function unzlibSync(data, opts) {
18983
+ return inflt(data.subarray(zls(data, opts && opts.dictionary), -4), { i: 2 }, opts && opts.out, opts && opts.dictionary);
18984
+ }
18985
+ var Decompress = /* @__PURE__ */ (function() {
18986
+ function Decompress2(opts, cb) {
18987
+ this.o = StrmOpt.call(this, opts, cb) || {};
18988
+ this.G = Gunzip;
18989
+ this.I = Inflate;
18990
+ this.Z = Unzlib;
18991
+ }
18992
+ Decompress2.prototype.i = function() {
18993
+ var _this = this;
18994
+ this.s.ondata = function(dat, final) {
18995
+ _this.ondata(dat, final);
18996
+ };
18997
+ };
18998
+ Decompress2.prototype.push = function(chunk, final) {
18999
+ if (!this.ondata)
19000
+ err(5);
19001
+ if (!this.s) {
19002
+ if (this.p && this.p.length) {
19003
+ var n = new u8(this.p.length + chunk.length);
19004
+ n.set(this.p), n.set(chunk, this.p.length);
19005
+ } else
19006
+ this.p = chunk;
19007
+ if (this.p.length > 2) {
19008
+ this.s = this.p[0] == 31 && this.p[1] == 139 && this.p[2] == 8 ? new this.G(this.o) : (this.p[0] & 15) != 8 || this.p[0] >> 4 > 7 || (this.p[0] << 8 | this.p[1]) % 31 ? new this.I(this.o) : new this.Z(this.o);
19009
+ this.i();
19010
+ this.s.push(this.p, final);
19011
+ this.p = null;
19012
+ }
19013
+ } else
19014
+ this.s.push(chunk, final);
19015
+ };
19016
+ return Decompress2;
19017
+ })();
19018
+ exports2.Decompress = Decompress;
19019
+ var AsyncDecompress = /* @__PURE__ */ (function() {
19020
+ function AsyncDecompress2(opts, cb) {
19021
+ Decompress.call(this, opts, cb);
19022
+ this.queuedSize = 0;
19023
+ this.G = AsyncGunzip;
19024
+ this.I = AsyncInflate;
19025
+ this.Z = AsyncUnzlib;
19026
+ }
19027
+ AsyncDecompress2.prototype.i = function() {
19028
+ var _this = this;
19029
+ this.s.ondata = function(err2, dat, final) {
19030
+ _this.ondata(err2, dat, final);
19031
+ };
19032
+ this.s.ondrain = function(size) {
19033
+ _this.queuedSize -= size;
19034
+ if (_this.ondrain)
19035
+ _this.ondrain(size);
19036
+ };
19037
+ };
19038
+ AsyncDecompress2.prototype.push = function(chunk, final) {
19039
+ this.queuedSize += chunk.length;
19040
+ Decompress.prototype.push.call(this, chunk, final);
19041
+ };
19042
+ return AsyncDecompress2;
19043
+ })();
19044
+ exports2.AsyncDecompress = AsyncDecompress;
19045
+ function decompress(data, opts, cb) {
19046
+ if (!cb)
19047
+ cb = opts, opts = {};
19048
+ if (typeof cb != "function")
19049
+ err(7);
19050
+ return data[0] == 31 && data[1] == 139 && data[2] == 8 ? gunzip(data, opts, cb) : (data[0] & 15) != 8 || data[0] >> 4 > 7 || (data[0] << 8 | data[1]) % 31 ? inflate(data, opts, cb) : unzlib(data, opts, cb);
19051
+ }
19052
+ function decompressSync(data, opts) {
19053
+ return data[0] == 31 && data[1] == 139 && data[2] == 8 ? gunzipSync(data, opts) : (data[0] & 15) != 8 || data[0] >> 4 > 7 || (data[0] << 8 | data[1]) % 31 ? inflateSync(data, opts) : unzlibSync(data, opts);
19054
+ }
19055
+ var fltn = function(d, p, t, o) {
19056
+ for (var k in d) {
19057
+ var val = d[k], n = p + k, op = o;
19058
+ if (Array.isArray(val))
19059
+ op = mrg(o, val[1]), val = val[0];
19060
+ if (ArrayBuffer.isView(val))
19061
+ t[n] = [val, op];
19062
+ else {
19063
+ t[n += "/"] = [new u8(0), op];
19064
+ fltn(val, n, t, o);
19065
+ }
19066
+ }
19067
+ };
19068
+ var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder();
19069
+ var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder();
19070
+ var tds = 0;
19071
+ try {
19072
+ td.decode(et, { stream: true });
19073
+ tds = 1;
19074
+ } catch (e) {
19075
+ }
19076
+ var dutf8 = function(d) {
19077
+ for (var r = "", i2 = 0; ; ) {
19078
+ var c = d[i2++];
19079
+ var eb = (c > 127) + (c > 223) + (c > 239);
19080
+ if (i2 + eb > d.length)
19081
+ return { s: r, r: slc(d, i2 - 1) };
19082
+ if (!eb)
19083
+ r += String.fromCharCode(c);
19084
+ else if (eb == 3) {
19085
+ c = ((c & 15) << 18 | (d[i2++] & 63) << 12 | (d[i2++] & 63) << 6 | d[i2++] & 63) - 65536, r += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023);
19086
+ } else if (eb & 1)
19087
+ r += String.fromCharCode((c & 31) << 6 | d[i2++] & 63);
19088
+ else
19089
+ r += String.fromCharCode((c & 15) << 12 | (d[i2++] & 63) << 6 | d[i2++] & 63);
19090
+ }
19091
+ };
19092
+ var DecodeUTF8 = /* @__PURE__ */ (function() {
19093
+ function DecodeUTF82(cb) {
19094
+ this.ondata = cb;
19095
+ if (tds)
19096
+ this.t = new TextDecoder();
19097
+ else
19098
+ this.p = et;
19099
+ }
19100
+ DecodeUTF82.prototype.push = function(chunk, final) {
19101
+ if (!this.ondata)
19102
+ err(5);
19103
+ final = !!final;
19104
+ if (this.t) {
19105
+ this.ondata(this.t.decode(chunk, { stream: true }), final);
19106
+ if (final) {
19107
+ if (this.t.decode().length)
19108
+ err(8);
19109
+ this.t = null;
19110
+ }
19111
+ return;
19112
+ }
19113
+ if (!this.p)
19114
+ err(4);
19115
+ var dat = new u8(this.p.length + chunk.length);
19116
+ dat.set(this.p);
19117
+ dat.set(chunk, this.p.length);
19118
+ var _a2 = dutf8(dat), s = _a2.s, r = _a2.r;
19119
+ if (final) {
19120
+ if (r.length)
19121
+ err(8);
19122
+ this.p = null;
19123
+ } else
19124
+ this.p = r;
19125
+ this.ondata(s, final);
19126
+ };
19127
+ return DecodeUTF82;
19128
+ })();
19129
+ exports2.DecodeUTF8 = DecodeUTF8;
19130
+ var EncodeUTF8 = /* @__PURE__ */ (function() {
19131
+ function EncodeUTF82(cb) {
19132
+ this.ondata = cb;
19133
+ }
19134
+ EncodeUTF82.prototype.push = function(chunk, final) {
19135
+ if (!this.ondata)
19136
+ err(5);
19137
+ if (this.d)
19138
+ err(4);
19139
+ this.ondata(strToU8(chunk), this.d = final || false);
19140
+ };
19141
+ return EncodeUTF82;
19142
+ })();
19143
+ exports2.EncodeUTF8 = EncodeUTF8;
19144
+ function strToU8(str, latin1) {
19145
+ if (latin1) {
19146
+ var ar_1 = new u8(str.length);
19147
+ for (var i2 = 0; i2 < str.length; ++i2)
19148
+ ar_1[i2] = str.charCodeAt(i2);
19149
+ return ar_1;
19150
+ }
19151
+ if (te)
19152
+ return te.encode(str);
19153
+ var l = str.length;
19154
+ var ar = new u8(str.length + (str.length >> 1));
19155
+ var ai = 0;
19156
+ var w = function(v) {
19157
+ ar[ai++] = v;
19158
+ };
19159
+ for (var i2 = 0; i2 < l; ++i2) {
19160
+ if (ai + 5 > ar.length) {
19161
+ var n = new u8(ai + 8 + (l - i2 << 1));
19162
+ n.set(ar);
19163
+ ar = n;
19164
+ }
19165
+ var c = str.charCodeAt(i2);
19166
+ if (c < 128 || latin1)
19167
+ w(c);
19168
+ else if (c < 2048)
19169
+ w(192 | c >> 6), w(128 | c & 63);
19170
+ else if (c > 55295 && c < 57344)
19171
+ c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i2) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);
19172
+ else
19173
+ w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
19174
+ }
19175
+ return slc(ar, 0, ai);
19176
+ }
19177
+ function strFromU8(dat, latin1) {
19178
+ if (latin1) {
19179
+ var r = "";
19180
+ for (var i2 = 0; i2 < dat.length; i2 += 16384)
19181
+ r += String.fromCharCode.apply(null, dat.subarray(i2, i2 + 16384));
19182
+ return r;
19183
+ } else if (td) {
19184
+ return td.decode(dat);
19185
+ } else {
19186
+ var _a2 = dutf8(dat), s = _a2.s, r = _a2.r;
19187
+ if (r.length)
19188
+ err(8);
19189
+ return s;
19190
+ }
19191
+ }
19192
+ var dbf = function(l) {
19193
+ return l == 1 ? 3 : l < 6 ? 2 : l == 9 ? 1 : 0;
19194
+ };
19195
+ var slzh = function(d, b) {
19196
+ return b + 30 + b2(d, b + 26) + b2(d, b + 28);
19197
+ };
19198
+ var zh = function(d, b, z9) {
19199
+ var fnl = b2(d, b + 28), efl = b2(d, b + 30), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl;
19200
+ var _a2 = z64hs(d, es, efl, z9, b4(d, b + 20), b4(d, b + 24), b4(d, b + 42)), sc = _a2[0], su = _a2[1], off = _a2[2];
19201
+ return [b2(d, b + 10), sc, su, fn, es + efl + b2(d, b + 32), off];
19202
+ };
19203
+ var z64hs = function(d, b, l, z9, sc, su, off) {
19204
+ var nsc = sc == 4294967295, nsu = su == 4294967295, noff = off == 4294967295, e = b + l;
19205
+ var nf = nsc + nsu + noff;
19206
+ if (z9 && nf) {
19207
+ for (; b + 4 < e; b += 4 + b2(d, b + 2)) {
19208
+ if (b2(d, b) == 1) {
19209
+ return [
19210
+ nsc ? b8(d, b + 4 + 8 * nsu) : sc,
19211
+ nsu ? b8(d, b + 4) : su,
19212
+ noff ? b8(d, b + 4 + 8 * (nsu + nsc)) : off,
19213
+ 1
19214
+ ];
19215
+ }
19216
+ }
19217
+ if (z9 < 2)
19218
+ err(13);
19219
+ }
19220
+ return [sc, su, off, 0];
19221
+ };
19222
+ var exfl = function(ex) {
19223
+ var le = 0;
19224
+ if (ex) {
19225
+ for (var k in ex) {
19226
+ var l = ex[k].length;
19227
+ if (l > 65535)
19228
+ err(9);
19229
+ le += l + 4;
19230
+ }
19231
+ }
19232
+ return le;
19233
+ };
19234
+ var wzh = function(d, b, f, fn, u, c, ce, co) {
19235
+ var fl2 = fn.length, ex = f.extra, col = co && co.length;
19236
+ var exl = exfl(ex);
19237
+ wbytes(d, b, ce != null ? 33639248 : 67324752), b += 4;
19238
+ if (ce != null)
19239
+ d[b++] = 20, d[b++] = f.os;
19240
+ d[b] = 20, b += 2;
19241
+ d[b++] = f.flag << 1 | (c < 0 && 8), d[b++] = u && 8;
19242
+ d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
19243
+ var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
19244
+ if (y < 0 || y > 119)
19245
+ err(10);
19246
+ wbytes(d, b, y << 25 | dt.getMonth() + 1 << 21 | dt.getDate() << 16 | dt.getHours() << 11 | dt.getMinutes() << 5 | dt.getSeconds() >> 1), b += 4;
19247
+ if (c != -1) {
19248
+ wbytes(d, b, f.crc);
19249
+ wbytes(d, b + 4, c < 0 ? -c - 2 : c);
19250
+ wbytes(d, b + 8, f.size);
19251
+ }
19252
+ wbytes(d, b + 12, fl2);
19253
+ wbytes(d, b + 14, exl), b += 16;
19254
+ if (ce != null) {
19255
+ wbytes(d, b, col);
19256
+ wbytes(d, b + 6, f.attrs);
19257
+ wbytes(d, b + 10, ce), b += 14;
19258
+ }
19259
+ d.set(fn, b);
19260
+ b += fl2;
19261
+ if (exl) {
19262
+ for (var k in ex) {
19263
+ var exf = ex[k], l = exf.length;
19264
+ wbytes(d, b, +k);
19265
+ wbytes(d, b + 2, l);
19266
+ d.set(exf, b + 4), b += 4 + l;
19267
+ }
19268
+ }
19269
+ if (col)
19270
+ d.set(co, b), b += col;
19271
+ return b;
19272
+ };
19273
+ var wzf = function(o, b, c, d, e) {
19274
+ wbytes(o, b, 101010256);
19275
+ wbytes(o, b + 8, c);
19276
+ wbytes(o, b + 10, c);
19277
+ wbytes(o, b + 12, d);
19278
+ wbytes(o, b + 16, e);
19279
+ };
19280
+ var ZipPassThrough = /* @__PURE__ */ (function() {
19281
+ function ZipPassThrough2(filename) {
19282
+ this.filename = filename;
19283
+ this.c = crc();
19284
+ this.size = 0;
19285
+ this.compression = 0;
19286
+ }
19287
+ ZipPassThrough2.prototype.process = function(chunk, final) {
19288
+ this.ondata(null, chunk, final);
19289
+ };
19290
+ ZipPassThrough2.prototype.push = function(chunk, final) {
19291
+ if (!this.ondata)
19292
+ err(5);
19293
+ this.c.p(chunk);
19294
+ this.size += chunk.length;
19295
+ if (final)
19296
+ this.crc = this.c.d();
19297
+ this.process(chunk, final || false);
19298
+ };
19299
+ return ZipPassThrough2;
19300
+ })();
19301
+ exports2.ZipPassThrough = ZipPassThrough;
19302
+ var ZipDeflate = /* @__PURE__ */ (function() {
19303
+ function ZipDeflate2(filename, opts) {
19304
+ var _this = this;
19305
+ if (!opts)
19306
+ opts = {};
19307
+ ZipPassThrough.call(this, filename);
19308
+ this.d = new Deflate(opts, function(dat, final) {
19309
+ _this.ondata(null, dat, final);
19310
+ });
19311
+ this.compression = 8;
19312
+ this.flag = dbf(opts.level);
19313
+ }
19314
+ ZipDeflate2.prototype.process = function(chunk, final) {
19315
+ try {
19316
+ this.d.push(chunk, final);
19317
+ } catch (e) {
19318
+ this.ondata(e, null, final);
19319
+ }
19320
+ };
19321
+ ZipDeflate2.prototype.push = function(chunk, final) {
19322
+ ZipPassThrough.prototype.push.call(this, chunk, final);
19323
+ };
19324
+ return ZipDeflate2;
19325
+ })();
19326
+ exports2.ZipDeflate = ZipDeflate;
19327
+ var AsyncZipDeflate = /* @__PURE__ */ (function() {
19328
+ function AsyncZipDeflate2(filename, opts) {
19329
+ var _this = this;
19330
+ if (!opts)
19331
+ opts = {};
19332
+ ZipPassThrough.call(this, filename);
19333
+ this.d = new AsyncDeflate(opts, function(err2, dat, final) {
19334
+ _this.ondata(err2, dat, final);
19335
+ });
19336
+ this.compression = 8;
19337
+ this.flag = dbf(opts.level);
19338
+ this.terminate = this.d.terminate;
19339
+ }
19340
+ AsyncZipDeflate2.prototype.process = function(chunk, final) {
19341
+ this.d.push(chunk, final);
19342
+ };
19343
+ AsyncZipDeflate2.prototype.push = function(chunk, final) {
19344
+ ZipPassThrough.prototype.push.call(this, chunk, final);
19345
+ };
19346
+ return AsyncZipDeflate2;
19347
+ })();
19348
+ exports2.AsyncZipDeflate = AsyncZipDeflate;
19349
+ var Zip = /* @__PURE__ */ (function() {
19350
+ function Zip2(cb) {
19351
+ this.ondata = cb;
19352
+ this.u = [];
19353
+ this.d = 1;
19354
+ }
19355
+ Zip2.prototype.add = function(file) {
19356
+ var _this = this;
19357
+ if (!this.ondata)
19358
+ err(5);
19359
+ if (this.d & 2)
19360
+ this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, false);
19361
+ else {
19362
+ var f = strToU8(file.filename), fl_1 = f.length;
19363
+ var com = file.comment, o = com && strToU8(com);
19364
+ var u = fl_1 != file.filename.length || o && com.length != o.length;
19365
+ var hl_1 = fl_1 + exfl(file.extra) + 30;
19366
+ if (fl_1 > 65535)
19367
+ this.ondata(err(11, 0, 1), null, false);
19368
+ var header = new u8(hl_1);
19369
+ wzh(header, 0, file, f, u, -1);
19370
+ var chks_1 = [header];
19371
+ var pAll_1 = function() {
19372
+ for (var _i = 0, chks_2 = chks_1; _i < chks_2.length; _i++) {
19373
+ var chk = chks_2[_i];
19374
+ _this.ondata(null, chk, false);
19375
+ }
19376
+ chks_1 = [];
19377
+ };
19378
+ var tr_1 = this.d;
19379
+ this.d = 0;
19380
+ var ind_1 = this.u.length;
19381
+ var uf_1 = mrg(file, {
19382
+ f,
19383
+ u,
19384
+ o,
19385
+ t: function() {
19386
+ if (file.terminate)
19387
+ file.terminate();
19388
+ },
19389
+ r: function() {
19390
+ pAll_1();
19391
+ if (tr_1) {
19392
+ var nxt = _this.u[ind_1 + 1];
19393
+ if (nxt)
19394
+ nxt.r();
19395
+ else
19396
+ _this.d = 1;
19397
+ }
19398
+ tr_1 = 1;
19399
+ }
19400
+ });
19401
+ var cl_1 = 0;
19402
+ file.ondata = function(err2, dat, final) {
19403
+ if (err2) {
19404
+ _this.ondata(err2, dat, final);
19405
+ _this.terminate();
19406
+ } else {
19407
+ cl_1 += dat.length;
19408
+ chks_1.push(dat);
19409
+ if (final) {
19410
+ var dd = new u8(16);
19411
+ wbytes(dd, 0, 134695760);
19412
+ wbytes(dd, 4, file.crc);
19413
+ wbytes(dd, 8, cl_1);
19414
+ wbytes(dd, 12, file.size);
19415
+ chks_1.push(dd);
19416
+ uf_1.c = cl_1, uf_1.b = hl_1 + cl_1 + 16, uf_1.crc = file.crc, uf_1.size = file.size;
19417
+ if (tr_1)
19418
+ uf_1.r();
19419
+ tr_1 = 1;
19420
+ } else if (tr_1)
19421
+ pAll_1();
19422
+ }
19423
+ };
19424
+ this.u.push(uf_1);
19425
+ }
19426
+ };
19427
+ Zip2.prototype.end = function() {
19428
+ var _this = this;
19429
+ if (this.d & 2) {
19430
+ this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, true);
19431
+ return;
19432
+ }
19433
+ if (this.d)
19434
+ this.e();
19435
+ else
19436
+ this.u.push({
19437
+ r: function() {
19438
+ if (!(_this.d & 1))
19439
+ return;
19440
+ _this.u.splice(-1, 1);
19441
+ _this.e();
19442
+ },
19443
+ t: function() {
19444
+ }
19445
+ });
19446
+ this.d = 3;
19447
+ };
19448
+ Zip2.prototype.e = function() {
19449
+ var bt = 0, l = 0, tl = 0;
19450
+ for (var _i = 0, _a2 = this.u; _i < _a2.length; _i++) {
19451
+ var f = _a2[_i];
19452
+ tl += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0);
19453
+ }
19454
+ var out = new u8(tl + 22);
19455
+ for (var _b2 = 0, _c = this.u; _b2 < _c.length; _b2++) {
19456
+ var f = _c[_b2];
19457
+ wzh(out, bt, f, f.f, f.u, -f.c - 2, l, f.o);
19458
+ bt += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0), l += f.b;
19459
+ }
19460
+ wzf(out, bt, this.u.length, tl, l);
19461
+ this.ondata(null, out, true);
19462
+ this.d = 2;
19463
+ };
19464
+ Zip2.prototype.terminate = function() {
19465
+ for (var _i = 0, _a2 = this.u; _i < _a2.length; _i++) {
19466
+ var f = _a2[_i];
19467
+ f.t();
19468
+ }
19469
+ this.d = 2;
19470
+ };
19471
+ return Zip2;
19472
+ })();
19473
+ exports2.Zip = Zip;
19474
+ function zip(data, opts, cb) {
19475
+ if (!cb)
19476
+ cb = opts, opts = {};
19477
+ if (typeof cb != "function")
19478
+ err(7);
19479
+ var r = {};
19480
+ fltn(data, "", r, opts);
19481
+ var k = Object.keys(r);
19482
+ var lft = k.length, o = 0, tot = 0;
19483
+ var slft = lft, files = new Array(lft);
19484
+ var term = [];
19485
+ var tAll = function() {
19486
+ for (var i3 = 0; i3 < term.length; ++i3)
19487
+ term[i3]();
19488
+ };
19489
+ var cbd = function(a, b) {
19490
+ mt(function() {
19491
+ cb(a, b);
19492
+ });
19493
+ };
19494
+ mt(function() {
19495
+ cbd = cb;
19496
+ });
19497
+ var cbf = function() {
19498
+ var out = new u8(tot + 22), oe = o, cdl = tot - o;
19499
+ tot = 0;
19500
+ for (var i3 = 0; i3 < slft; ++i3) {
19501
+ var f = files[i3];
19502
+ try {
19503
+ var l = f.c.length;
19504
+ wzh(out, tot, f, f.f, f.u, l);
19505
+ var badd = 30 + f.f.length + exfl(f.extra);
19506
+ var loc = tot + badd;
19507
+ out.set(f.c, loc);
19508
+ wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l;
19509
+ } catch (e) {
19510
+ return cbd(e, null);
19511
+ }
19512
+ }
19513
+ wzf(out, o, files.length, cdl, oe);
19514
+ cbd(null, out);
19515
+ };
19516
+ if (!lft)
19517
+ cbf();
19518
+ var _loop_1 = function(i3) {
19519
+ var fn = k[i3];
19520
+ var _a2 = r[fn], file = _a2[0], p = _a2[1];
19521
+ var c = crc(), size = file.length;
19522
+ c.p(file);
19523
+ var f = strToU8(fn), s = f.length;
19524
+ var com = p.comment, m = com && strToU8(com), ms = m && m.length;
19525
+ var exl = exfl(p.extra);
19526
+ var compression = p.level == 0 ? 0 : 8;
19527
+ var cbl = function(e, d) {
19528
+ if (e) {
19529
+ tAll();
19530
+ cbd(e, null);
19531
+ } else {
19532
+ var l = d.length;
19533
+ files[i3] = mrg(p, {
19534
+ size,
19535
+ crc: c.d(),
19536
+ c: d,
19537
+ f,
19538
+ m,
19539
+ u: s != fn.length || m && com.length != ms,
19540
+ compression
19541
+ });
19542
+ o += 30 + s + exl + l;
19543
+ tot += 76 + 2 * (s + exl) + (ms || 0) + l;
19544
+ if (!--lft)
19545
+ cbf();
19546
+ }
19547
+ };
19548
+ if (s > 65535)
19549
+ cbl(err(11, 0, 1), null);
19550
+ if (!compression)
19551
+ cbl(null, file);
19552
+ else if (size < 16e4) {
19553
+ try {
19554
+ cbl(null, deflateSync(file, p));
19555
+ } catch (e) {
19556
+ cbl(e, null);
19557
+ }
19558
+ } else
19559
+ term.push(deflate(file, p, cbl));
19560
+ };
19561
+ for (var i2 = 0; i2 < slft; ++i2) {
19562
+ _loop_1(i2);
19563
+ }
19564
+ return tAll;
19565
+ }
19566
+ function zipSync(data, opts) {
19567
+ if (!opts)
19568
+ opts = {};
19569
+ var r = {};
19570
+ var files = [];
19571
+ fltn(data, "", r, opts);
19572
+ var o = 0;
19573
+ var tot = 0;
19574
+ for (var fn in r) {
19575
+ var _a2 = r[fn], file = _a2[0], p = _a2[1];
19576
+ var compression = p.level == 0 ? 0 : 8;
19577
+ var f = strToU8(fn), s = f.length;
19578
+ var com = p.comment, m = com && strToU8(com), ms = m && m.length;
19579
+ var exl = exfl(p.extra);
19580
+ if (s > 65535)
19581
+ err(11);
19582
+ var d = compression ? deflateSync(file, p) : file, l = d.length;
19583
+ var c = crc();
19584
+ c.p(file);
19585
+ files.push(mrg(p, {
19586
+ size: file.length,
19587
+ crc: c.d(),
19588
+ c: d,
19589
+ f,
19590
+ m,
19591
+ u: s != fn.length || m && com.length != ms,
19592
+ o,
19593
+ compression
19594
+ }));
19595
+ o += 30 + s + exl + l;
19596
+ tot += 76 + 2 * (s + exl) + (ms || 0) + l;
19597
+ }
19598
+ var out = new u8(tot + 22), oe = o, cdl = tot - o;
19599
+ for (var i2 = 0; i2 < files.length; ++i2) {
19600
+ var f = files[i2];
19601
+ wzh(out, f.o, f, f.f, f.u, f.c.length);
19602
+ var badd = 30 + f.f.length + exfl(f.extra);
19603
+ out.set(f.c, f.o + badd);
19604
+ wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
19605
+ }
19606
+ wzf(out, o, files.length, cdl, oe);
19607
+ return out;
19608
+ }
19609
+ var UnzipPassThrough = /* @__PURE__ */ (function() {
19610
+ function UnzipPassThrough2() {
19611
+ }
19612
+ UnzipPassThrough2.prototype.push = function(chunk, final) {
19613
+ this.ondata(null, chunk, final);
19614
+ };
19615
+ UnzipPassThrough2.compression = 0;
19616
+ return UnzipPassThrough2;
19617
+ })();
19618
+ exports2.UnzipPassThrough = UnzipPassThrough;
19619
+ var UnzipInflate = /* @__PURE__ */ (function() {
19620
+ function UnzipInflate2() {
19621
+ var _this = this;
19622
+ this.i = new Inflate(function(dat, final) {
19623
+ _this.ondata(null, dat, final);
19624
+ });
19625
+ }
19626
+ UnzipInflate2.prototype.push = function(chunk, final) {
19627
+ try {
19628
+ this.i.push(chunk, final);
19629
+ } catch (e) {
19630
+ this.ondata(e, null, final);
19631
+ }
19632
+ };
19633
+ UnzipInflate2.compression = 8;
19634
+ return UnzipInflate2;
19635
+ })();
19636
+ exports2.UnzipInflate = UnzipInflate;
19637
+ var AsyncUnzipInflate = /* @__PURE__ */ (function() {
19638
+ function AsyncUnzipInflate2(_, sz) {
19639
+ var _this = this;
19640
+ if (sz < 32e4) {
19641
+ this.i = new Inflate(function(dat, final) {
19642
+ _this.ondata(null, dat, final);
19643
+ });
19644
+ } else {
19645
+ this.i = new AsyncInflate(function(err2, dat, final) {
19646
+ _this.ondata(err2, dat, final);
19647
+ });
19648
+ this.terminate = this.i.terminate;
19649
+ }
19650
+ }
19651
+ AsyncUnzipInflate2.prototype.push = function(chunk, final) {
19652
+ if (this.i.terminate)
19653
+ chunk = slc(chunk, 0);
19654
+ this.i.push(chunk, final);
19655
+ };
19656
+ AsyncUnzipInflate2.compression = 8;
19657
+ return AsyncUnzipInflate2;
19658
+ })();
19659
+ exports2.AsyncUnzipInflate = AsyncUnzipInflate;
19660
+ var Unzip = /* @__PURE__ */ (function() {
19661
+ function Unzip2(cb) {
19662
+ this.onfile = cb;
19663
+ this.k = [];
19664
+ this.o = {
19665
+ 0: UnzipPassThrough
19666
+ };
19667
+ this.p = et;
19668
+ }
19669
+ Unzip2.prototype.push = function(chunk, final) {
19670
+ var _this = this;
19671
+ if (!this.onfile)
19672
+ err(5);
19673
+ if (!this.p)
19674
+ err(4);
19675
+ if (this.c > 0) {
19676
+ var len = Math.min(this.c, chunk.length);
19677
+ var toAdd = chunk.subarray(0, len);
19678
+ this.c -= len;
19679
+ if (this.d)
19680
+ this.d.push(toAdd, !this.c);
19681
+ else
19682
+ this.k[0].push(toAdd);
19683
+ chunk = chunk.subarray(len);
19684
+ if (chunk.length)
19685
+ return this.push(chunk, final);
19686
+ } else {
19687
+ var f = 0, i2 = 0, is = void 0, buf = void 0;
19688
+ if (!this.p.length)
19689
+ buf = chunk;
19690
+ else if (!chunk.length)
19691
+ buf = this.p;
19692
+ else {
19693
+ buf = new u8(this.p.length + chunk.length);
19694
+ buf.set(this.p), buf.set(chunk, this.p.length);
19695
+ }
19696
+ var l = buf.length, oc = this.c, add = oc && this.d;
19697
+ var _loop_2 = function() {
19698
+ var sig = b4(buf, i2);
19699
+ if (sig == 67324752) {
19700
+ f = 1, is = i2;
19701
+ this_1.d = null;
19702
+ this_1.c = 0;
19703
+ var bf = b2(buf, i2 + 6), cmp_1 = b2(buf, i2 + 8), u = bf & 2048, dd = bf & 8, fnl = b2(buf, i2 + 26), es = b2(buf, i2 + 28);
19704
+ if (l > i2 + 30 + fnl + es) {
19705
+ var chks_3 = [];
19706
+ this_1.k.unshift(chks_3);
19707
+ f = 2;
19708
+ var lsc = b4(buf, i2 + 18), lsu = b4(buf, i2 + 22);
19709
+ var fn_1 = strFromU8(buf.subarray(i2 + 30, i2 += 30 + fnl), !u);
19710
+ var _a2 = z64hs(buf, i2, es, 2, lsc, lsu, 0), sc_1 = _a2[0], su_1 = _a2[1], z64 = _a2[3];
19711
+ if (dd)
19712
+ sc_1 = -1 - z64;
19713
+ i2 += es;
19714
+ this_1.c = sc_1;
19715
+ var d_1;
19716
+ var file_1 = {
19717
+ name: fn_1,
19718
+ compression: cmp_1,
19719
+ start: function() {
19720
+ if (!file_1.ondata)
19721
+ err(5);
19722
+ if (!sc_1)
19723
+ file_1.ondata(null, et, true);
19724
+ else {
19725
+ var ctr = _this.o[cmp_1];
19726
+ if (!ctr)
19727
+ file_1.ondata(err(14, "unknown compression type " + cmp_1, 1), null, false);
19728
+ d_1 = sc_1 < 0 ? new ctr(fn_1) : new ctr(fn_1, sc_1, su_1);
19729
+ d_1.ondata = function(err2, dat3, final2) {
19730
+ file_1.ondata(err2, dat3, final2);
19731
+ };
19732
+ for (var _i = 0, chks_4 = chks_3; _i < chks_4.length; _i++) {
19733
+ var dat2 = chks_4[_i];
19734
+ d_1.push(dat2, false);
19735
+ }
19736
+ if (_this.k[0] == chks_3 && _this.c)
19737
+ _this.d = d_1;
19738
+ else
19739
+ d_1.push(et, true);
19740
+ }
19741
+ },
19742
+ terminate: function() {
19743
+ if (d_1 && d_1.terminate)
19744
+ d_1.terminate();
19745
+ }
19746
+ };
19747
+ if (sc_1 >= 0)
19748
+ file_1.size = sc_1, file_1.originalSize = su_1;
19749
+ this_1.onfile(file_1);
19750
+ }
19751
+ return "break";
19752
+ } else if (oc) {
19753
+ if (sig == 134695760) {
19754
+ is = i2 += 12 + (oc == -2 && 8), f = 3, this_1.c = 0;
19755
+ return "break";
19756
+ } else if (sig == 33639248) {
19757
+ is = i2 -= 4, f = 3, this_1.c = 0;
19758
+ return "break";
19759
+ }
19760
+ }
19761
+ };
19762
+ var this_1 = this;
19763
+ for (; i2 < l - 4; ++i2) {
19764
+ var state_1 = _loop_2();
19765
+ if (state_1 === "break")
19766
+ break;
19767
+ }
19768
+ this.p = et;
19769
+ if (oc < 0) {
19770
+ var dat = f ? buf.subarray(0, is - 12 - (oc == -2 && 8) - (b4(buf, is - 16) == 134695760 && 4)) : buf.subarray(0, i2);
19771
+ if (add)
19772
+ add.push(dat, !!f);
19773
+ else
19774
+ this.k[+(f == 2)].push(dat);
19775
+ }
19776
+ if (f & 2)
19777
+ return this.push(buf.subarray(i2), final);
19778
+ this.p = buf.subarray(i2);
19779
+ }
19780
+ if (final) {
19781
+ if (this.c)
19782
+ err(13);
19783
+ this.p = null;
19784
+ }
19785
+ };
19786
+ Unzip2.prototype.register = function(decoder) {
19787
+ this.o[decoder.compression] = decoder;
19788
+ };
19789
+ return Unzip2;
19790
+ })();
19791
+ exports2.Unzip = Unzip;
19792
+ var mt = typeof queueMicrotask == "function" ? queueMicrotask : typeof setTimeout == "function" ? setTimeout : function(fn) {
19793
+ fn();
19794
+ };
19795
+ function unzip(data, opts, cb) {
19796
+ if (!cb)
19797
+ cb = opts, opts = {};
19798
+ if (typeof cb != "function")
19799
+ err(7);
19800
+ var term = [];
19801
+ var tAll = function() {
19802
+ for (var i3 = 0; i3 < term.length; ++i3)
19803
+ term[i3]();
19804
+ };
19805
+ var files = {};
19806
+ var cbd = function(a, b) {
19807
+ mt(function() {
19808
+ cb(a, b);
19809
+ });
19810
+ };
19811
+ mt(function() {
19812
+ cbd = cb;
19813
+ });
19814
+ var e = data.length - 22;
19815
+ for (; b4(data, e) != 101010256; --e) {
19816
+ if (!e || data.length - e > 65558) {
19817
+ cbd(err(13, 0, 1), null);
19818
+ return tAll;
19819
+ }
19820
+ }
19821
+ ;
19822
+ var lft = b2(data, e + 8);
19823
+ if (lft) {
19824
+ var c = lft;
19825
+ var o = b4(data, e + 16);
19826
+ var z9 = b4(data, e - 20) == 117853008;
19827
+ if (z9) {
19828
+ var ze = b4(data, e - 12);
19829
+ z9 = b4(data, ze) == 101075792;
19830
+ if (z9) {
19831
+ c = lft = b4(data, ze + 32);
19832
+ o = b4(data, ze + 48);
19833
+ }
19834
+ }
19835
+ var fltr = opts && opts.filter;
19836
+ var _loop_3 = function(i3) {
19837
+ var _a2 = zh(data, o, z9), c_1 = _a2[0], sc = _a2[1], su = _a2[2], fn = _a2[3], no = _a2[4], off = _a2[5], b = slzh(data, off);
19838
+ o = no;
19839
+ var cbl = function(e2, d) {
19840
+ if (e2) {
19841
+ tAll();
19842
+ cbd(e2, null);
19843
+ } else {
19844
+ if (d)
19845
+ files[fn] = d;
19846
+ if (!--lft)
19847
+ cbd(null, files);
19848
+ }
19849
+ };
19850
+ if (!fltr || fltr({
19851
+ name: fn,
19852
+ size: sc,
19853
+ originalSize: su,
19854
+ compression: c_1
19855
+ })) {
19856
+ if (!c_1)
19857
+ cbl(null, slc(data, b, b + sc));
19858
+ else if (c_1 == 8) {
19859
+ var infl = data.subarray(b, b + sc);
19860
+ if (su < 524288 || sc > 0.8 * su) {
19861
+ try {
19862
+ cbl(null, inflateSync(infl, { out: new u8(su) }));
19863
+ } catch (e2) {
19864
+ cbl(e2, null);
19865
+ }
19866
+ } else
19867
+ term.push(inflate(infl, { size: su }, cbl));
19868
+ } else
19869
+ cbl(err(14, "unknown compression type " + c_1, 1), null);
19870
+ } else
19871
+ cbl(null, null);
19872
+ };
19873
+ for (var i2 = 0; i2 < c; ++i2) {
19874
+ _loop_3(i2);
19875
+ }
19876
+ } else
19877
+ cbd(null, {});
19878
+ return tAll;
19879
+ }
19880
+ function unzipSync(data, opts) {
19881
+ var files = {};
19882
+ var e = data.length - 22;
19883
+ for (; b4(data, e) != 101010256; --e) {
19884
+ if (!e || data.length - e > 65558)
19885
+ err(13);
19886
+ }
19887
+ ;
19888
+ var c = b2(data, e + 8);
19889
+ if (!c)
19890
+ return {};
19891
+ var o = b4(data, e + 16);
19892
+ var z9 = b4(data, e - 20) == 117853008;
19893
+ if (z9) {
19894
+ var ze = b4(data, e - 12);
19895
+ z9 = b4(data, ze) == 101075792;
19896
+ if (z9) {
19897
+ c = b4(data, ze + 32);
19898
+ o = b4(data, ze + 48);
19899
+ }
19900
+ }
19901
+ var fltr = opts && opts.filter;
19902
+ for (var i2 = 0; i2 < c; ++i2) {
19903
+ var _a2 = zh(data, o, z9), c_2 = _a2[0], sc = _a2[1], su = _a2[2], fn = _a2[3], no = _a2[4], off = _a2[5], b = slzh(data, off);
19904
+ o = no;
19905
+ if (!fltr || fltr({
19906
+ name: fn,
19907
+ size: sc,
19908
+ originalSize: su,
19909
+ compression: c_2
19910
+ })) {
19911
+ if (!c_2)
19912
+ files[fn] = slc(data, b, b + sc);
19913
+ else if (c_2 == 8)
19914
+ files[fn] = inflateSync(data.subarray(b, b + sc), { out: new u8(su) });
19915
+ else
19916
+ err(14, "unknown compression type " + c_2);
19917
+ }
19918
+ }
19919
+ return files;
19920
+ }
19921
+ }
19922
+ });
19923
+
19924
+ // sdk/dist/index.js
19925
+ var require_dist = __commonJS({
19926
+ "sdk/dist/index.js"(exports2, module2) {
19927
+ "use strict";
19928
+ var __create2 = Object.create;
19929
+ var __defProp2 = Object.defineProperty;
19930
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
19931
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
19932
+ var __getProtoOf2 = Object.getPrototypeOf;
19933
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
19934
+ var __commonJS2 = (cb, mod) => function __require() {
19935
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19936
+ };
19937
+ var __export2 = (target, all) => {
19938
+ for (var name in all)
19939
+ __defProp2(target, name, { get: all[name], enumerable: true });
19940
+ };
19941
+ var __copyProps2 = (to, from, except, desc) => {
19942
+ if (from && typeof from === "object" || typeof from === "function") {
19943
+ for (let key of __getOwnPropNames2(from))
19944
+ if (!__hasOwnProp2.call(to, key) && key !== except)
19945
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
19946
+ }
19947
+ return to;
19948
+ };
19949
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
19950
+ // If the importer is in node compatibility mode or this is not an ESM
19951
+ // file that has been converted to a CommonJS file using a Babel-
19952
+ // compatible transform (i.e. "__esModule" has not been set), then set
19953
+ // "default" to the CommonJS "module.exports" for node compatibility.
19954
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
19955
+ mod
19956
+ ));
19957
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
19958
+ var require_package = __commonJS2({
19959
+ "package.json"(exports22, module22) {
19960
+ module22.exports = {
19961
+ name: "@wairon/sdk",
19962
+ version: "0.0.0-dev",
19963
+ description: "Wairon pack-archive (.wpack) format authority and authoring toolkit \u2014 scaffold, build, inspect, and safely extract wairon extension packs.",
19964
+ keywords: [
19965
+ "wairon",
19966
+ "sdd",
19967
+ "pack",
19968
+ "wpack",
19969
+ "archive",
19970
+ "developer-tools"
19971
+ ],
19972
+ author: "SYW",
19973
+ license: "MIT",
19974
+ homepage: "https://github.com/SYW-Apps/Waffle-AIron",
19975
+ repository: {
19976
+ type: "git",
19977
+ url: "https://github.com/SYW-Apps/Waffle-AIron.git"
19978
+ },
19979
+ type: "commonjs",
19980
+ main: "./dist/index.js",
19981
+ types: "./dist/index.d.ts",
19982
+ files: [
19983
+ "dist",
19984
+ "README.md"
19985
+ ],
19986
+ engines: {
19987
+ node: ">=18.0.0"
19988
+ },
19989
+ scripts: {
19990
+ build: "tsup",
19991
+ typecheck: "tsc --noEmit",
19992
+ test: "vitest run",
19993
+ "test:watch": "vitest",
19994
+ clean: "rimraf dist"
19995
+ },
19996
+ dependencies: {
19997
+ fflate: "^0.8.2",
19998
+ "js-yaml": "^4.1.0"
19999
+ },
20000
+ devDependencies: {
20001
+ "@types/js-yaml": "^4.0.9",
20002
+ "@types/node": "^20.14.0",
20003
+ rimraf: "^5.0.7",
20004
+ tsup: "^8.1.0",
20005
+ typescript: "^5.5.2",
20006
+ vitest: "^4.1.9"
20007
+ }
20008
+ };
20009
+ }
20010
+ });
20011
+ var src_exports2 = {};
20012
+ __export2(src_exports2, {
20013
+ buildPack: () => buildPack2,
20014
+ buildTreeArchive: () => buildTreeArchive22,
20015
+ defineRule: () => defineRule,
20016
+ extractPack: () => extractPack2,
20017
+ extractTreeArchive: () => extractTreeArchive22,
20018
+ inspectArchive: () => inspectArchive2,
20019
+ inspectTreeArchive: () => inspectTreeArchive22,
20020
+ scaffoldPack: () => scaffoldPack2
20021
+ });
20022
+ module2.exports = __toCommonJS2(src_exports2);
20023
+ var path27 = __toESM2(require("path"));
20024
+ var import_js_yaml3 = require("js-yaml");
20025
+ var import_js_yaml = require("js-yaml");
20026
+ var import_crypto = require("crypto");
20027
+ var ENVELOPE_FILENAME = "wairon-pack.yaml";
20028
+ var SUPPORTED_FORMAT_VERSION = 1;
20029
+ var DEFAULTS = {
20030
+ maxEntries: 4096,
20031
+ maxTotalUncompressedBytes: 32 * 1024 * 1024,
20032
+ maxEntryBytes: 8 * 1024 * 1024,
20033
+ maxCompressionRatio: 100,
20034
+ maxDepth: 16
20035
+ };
20036
+ function parseManifest(text) {
20037
+ const raw = (0, import_js_yaml.load)(text);
20038
+ const manifest = validateEnvelope(raw);
20039
+ if (Math.trunc(manifest.formatVersion) > SUPPORTED_FORMAT_VERSION) {
20040
+ throw new Error("unsupported pack-archive formatVersion (newer than this wairon understands)");
20041
+ }
20042
+ return manifest;
20043
+ }
20044
+ function serializeManifest(manifest) {
20045
+ const clean = {
20046
+ formatVersion: manifest.formatVersion,
20047
+ name: manifest.name,
20048
+ version: manifest.version,
20049
+ kind: manifest.kind,
20050
+ entry: manifest.entry
20051
+ };
20052
+ if (manifest.minWaironVersion !== void 0) clean.minWaironVersion = manifest.minWaironVersion;
20053
+ if (manifest.digest !== void 0) clean.digest = manifest.digest;
20054
+ if (manifest.entryDigests !== void 0) clean.entryDigests = manifest.entryDigests;
20055
+ if (manifest.generatedBy !== void 0) clean.generatedBy = manifest.generatedBy;
20056
+ if (manifest.generatedAt !== void 0) clean.generatedAt = manifest.generatedAt;
20057
+ return (0, import_js_yaml.dump)(clean, { sortKeys: false });
20058
+ }
20059
+ function defaultLimits() {
20060
+ return { ...DEFAULTS };
20061
+ }
20062
+ function planExtraction(entries, limits) {
20063
+ const caps = {
20064
+ maxEntries: limits.maxEntries ?? DEFAULTS.maxEntries,
20065
+ maxTotalUncompressedBytes: limits.maxTotalUncompressedBytes ?? DEFAULTS.maxTotalUncompressedBytes,
20066
+ maxEntryBytes: limits.maxEntryBytes ?? DEFAULTS.maxEntryBytes,
20067
+ maxCompressionRatio: limits.maxCompressionRatio ?? DEFAULTS.maxCompressionRatio,
20068
+ maxDepth: limits.maxDepth ?? DEFAULTS.maxDepth
20069
+ };
20070
+ const approved = [];
20071
+ let total = 0;
20072
+ for (const entry of entries) {
20073
+ if (isSymlinkOrNonRegular(entry.kind) || isStructurallyUnsafePath(entry.path)) {
20074
+ rejectUnsafe();
20075
+ }
20076
+ if (entry.kind === "dir") continue;
20077
+ const normalized = normalizeRelPath(entry.path);
20078
+ if (escapesDestination(normalized) || pathDepth(normalized) > caps.maxDepth) {
20079
+ rejectUnsafe();
20080
+ }
20081
+ if (entry.uncompressedSize > caps.maxEntryBytes || compressionRatio(entry) > caps.maxCompressionRatio) {
20082
+ rejectUnsafe();
20083
+ }
20084
+ approved.push(normalized);
20085
+ total += entry.uncompressedSize;
20086
+ }
20087
+ if (approved.length > caps.maxEntries || total > caps.maxTotalUncompressedBytes) {
20088
+ rejectUnsafe();
20089
+ }
20090
+ return { paths: approved, totalUncompressedBytes: total };
20091
+ }
20092
+ function verifyIdentity(manifest, packName, packVersion) {
20093
+ if (manifest.name !== packName || manifest.version !== packVersion) {
20094
+ throw new Error("envelope identity mismatch (envelope name/version differ from the inner pack manifest)");
20095
+ }
20096
+ }
20097
+ function verifyIntegrity2(manifest, files) {
20098
+ if (!manifest.entryDigests) {
20099
+ return false;
20100
+ }
20101
+ const digests = manifest.entryDigests;
20102
+ for (const file of files) {
20103
+ if (file.path === ENVELOPE_FILENAME) continue;
20104
+ if (sha256(file.contents) !== digests[file.path]) {
20105
+ throw new Error("integrity digest mismatch");
20106
+ }
20107
+ }
20108
+ return true;
20109
+ }
20110
+ function sealIntegrity(manifest, files, generatedBy, generatedAt) {
20111
+ const entryDigests = {};
20112
+ for (const file of files) {
20113
+ if (file.path === ENVELOPE_FILENAME) continue;
20114
+ entryDigests[file.path] = sha256(file.contents);
20115
+ }
20116
+ const digest = sha256(canonicalDigestBytes(entryDigests));
20117
+ return { ...manifest, entryDigests, digest, generatedBy, generatedAt };
20118
+ }
20119
+ function checkCompatibility(manifest, waironVersion) {
20120
+ if (Math.trunc(manifest.formatVersion) > SUPPORTED_FORMAT_VERSION) {
20121
+ return false;
20122
+ }
20123
+ if (manifest.minWaironVersion && isBelow(waironVersion, manifest.minWaironVersion)) {
20124
+ return false;
20125
+ }
20126
+ return true;
20127
+ }
20128
+ function rejectUnsafe() {
20129
+ throw new Error("reject: unsafe or oversized archive entry (zip-slip / size / ratio / depth guard)");
20130
+ }
20131
+ function validateEnvelope(raw) {
20132
+ if (!raw || typeof raw !== "object") {
20133
+ throw new Error("malformed pack envelope (not a YAML mapping)");
20134
+ }
20135
+ const o = raw;
20136
+ if (typeof o.formatVersion !== "number") throw new Error("pack envelope: formatVersion must be a number");
20137
+ if (typeof o.name !== "string" || !o.name) throw new Error("pack envelope: name is required");
20138
+ if (typeof o.version !== "string" || !o.version) throw new Error("pack envelope: version is required");
20139
+ if (typeof o.kind !== "string" || o.kind !== "declarative" && o.kind !== "code") {
20140
+ throw new Error('pack envelope: kind must be "declarative" or "code"');
20141
+ }
20142
+ if (typeof o.entry !== "string" || !o.entry) throw new Error("pack envelope: entry is required");
20143
+ const manifest = {
20144
+ formatVersion: o.formatVersion,
20145
+ name: o.name,
20146
+ version: o.version,
20147
+ kind: o.kind,
20148
+ entry: o.entry
20149
+ };
20150
+ if (typeof o.minWaironVersion === "string") manifest.minWaironVersion = o.minWaironVersion;
20151
+ if (typeof o.digest === "string") manifest.digest = o.digest;
20152
+ if (o.entryDigests && typeof o.entryDigests === "object") {
20153
+ manifest.entryDigests = o.entryDigests;
20154
+ }
20155
+ if (typeof o.generatedBy === "string") manifest.generatedBy = o.generatedBy;
20156
+ if (typeof o.generatedAt === "string") manifest.generatedAt = o.generatedAt;
20157
+ return manifest;
20158
+ }
20159
+ function isSymlinkOrNonRegular(kind) {
20160
+ return kind !== "file" && kind !== "dir";
20161
+ }
20162
+ function isStructurallyUnsafePath(p) {
20163
+ if (p.includes("\\")) return true;
20164
+ if (/^[A-Za-z]:/.test(p)) return true;
20165
+ if (p.startsWith("/")) return true;
20166
+ return p.split("/").some((seg) => seg === "..");
20167
+ }
20168
+ function normalizeRelPath(p) {
20169
+ return p.split("/").filter((seg) => seg !== "" && seg !== ".").join("/");
20170
+ }
20171
+ function escapesDestination(normalized) {
20172
+ return normalized.startsWith("/") || normalized.split("/").some((seg) => seg === "..");
20173
+ }
20174
+ function pathDepth(normalized) {
20175
+ return normalized.split("/").filter((seg) => seg !== "").length;
20176
+ }
20177
+ function compressionRatio(entry) {
20178
+ if (entry.compressedSize > 0) return entry.uncompressedSize / entry.compressedSize;
20179
+ return entry.uncompressedSize > 0 ? Infinity : 0;
20180
+ }
20181
+ function canonicalDigestBytes(entryDigests) {
20182
+ const lines = Object.keys(entryDigests).sort().map((key) => `${key}:${entryDigests[key]}`).join("\n");
20183
+ return new TextEncoder().encode(lines);
20184
+ }
20185
+ function sha256(data) {
20186
+ return (0, import_crypto.createHash)("sha256").update(data).digest("hex");
20187
+ }
20188
+ function isBelow(running, minimum) {
20189
+ const [rMaj, rMin, rPat] = parseSemverCore(running);
20190
+ const [mMaj, mMin, mPat] = parseSemverCore(minimum);
20191
+ if (rMaj !== mMaj) return rMaj < mMaj;
20192
+ if (rMin !== mMin) return rMin < mMin;
20193
+ return rPat < mPat;
20194
+ }
20195
+ function parseSemverCore(v) {
20196
+ const cleaned = v.trim().replace(/^[^0-9]*/, "");
20197
+ const core = cleaned.split(/[-+]/)[0];
20198
+ const parts = core.split(".").map((n) => parseInt(n, 10));
20199
+ return [parts[0] || 0, parts[1] || 0, parts[2] || 0];
20200
+ }
20201
+ var import_js_yaml2 = require("js-yaml");
20202
+ var import_crypto2 = require("crypto");
20203
+ var TREE_ENVELOPE_FILENAME = "wairon-tree.yaml";
20204
+ var SUPPORTED_FORMAT_VERSION2 = 1;
20205
+ var TREE_DEFAULTS = {
20206
+ maxEntries: 2e4,
20207
+ maxTotalUncompressedBytes: 64 * 1024 * 1024,
20208
+ maxEntryBytes: 8 * 1024 * 1024,
20209
+ maxCompressionRatio: 100,
20210
+ maxDepth: 24
20211
+ };
20212
+ var DERIVED_ROOTS = ["generated", "docs"];
20213
+ var EXECUTABLE_EXT_RE = /\.(c|m)?js$/i;
20214
+ var WAI_SEGMENT = ".wai";
20215
+ function parseTreeManifest(text) {
20216
+ const raw = (0, import_js_yaml2.load)(text);
20217
+ const manifest = validateEnvelope2(raw);
20218
+ if (Math.trunc(manifest.formatVersion) > SUPPORTED_FORMAT_VERSION2) {
20219
+ throw new Error("unsupported tree-archive formatVersion (newer than this wairon understands)");
20220
+ }
20221
+ return manifest;
20222
+ }
20223
+ function serializeTreeManifest(manifest) {
20224
+ const clean = {
20225
+ formatVersion: manifest.formatVersion,
20226
+ projectName: manifest.projectName,
20227
+ roots: manifest.roots
20228
+ };
20229
+ if (manifest.stateId !== void 0) clean.stateId = manifest.stateId;
20230
+ if (manifest.waironVersion !== void 0) clean.waironVersion = manifest.waironVersion;
20231
+ if (manifest.minWaironVersion !== void 0) clean.minWaironVersion = manifest.minWaironVersion;
20232
+ if (manifest.includesDerived !== void 0) clean.includesDerived = manifest.includesDerived;
20233
+ if (manifest.digest !== void 0) clean.digest = manifest.digest;
20234
+ if (manifest.entryDigests !== void 0) clean.entryDigests = manifest.entryDigests;
20235
+ if (manifest.generatedBy !== void 0) clean.generatedBy = manifest.generatedBy;
20236
+ if (manifest.generatedAt !== void 0) clean.generatedAt = manifest.generatedAt;
20237
+ return (0, import_js_yaml2.dump)(clean, { sortKeys: false });
20238
+ }
20239
+ function defaultTreeLimits() {
20240
+ return { ...TREE_DEFAULTS };
20241
+ }
20242
+ function selectTreeFiles(files, includeDerived) {
20243
+ if (includeDerived) {
20244
+ return files;
20245
+ }
20246
+ const kept = files.filter((file) => !isDerivedPath(file.path));
20247
+ return kept;
20248
+ }
20249
+ function planTreeExtraction(entries, limits) {
20250
+ const caps = {
20251
+ maxEntries: limits.maxEntries ?? TREE_DEFAULTS.maxEntries,
20252
+ maxTotalUncompressedBytes: limits.maxTotalUncompressedBytes ?? TREE_DEFAULTS.maxTotalUncompressedBytes,
20253
+ maxEntryBytes: limits.maxEntryBytes ?? TREE_DEFAULTS.maxEntryBytes,
20254
+ maxCompressionRatio: limits.maxCompressionRatio ?? TREE_DEFAULTS.maxCompressionRatio,
20255
+ maxDepth: limits.maxDepth ?? TREE_DEFAULTS.maxDepth
20256
+ };
20257
+ const approved = [];
20258
+ let total = 0;
20259
+ for (const entry of entries) {
20260
+ if (isSymlinkOrNonRegular2(entry.kind) || isStructurallyUnsafePath2(entry.path)) {
20261
+ rejectUnsafe2();
20262
+ }
20263
+ if (entry.kind === "dir") continue;
20264
+ const normalized = normalizeRelPath2(entry.path);
20265
+ if (escapesDestination2(normalized) || pathDepth2(normalized) > caps.maxDepth) {
20266
+ rejectUnsafe2();
20267
+ }
20268
+ if (entry.uncompressedSize > caps.maxEntryBytes || compressionRatio2(entry) > caps.maxCompressionRatio) {
20269
+ rejectUnsafe2();
20270
+ }
20271
+ approved.push(normalized);
20272
+ total += entry.uncompressedSize;
20273
+ }
20274
+ if (approved.length > caps.maxEntries || total > caps.maxTotalUncompressedBytes) {
20275
+ rejectUnsafe2();
20276
+ }
20277
+ return { paths: approved, totalUncompressedBytes: total };
20278
+ }
20279
+ function assertPortableTreePaths(paths) {
20280
+ for (const entryPath of paths) {
20281
+ if (EXECUTABLE_EXT_RE.test(entryPath)) {
20282
+ throw new Error(
20283
+ "refused: the archive carries executable content. Only declarative spec state transfers over this surface; rule/code packs are executable and install via the trusted filesystem (mount into WAIRON_PACKS_DIR, or run `wairon packs add`)."
20284
+ );
20285
+ }
20286
+ if (entryPath !== TREE_ENVELOPE_FILENAME && !isUnderWaiRoot(entryPath)) {
20287
+ throw new Error(`refused: the archive carries an entry outside any spec-tree root ("${entryPath}")`);
20288
+ }
20289
+ }
20290
+ }
20291
+ function verifyTreeIntegrity(manifest, files) {
20292
+ if (!manifest.entryDigests) {
20293
+ return false;
20294
+ }
20295
+ const digests = manifest.entryDigests;
20296
+ for (const file of files) {
20297
+ if (file.path === TREE_ENVELOPE_FILENAME) continue;
20298
+ if (sha2562(file.contents) !== digests[file.path]) {
20299
+ throw new Error("tree integrity digest mismatch");
20300
+ }
20301
+ }
20302
+ return true;
20303
+ }
20304
+ function sealTreeIntegrity(manifest, files, generatedBy, generatedAt) {
20305
+ const entryDigests = {};
20306
+ for (const file of files) {
20307
+ if (file.path === TREE_ENVELOPE_FILENAME) continue;
20308
+ entryDigests[file.path] = sha2562(file.contents);
20309
+ }
20310
+ const digest = sha2562(canonicalDigestBytes2(entryDigests));
20311
+ return { ...manifest, entryDigests, digest, generatedBy, generatedAt };
20312
+ }
20313
+ function checkTreeCompatibility(manifest, waironVersion) {
20314
+ if (Math.trunc(manifest.formatVersion) > SUPPORTED_FORMAT_VERSION2) {
20315
+ return false;
20316
+ }
20317
+ if (manifest.minWaironVersion && isBelow2(waironVersion, manifest.minWaironVersion)) {
20318
+ return false;
20319
+ }
20320
+ return true;
20321
+ }
20322
+ function rejectUnsafe2() {
20323
+ throw new Error("reject: unsafe or oversized tree-archive entry (zip-slip / size / ratio / depth guard)");
20324
+ }
20325
+ function validateEnvelope2(raw) {
20326
+ if (!raw || typeof raw !== "object") {
20327
+ throw new Error("malformed tree envelope (not a YAML mapping)");
20328
+ }
20329
+ const o = raw;
20330
+ if (typeof o.formatVersion !== "number") throw new Error("tree envelope: formatVersion must be a number");
20331
+ if (typeof o.projectName !== "string" || !o.projectName) throw new Error("tree envelope: projectName is required");
20332
+ if (!Array.isArray(o.roots) || o.roots.length === 0 || o.roots.some((r) => typeof r !== "string" || !r)) {
20333
+ throw new Error("tree envelope: roots must be a non-empty list of project-relative directories");
20334
+ }
20335
+ const manifest = {
20336
+ formatVersion: o.formatVersion,
20337
+ projectName: o.projectName,
20338
+ roots: o.roots
20339
+ };
20340
+ if (typeof o.stateId === "string") manifest.stateId = o.stateId;
20341
+ if (typeof o.waironVersion === "string") manifest.waironVersion = o.waironVersion;
20342
+ if (typeof o.minWaironVersion === "string") manifest.minWaironVersion = o.minWaironVersion;
20343
+ if (typeof o.includesDerived === "boolean") manifest.includesDerived = o.includesDerived;
20344
+ if (typeof o.digest === "string") manifest.digest = o.digest;
20345
+ if (o.entryDigests && typeof o.entryDigests === "object") {
20346
+ manifest.entryDigests = o.entryDigests;
20347
+ }
20348
+ if (typeof o.generatedBy === "string") manifest.generatedBy = o.generatedBy;
20349
+ if (typeof o.generatedAt === "string") manifest.generatedAt = o.generatedAt;
20350
+ return manifest;
20351
+ }
20352
+ function isDerivedPath(relPath) {
20353
+ const first = relPath.split("/")[0];
20354
+ return DERIVED_ROOTS.includes(first);
20355
+ }
20356
+ function isUnderWaiRoot(archivePath) {
20357
+ const segments = archivePath.split("/");
20358
+ const at = segments.indexOf(WAI_SEGMENT);
20359
+ return at >= 0 && at < segments.length - 1;
20360
+ }
20361
+ function isSymlinkOrNonRegular2(kind) {
20362
+ return kind !== "file" && kind !== "dir";
20363
+ }
20364
+ function isStructurallyUnsafePath2(p) {
20365
+ if (p.includes("\\")) return true;
20366
+ if (/^[A-Za-z]:/.test(p)) return true;
20367
+ if (p.startsWith("/")) return true;
20368
+ return p.split("/").some((seg) => seg === "..");
20369
+ }
20370
+ function normalizeRelPath2(p) {
20371
+ return p.split("/").filter((seg) => seg !== "" && seg !== ".").join("/");
20372
+ }
20373
+ function escapesDestination2(normalized) {
20374
+ return normalized.startsWith("/") || normalized.split("/").some((seg) => seg === "..");
20375
+ }
20376
+ function pathDepth2(normalized) {
20377
+ return normalized.split("/").filter((seg) => seg !== "").length;
20378
+ }
20379
+ function compressionRatio2(entry) {
20380
+ if (entry.compressedSize > 0) return entry.uncompressedSize / entry.compressedSize;
20381
+ return entry.uncompressedSize > 0 ? Infinity : 0;
20382
+ }
20383
+ function canonicalDigestBytes2(entryDigests) {
20384
+ const lines = Object.keys(entryDigests).sort().map((key) => `${key}:${entryDigests[key]}`).join("\n");
20385
+ return new TextEncoder().encode(lines);
20386
+ }
20387
+ function sha2562(data) {
20388
+ return (0, import_crypto2.createHash)("sha256").update(data).digest("hex");
20389
+ }
20390
+ function isBelow2(running, minimum) {
20391
+ const [rMaj, rMin, rPat] = parseSemverCore2(running);
20392
+ const [mMaj, mMin, mPat] = parseSemverCore2(minimum);
20393
+ if (rMaj !== mMaj) return rMaj < mMaj;
20394
+ if (rMin !== mMin) return rMin < mMin;
20395
+ return rPat < mPat;
20396
+ }
20397
+ function parseSemverCore2(v) {
20398
+ const cleaned = v.trim().replace(/^[^0-9]*/, "");
20399
+ const core = cleaned.split(/[-+]/)[0];
20400
+ const parts = core.split(".").map((n) => parseInt(n, 10));
20401
+ return [parts[0] || 0, parts[1] || 0, parts[2] || 0];
20402
+ }
20403
+ var SDK_VERSION = loadVersion();
20404
+ function loadVersion() {
20405
+ try {
20406
+ const pkg = require_package();
20407
+ return pkg.version ?? "0.0.0";
20408
+ } catch {
20409
+ return "0.0.0";
20410
+ }
20411
+ }
20412
+ var enc = (s) => new TextEncoder().encode(s);
20413
+ function render(request) {
20414
+ const version = request.version ?? "0.1.0";
20415
+ let files;
20416
+ if (request.kind === "code") {
20417
+ files = renderCodePack(request.name, version);
20418
+ } else {
20419
+ files = renderDeclarativePack(request.name, version);
20420
+ }
20421
+ if (request.withSkill) {
20422
+ files.push(renderSkillStub(request.name, version));
20423
+ }
20424
+ return files;
20425
+ }
20426
+ function renderDeclarativePack(name, version) {
20427
+ return [
20428
+ { path: "wairon-pack.yaml", contents: enc(declarativeEnvelope(name, version)) },
20429
+ { path: "pack.yaml", contents: enc(declarativeManifest(name, version)) },
20430
+ { path: "README.md", contents: enc(readme(name, "declarative", "pack.yaml")) }
20431
+ ];
20432
+ }
20433
+ function renderCodePack(name, version) {
20434
+ return [
20435
+ { path: "wairon-pack.yaml", contents: enc(codeEnvelope(name, version)) },
20436
+ { path: "package.json", contents: enc(codePackageJson(name, version)) },
20437
+ { path: "tsconfig.json", contents: enc(codeTsconfig()) },
20438
+ { path: "pack.ts", contents: enc(codeEntry(name, version)) },
20439
+ { path: "README.md", contents: enc(readme(name, "code", "pack.cjs")) }
20440
+ ];
20441
+ }
20442
+ function renderSkillStub(name, _version) {
20443
+ const id = slug(name);
20444
+ return { path: `skills/${id}/SKILL.md`, contents: enc(skillStub(name)) };
20445
+ }
20446
+ function declarativeEnvelope(name, version) {
20447
+ return [
20448
+ "formatVersion: 1",
20449
+ `name: ${name}`,
20450
+ `version: ${version}`,
20451
+ "kind: declarative",
20452
+ "entry: pack.yaml",
20453
+ ""
20454
+ ].join("\n");
20455
+ }
20456
+ function codeEnvelope(name, version) {
20457
+ return [
20458
+ "formatVersion: 1",
20459
+ `name: ${name}`,
20460
+ `version: ${version}`,
20461
+ "kind: code",
20462
+ "entry: pack.cjs",
20463
+ `minWaironVersion: ${SDK_VERSION}`,
20464
+ ""
20465
+ ].join("\n");
20466
+ }
20467
+ function declarativeManifest(name, version) {
20468
+ return [
20469
+ `name: ${name}`,
20470
+ `version: ${version}`,
20471
+ "",
20472
+ "# Custom architectural profiles this pack contributes (example, commented):",
20473
+ "# profiles:",
20474
+ "# my-profile:",
20475
+ "# family: backend-like",
20476
+ "# forbiddenStereotypes:",
20477
+ "# - types: [Adapter]",
20478
+ '# reason: "Domain components must not touch adapters directly."',
20479
+ "profiles: {}",
20480
+ "",
20481
+ "# Target language / platform tables (example, commented):",
20482
+ "# languages:",
20483
+ "# rust:",
20484
+ "# unsupportedFlow: {}",
20485
+ "# foreignBuiltins: []",
20486
+ "languages: {}",
20487
+ "",
20488
+ "# Reusable, versioned architecture patterns:",
20489
+ "patterns: []",
20490
+ ""
20491
+ ].join("\n");
20492
+ }
20493
+ function codePackageJson(name, version) {
20494
+ const pkg = {
20495
+ name,
20496
+ version,
20497
+ private: true,
20498
+ scripts: {
20499
+ build: "esbuild pack.ts --bundle --platform=node --packages=external --format=cjs --outfile=pack.cjs"
20500
+ },
20501
+ dependencies: {
20502
+ "@wairon/sdk": SDK_VERSION
20503
+ },
20504
+ devDependencies: {
20505
+ esbuild: "^0.21.0",
20506
+ typescript: "^5.0.0"
20507
+ }
20508
+ };
20509
+ return `${JSON.stringify(pkg, null, 2)}
20510
+ `;
20511
+ }
20512
+ function codeTsconfig() {
20513
+ const tsconfig = {
20514
+ compilerOptions: {
20515
+ target: "ES2020",
20516
+ module: "CommonJS",
20517
+ moduleResolution: "node",
20518
+ strict: true,
20519
+ esModuleInterop: true,
20520
+ skipLibCheck: true,
20521
+ declaration: false,
20522
+ noEmit: true
20523
+ },
20524
+ include: ["pack.ts"]
20525
+ };
20526
+ return `${JSON.stringify(tsconfig, null, 2)}
20527
+ `;
20528
+ }
20529
+ function codeEntry(name, version) {
20530
+ const code = slug(name).toUpperCase().replace(/-/g, "_");
20531
+ return [
20532
+ "import { defineRule } from '@wairon/sdk';",
20533
+ "import type { RuleContext, Finding } from '@wairon/sdk';",
20534
+ "",
20535
+ "const exampleRule = defineRule({",
20536
+ ` name: '${slug(name)}-example',`,
20537
+ " description: 'Example architectural rule. Replace with your own doctrine.',",
20538
+ ` codes: ['${code}_EXAMPLE'],`,
20539
+ " check(ctx: RuleContext): Finding[] {",
20540
+ " const findings: Finding[] = [];",
20541
+ " for (const component of ctx.components) {",
20542
+ " // Inspect the spec tree and push findings as needed.",
20543
+ " void component;",
20544
+ " }",
20545
+ " return findings;",
20546
+ " },",
20547
+ "});",
20548
+ "",
20549
+ "export default {",
20550
+ ` name: '${name}',`,
20551
+ ` version: '${version}',`,
20552
+ " rules: [exampleRule],",
20553
+ "};",
20554
+ ""
20555
+ ].join("\n");
20556
+ }
20557
+ function readme(name, kind, entry) {
20558
+ return [
20559
+ `# ${name}`,
20560
+ "",
20561
+ `A wairon ${kind} pack.`,
20562
+ "",
20563
+ `- Envelope: \`wairon-pack.yaml\``,
20564
+ `- Entry: \`${entry}\``,
20565
+ "",
20566
+ "Build an installable `.wpack` archive with `wairon pack build`.",
20567
+ ""
20568
+ ].join("\n");
20569
+ }
20570
+ function skillStub(name) {
20571
+ return [
20572
+ "---",
20573
+ `name: ${name}`,
20574
+ `description: ${name} authoring skill (stub).`,
20575
+ "---",
20576
+ "",
20577
+ `# ${name}`,
20578
+ "",
20579
+ "Describe when this skill applies and what it guides.",
20580
+ ""
20581
+ ].join("\n");
20582
+ }
20583
+ function slug(name) {
20584
+ return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
20585
+ }
20586
+ var fs17 = __toESM2(require("fs"));
20587
+ var path28 = __toESM2(require("path"));
20588
+ var import_fflate = require_node();
20589
+ var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".hg", ".svn"]);
20590
+ function listEntries(archive) {
20591
+ const symlinks = detectSymlinkNames(archive);
20592
+ const metas = [];
20593
+ (0, import_fflate.unzipSync)(archive, {
20594
+ filter: (info) => {
20595
+ metas.push({
20596
+ path: info.name,
20597
+ uncompressedSize: info.originalSize,
20598
+ compressedSize: info.size,
20599
+ kind: classifyKind(info.name, symlinks)
20600
+ });
20601
+ return false;
20602
+ }
20603
+ });
20604
+ return metas;
20605
+ }
20606
+ function inflateEntry(archive, entryPath) {
20607
+ const inflated = (0, import_fflate.unzipSync)(archive, { filter: (info) => info.name === entryPath });
20608
+ const bytes = inflated[entryPath];
20609
+ if (!bytes) throw new Error(`archive entry not found: ${entryPath}`);
20610
+ return bytes;
20611
+ }
20612
+ function assembleArchive(files) {
20613
+ const zippable = {};
20614
+ for (const file of files) zippable[file.path] = file.contents;
20615
+ const bytes = (0, import_fflate.zipSync)(zippable);
20616
+ return bytes;
20617
+ }
20618
+ function readPackDir(dir) {
20619
+ const files = [];
20620
+ walkPackDir(dir, dir, files);
20621
+ return files;
20622
+ }
20623
+ function writeTree(destDir, files) {
20624
+ for (const file of files) {
20625
+ const absolute = path28.join(destDir, file.path);
20626
+ fs17.mkdirSync(path28.dirname(absolute), { recursive: true });
20627
+ fs17.writeFileSync(absolute, file.contents);
20628
+ }
20629
+ }
20630
+ function classifyKind(name, symlinks) {
20631
+ if (symlinks.has(name)) return "symlink";
20632
+ if (name.endsWith("/")) return "dir";
20633
+ return "file";
20634
+ }
20635
+ function walkPackDir(root, current2, out) {
20636
+ for (const entry of fs17.readdirSync(current2, { withFileTypes: true })) {
20637
+ if (entry.isDirectory()) {
20638
+ if (SKIP_DIRS.has(entry.name)) continue;
20639
+ walkPackDir(root, path28.join(current2, entry.name), out);
20640
+ } else if (entry.isFile()) {
20641
+ const absolute = path28.join(current2, entry.name);
20642
+ const relative22 = path28.relative(root, absolute).split(path28.sep).join("/");
20643
+ out.push({ path: relative22, contents: fs17.readFileSync(absolute) });
20644
+ }
20645
+ }
20646
+ }
20647
+ function detectSymlinkNames(archive) {
20648
+ const names = /* @__PURE__ */ new Set();
20649
+ try {
20650
+ const eocd = findEocd(archive);
20651
+ if (eocd < 0) return names;
20652
+ let p = readU32(archive, eocd + 16);
20653
+ const count = readU16(archive, eocd + 10);
20654
+ const decoder = new TextDecoder();
20655
+ for (let i = 0; i < count; i++) {
20656
+ if (readU32(archive, p) !== 33639248) break;
20657
+ const versionMadeBy = readU16(archive, p + 4);
20658
+ const nameLen = readU16(archive, p + 28);
20659
+ const extraLen = readU16(archive, p + 30);
20660
+ const commentLen = readU16(archive, p + 32);
20661
+ const externalAttrs = readU32(archive, p + 38);
20662
+ const name = decoder.decode(archive.subarray(p + 46, p + 46 + nameLen));
20663
+ if (versionMadeBy >> 8 === 3) {
20664
+ const unixMode = externalAttrs >>> 16 & 65535;
20665
+ if ((unixMode & 61440) === 40960) names.add(name);
20666
+ }
20667
+ p += 46 + nameLen + extraLen + commentLen;
20668
+ }
20669
+ } catch {
20670
+ return names;
20671
+ }
20672
+ return names;
20673
+ }
20674
+ function findEocd(buf) {
20675
+ const minRecord = 22;
20676
+ const lowerBound = Math.max(0, buf.length - (minRecord + 65535));
20677
+ for (let i = buf.length - minRecord; i >= lowerBound; i--) {
20678
+ if (readU32(buf, i) === 101010256) return i;
20679
+ }
20680
+ return -1;
20681
+ }
20682
+ function readU16(buf, off) {
20683
+ return buf[off] | buf[off + 1] << 8;
20684
+ }
20685
+ function readU32(buf, off) {
20686
+ return (buf[off] | buf[off + 1] << 8 | buf[off + 2] << 16 | buf[off + 3] << 24) >>> 0;
20687
+ }
20688
+ var decode = (b) => new TextDecoder().decode(b);
20689
+ var encode = (s) => new TextEncoder().encode(s);
20690
+ function scaffoldPack(request) {
20691
+ const files = render(request);
20692
+ writeTree(request.targetDir, files);
20693
+ return files.map((file) => path27.join(request.targetDir, file.path));
20694
+ }
20695
+ function buildPack(sourceDir) {
20696
+ const files = readPackDir(sourceDir);
20697
+ const envelope = files.find((file) => file.path === ENVELOPE_FILENAME);
20698
+ if (!envelope) {
20699
+ throw new Error("pack build requires a wairon-pack.yaml envelope (run `wairon pack init` to scaffold one)");
20700
+ }
20701
+ const manifest = parseManifest(decode(envelope.contents));
20702
+ const identity = readInnerIdentity(files, manifest);
20703
+ verifyIdentity(manifest, identity.name, identity.version);
20704
+ const sealed = sealIntegrity(manifest, files, `@wairon/sdk@${SDK_VERSION}`, (/* @__PURE__ */ new Date()).toISOString());
20705
+ const sealedText = serializeManifest(sealed);
20706
+ const finalFiles = upsertEnvelope(files, sealedText);
20707
+ const archiveBytes = assembleArchive(finalFiles);
20708
+ const info = buildInfo(sealed, finalFiles);
20709
+ const suggestedFileName = `${sealed.name}-${sealed.version}.wpack`;
20710
+ return { archive: archiveBytes, info, suggestedFileName };
20711
+ }
20712
+ function inspectArchive(archiveBytes) {
20713
+ const entries = listEntries(archiveBytes);
20714
+ if (!entries.some((entry) => entry.path === ENVELOPE_FILENAME)) {
20715
+ throw new Error("not a .wpack archive (missing wairon-pack.yaml envelope)");
20716
+ }
20717
+ const envelopeBytes = inflateEntry(archiveBytes, ENVELOPE_FILENAME);
20718
+ const manifest = parseManifest(decode(envelopeBytes));
20719
+ const compatible = checkCompatibility(manifest, SDK_VERSION);
20720
+ const fileEntries = entries.filter((entry) => entry.kind === "file");
20721
+ const totalUncompressedBytes = entries.reduce((sum, entry) => sum + entry.uncompressedSize, 0);
20722
+ const info = {
20723
+ name: manifest.name,
20724
+ version: manifest.version,
20725
+ kind: manifest.kind,
20726
+ entry: manifest.entry,
20727
+ formatVersion: manifest.formatVersion,
20728
+ entryCount: fileEntries.length,
20729
+ totalUncompressedBytes,
20730
+ compatible
20731
+ };
20732
+ if (manifest.minWaironVersion !== void 0) info.minWaironVersion = manifest.minWaironVersion;
20733
+ return info;
20734
+ }
20735
+ function extractPack(archiveBytes, destDir, limits) {
20736
+ const effectiveLimits = limits === void 0 ? defaultLimits() : limits;
20737
+ const entries = listEntries(archiveBytes);
20738
+ const plan = planExtraction(entries, effectiveLimits);
20739
+ const files = [];
20740
+ for (const approvedPath of plan.paths) {
20741
+ const contents = inflateEntry(archiveBytes, approvedPath);
20742
+ files.push({ path: approvedPath, contents });
20743
+ }
20744
+ const envelope = files.find((file) => file.path === ENVELOPE_FILENAME);
20745
+ if (!envelope) {
20746
+ throw new Error("not a .wpack archive (missing wairon-pack.yaml envelope)");
20747
+ }
20748
+ const manifest = parseManifest(decode(envelope.contents));
20749
+ verifyIntegrity2(manifest, files);
20750
+ const directory = path27.resolve(destDir);
20751
+ writeTree(directory, files);
20752
+ const result = {
20753
+ directory,
20754
+ entryPath: manifest.entry,
20755
+ manifest,
20756
+ name: manifest.name,
20757
+ kind: manifest.kind,
20758
+ entryCount: files.length
20759
+ };
20760
+ return result;
20761
+ }
20762
+ function buildTreeArchive3(roots, projectName, stateId, includeDerived) {
20763
+ const files = [];
20764
+ const packedRoots = [];
20765
+ for (const root of roots) {
20766
+ const rootFiles = readPackDir(root.waiDir);
20767
+ const portable = selectTreeFiles(rootFiles, includeDerived === true);
20768
+ const prefix = treeRootPrefix(root.relativePath);
20769
+ for (const file of portable) files.push({ path: `${prefix}${file.path}`, contents: file.contents });
20770
+ packedRoots.push(normalizeRootPath(root.relativePath));
20771
+ }
20772
+ if (files.length === 0) {
20773
+ throw new Error("tree export found no spec-tree files under the supplied roots");
20774
+ }
20775
+ const manifest = {
20776
+ formatVersion: 1,
20777
+ projectName,
20778
+ roots: packedRoots,
20779
+ waironVersion: SDK_VERSION,
20780
+ includesDerived: includeDerived === true
20781
+ };
20782
+ if (stateId !== void 0) manifest.stateId = stateId;
20783
+ const sealed = sealTreeIntegrity(
20784
+ manifest,
20785
+ files,
20786
+ `@wairon/sdk@${SDK_VERSION}`,
20787
+ (/* @__PURE__ */ new Date()).toISOString()
20788
+ );
20789
+ const sealedText = serializeTreeManifest(sealed);
20790
+ const finalFiles = [
20791
+ ...files.filter((file) => file.path !== TREE_ENVELOPE_FILENAME),
20792
+ { path: TREE_ENVELOPE_FILENAME, contents: encode(sealedText) }
20793
+ ];
20794
+ const archiveBytes = assembleArchive(finalFiles);
20795
+ const suggestedFileName = `${slugify(projectName)}.waitree`;
20796
+ return { archive: archiveBytes, manifest: sealed, suggestedFileName, fileCount: files.length };
20797
+ }
20798
+ function inspectTreeArchive3(archiveBytes) {
20799
+ const entries = listEntries(archiveBytes);
20800
+ if (!entries.some((entry) => entry.path === TREE_ENVELOPE_FILENAME)) {
20801
+ throw new Error("not a .waitree archive (missing wairon-tree.yaml envelope)");
20802
+ }
20803
+ const envelopeBytes = inflateEntry(archiveBytes, TREE_ENVELOPE_FILENAME);
20804
+ const manifest = parseTreeManifest(decode(envelopeBytes));
20805
+ const compatible = checkTreeCompatibility(manifest, SDK_VERSION);
20806
+ const fileEntries = entries.filter((entry) => entry.kind === "file");
20807
+ const totalUncompressedBytes = entries.reduce((sum, entry) => sum + entry.uncompressedSize, 0);
20808
+ return { manifest, entryCount: fileEntries.length, totalUncompressedBytes, compatible };
20809
+ }
20810
+ function extractTreeArchive3(archiveBytes, destDir, limits, refuseExecutableEntries) {
20811
+ const effectiveLimits = limits === void 0 ? defaultTreeLimits() : limits;
20812
+ const entries = listEntries(archiveBytes);
20813
+ const plan = planTreeExtraction(entries, effectiveLimits);
20814
+ if (refuseExecutableEntries === true) {
20815
+ assertPortableTreePaths(plan.paths);
20816
+ }
20817
+ const files = [];
20818
+ for (const approvedPath of plan.paths) {
20819
+ const contents = inflateEntry(archiveBytes, approvedPath);
20820
+ files.push({ path: approvedPath, contents });
20821
+ }
20822
+ const envelope = files.find((file) => file.path === TREE_ENVELOPE_FILENAME);
20823
+ if (!envelope) {
20824
+ throw new Error("not a .waitree archive (missing wairon-tree.yaml envelope)");
20825
+ }
20826
+ const manifest = parseTreeManifest(decode(envelope.contents));
20827
+ verifyTreeIntegrity(manifest, files);
20828
+ const directory = path27.resolve(destDir);
20829
+ writeTree(directory, files);
20830
+ const result = {
20831
+ destDir: directory,
20832
+ manifest,
20833
+ roots: manifest.roots,
20834
+ writtenPaths: files.map((file) => file.path)
20835
+ };
20836
+ return result;
20837
+ }
20838
+ function treeRootPrefix(relativePath) {
20839
+ const normalized = normalizeRootPath(relativePath);
20840
+ return normalized === "." ? ".wai/" : `${normalized}/.wai/`;
20841
+ }
20842
+ function normalizeRootPath(relativePath) {
20843
+ const posix3 = relativePath.split(path27.sep).join("/").replace(/^\.\//, "").replace(/\/+$/, "");
20844
+ return posix3 === "" || posix3 === "." ? "." : posix3;
20845
+ }
20846
+ function slugify(projectName) {
20847
+ const slug2 = projectName.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
20848
+ return slug2 || "spec-tree";
20849
+ }
20850
+ function readInnerIdentity(files, manifest) {
20851
+ const innerPath = manifest.kind === "code" ? "package.json" : manifest.entry;
20852
+ const inner = files.find((file) => file.path === innerPath);
20853
+ if (!inner) throw new Error(`pack build: inner pack manifest "${innerPath}" is missing`);
20854
+ const parsed = manifest.kind === "code" ? JSON.parse(decode(inner.contents)) : (0, import_js_yaml3.load)(decode(inner.contents));
20855
+ const name = parsed?.name;
20856
+ const version = parsed?.version;
20857
+ if (typeof name !== "string" || typeof version !== "string") {
20858
+ throw new Error(`pack build: inner pack manifest "${innerPath}" lacks a name/version`);
20859
+ }
20860
+ return { name, version };
20861
+ }
20862
+ function upsertEnvelope(files, envelopeText) {
20863
+ const others = files.filter((file) => file.path !== ENVELOPE_FILENAME);
20864
+ return [...others, { path: ENVELOPE_FILENAME, contents: encode(envelopeText) }];
20865
+ }
20866
+ function buildInfo(manifest, files) {
20867
+ const totalUncompressedBytes = files.reduce((sum, file) => sum + file.contents.length, 0);
20868
+ const info = {
20869
+ name: manifest.name,
20870
+ version: manifest.version,
20871
+ kind: manifest.kind,
20872
+ entry: manifest.entry,
20873
+ formatVersion: manifest.formatVersion,
20874
+ entryCount: files.length,
20875
+ totalUncompressedBytes,
20876
+ compatible: true
20877
+ };
20878
+ if (manifest.minWaironVersion !== void 0) info.minWaironVersion = manifest.minWaironVersion;
20879
+ return info;
20880
+ }
20881
+ function defineRule(rule) {
20882
+ return rule;
20883
+ }
20884
+ function scaffoldPack2(request) {
20885
+ return scaffoldPack(request);
20886
+ }
20887
+ function buildPack2(sourceDir) {
20888
+ return buildPack(sourceDir);
20889
+ }
20890
+ function inspectArchive2(archive) {
20891
+ return inspectArchive(archive);
20892
+ }
20893
+ function extractPack2(archive, destDir, limits) {
20894
+ return extractPack(archive, destDir, limits);
20895
+ }
20896
+ function buildTreeArchive22(roots, projectName, stateId, includeDerived) {
20897
+ return buildTreeArchive3(roots, projectName, stateId, includeDerived);
20898
+ }
20899
+ function inspectTreeArchive22(archive) {
20900
+ return inspectTreeArchive3(archive);
20901
+ }
20902
+ function extractTreeArchive22(archive, destDir, limits, refuseExecutableEntries) {
20903
+ return extractTreeArchive3(archive, destDir, limits, refuseExecutableEntries);
20904
+ }
20905
+ }
20906
+ });
20907
+
20908
+ // src/index.ts
20909
+ var src_exports = {};
20910
+ __export(src_exports, {
20911
+ AI_PATHS: () => AI_PATHS,
20912
+ ARCHITECT_AGENT_ID: () => ARCHITECT_AGENT_ID,
20913
+ ARCHITECT_TEMPLATE_ID: () => ARCHITECT_TEMPLATE_ID,
20914
+ AgentBriefSchema: () => AgentBriefSchema,
20915
+ AgentRecordSchema: () => AgentRecordSchema,
20916
+ AgentStatusSchema: () => AgentStatusSchema,
20917
+ AgentTemplateSchema: () => AgentTemplateSchema,
20918
+ AssertionSelectorSchema: () => AssertionSelectorSchema,
20919
+ BACKEND_COMMANDS: () => BACKEND_COMMANDS,
20920
+ BUILTIN_PROFILES: () => BUILTIN_PROFILES,
20921
+ BUILTIN_TYPES: () => BUILTIN_TYPES,
20922
+ BoundaryItemSchema: () => BoundaryItemSchema,
20923
+ BuiltinTargetConfigSchema: () => BuiltinTargetConfigSchema,
20924
+ BuiltinTargetSchema: () => BuiltinTargetSchema,
20925
+ BundleNotFoundError: () => BundleNotFoundError,
20926
+ CONTEXT_PATHS: () => CONTEXT_PATHS,
20927
+ CatchClauseSchema: () => CatchClauseSchema,
20928
+ ClaudeExporter: () => ClaudeExporter,
20929
+ ComplexityRuleConfigSchema: () => ComplexityRuleConfigSchema,
20930
+ ComponentSpecSchema: () => ComponentSpecSchema,
20931
+ ComponentTypeSchema: () => ComponentTypeSchema,
20932
+ ConfigValidationError: () => ConfigValidationError,
20933
+ ConformanceTierSchema: () => ConformanceTierSchema,
20934
+ CustomExporter: () => CustomExporter,
20935
+ CustomTargetConfigSchema: () => CustomTargetConfigSchema,
20936
+ CustomTargetSchema: () => CustomTargetSchema,
20937
+ DEFAULT_TARGET_DIRS: () => DEFAULT_TARGET_DIRS,
20938
+ DatabaseSpecSchema: () => DatabaseSpecSchema,
20939
+ DeclarativePackSchema: () => DeclarativePackSchema,
20940
+ DesignDepthSchema: () => DesignDepthSchema,
20941
+ DiagramConfigSchema: () => DiagramConfigSchema,
20942
+ DispatchBindingSchema: () => DispatchBindingSchema,
20943
+ DocumentationRuleConfigSchema: () => DocumentationRuleConfigSchema,
20944
+ DomainSchema: () => DomainSchema,
20945
+ DomainTypeSchema: () => DomainTypeSchema,
20946
+ DurabilitySchema: () => DurabilitySchema,
20947
+ EndpointSchema: () => EndpointSchema,
20948
+ EventBindingSchema: () => EventBindingSchema,
20949
+ ExtDataSchema: () => ExtDataSchema,
20950
+ ExternalLinkSchema: () => ExternalLinkSchema,
20951
+ ExternalLinkTypeSchema: () => ExternalLinkTypeSchema,
20952
+ GITHUB_REPO: () => GITHUB_REPO,
20953
+ GLOBAL_PACKS_DEFAULT: () => GLOBAL_PACKS_DEFAULT,
20954
+ GeminiExporter: () => GeminiExporter,
20955
+ GroupSpecSchema: () => GroupSpecSchema,
20956
+ GuaranteeSchema: () => GuaranteeSchema,
20957
+ HttpMethodSchema: () => HttpMethodSchema,
20958
+ ImplementationSpecSchema: () => ImplementationSpecSchema,
20959
+ InterfaceSpecSchema: () => InterfaceSpecSchema,
20960
+ InvariantSchema: () => InvariantSchema,
20961
+ LANGUAGE_MARKERS: () => LANGUAGE_MARKERS,
20962
+ LanguagePackDefSchema: () => LanguagePackDefSchema,
20963
+ LifecycleEntrypointSchema: () => LifecycleEntrypointSchema,
20964
+ LintAllowSchema: () => LintAllowSchema,
20965
+ LintConfigSchema: () => LintConfigSchema,
20966
+ LoopKindSchema: () => LoopKindSchema,
20967
+ MethodImplementationSchema: () => MethodImplementationSchema,
20968
+ MethodParamSchema: () => MethodParamSchema,
20969
+ MethodSignatureSchema: () => MethodSignatureSchema,
20970
+ NamedOpenApiSpecSchema: () => NamedOpenApiSpecSchema,
20971
+ NamingRuleConfigSchema: () => NamingRuleConfigSchema,
20972
+ NarrativeDetailSchema: () => NarrativeDetailSchema,
20973
+ NarrativeStepSchema: () => NarrativeStepSchema,
20974
+ NarrativeStepTypeSchema: () => NarrativeStepTypeSchema,
20975
+ OutputTargetSchema: () => OutputTargetSchema,
20976
+ PACK_DIR_ENTRIES: () => PACK_DIR_ENTRIES,
20977
+ PATTERN_TYPES: () => PATTERN_TYPES,
20978
+ PROJECT_KINDS: () => PROJECT_KINDS,
20979
+ PackAssertionSchema: () => PackAssertionSchema,
20980
+ PackInstructionBlockSchema: () => PackInstructionBlockSchema,
20981
+ PackSelectionSchema: () => PackSelectionSchema,
20982
+ PackSkillSchema: () => PackSkillSchema,
20983
+ ParallelBranchSchema: () => ParallelBranchSchema,
20984
+ PathsConfigSchema: () => PathsConfigSchema,
20985
+ PatternDefSchema: () => PatternDefSchema,
20986
+ PatternRefSchema: () => PatternRefSchema,
20987
+ PortalAuthSchema: () => PortalAuthSchema,
20988
+ PortalAuthSchemeSchema: () => PortalAuthSchemeSchema,
20989
+ PortalTypeSchema: () => PortalTypeSchema,
20990
+ ProfileDefSchema: () => ProfileDefSchema,
20991
+ ProfileSelectionSubjectSchema: () => ProfileSelectionSubjectSchema,
20992
+ ProjectConfigSchema: () => ProjectConfigSchema,
20993
+ ProjectNotInitializedError: () => ProjectNotInitializedError,
20994
+ ProjectProfileSelectionSchema: () => ProjectProfileSelectionSchema,
20995
+ PublicInterfaceSchema: () => PublicInterfaceSchema,
20996
+ PublicInterfaceTypeSchema: () => PublicInterfaceTypeSchema,
20997
+ RegistrySchema: () => RegistrySchema,
20998
+ RequirementItemSchema: () => RequirementItemSchema,
20999
+ RulesConfigSchema: () => RulesConfigSchema,
21000
+ SCAN_EXCLUDE_DIRS: () => SCAN_EXCLUDE_DIRS,
21001
+ SDD_RULES: () => SDD_RULES,
21002
+ SEMANTIC_GUARANTEES: () => SEMANTIC_GUARANTEES,
21003
+ SUPPORTED_ALIASES: () => SUPPORTED_ALIASES,
21004
+ SURFACE_AUDIENCES: () => SURFACE_AUDIENCES,
21005
+ SkillResourceNotFoundError: () => SkillResourceNotFoundError,
21006
+ SpecIdSchema: () => SpecIdSchema,
21007
+ SpecStatusSchema: () => SpecStatusSchema,
21008
+ SpecWorkspace: () => SpecWorkspace,
21009
+ SubsystemSpecSchema: () => SubsystemSpecSchema,
21010
+ SurfaceAudienceSchema: () => SurfaceAudienceSchema,
21011
+ SurfaceContractEntrySchema: () => SurfaceContractEntrySchema,
21012
+ SurfaceOriginSchema: () => SurfaceOriginSchema,
21013
+ SurfaceSnapshotSchema: () => SurfaceSnapshotSchema,
21014
+ SurfaceTypeDefSchema: () => SurfaceTypeDefSchema,
21015
+ SwitchCaseSchema: () => SwitchCaseSchema,
21016
+ SystemPublicInterfaceSchema: () => SystemPublicInterfaceSchema,
21017
+ SystemSpecSchema: () => SystemSpecSchema,
21018
+ TargetConfigSchema: () => TargetConfigSchema,
21019
+ TemplateNotFoundError: () => TemplateNotFoundError,
21020
+ TemplateSchema: () => TemplateSchema,
21021
+ TopologyConfigSchema: () => TopologyConfigSchema,
21022
+ TransportSchema: () => TransportSchema,
21023
+ TrustedLinkSchema: () => TrustedLinkSchema,
21024
+ TypeFieldSchema: () => TypeFieldSchema,
21025
+ TypeKindSchema: () => TypeKindSchema,
21026
+ TypeMethodSchema: () => TypeMethodSchema,
21027
+ TypeSpecSchema: () => TypeSpecSchema,
21028
+ UNVERSIONED: () => UNVERSIONED,
21029
+ UnknownAgentError: () => UnknownAgentError,
21030
+ VariantDefSchema: () => VariantDefSchema,
21031
+ WAIRON_MANAGED_BANNER: () => WAIRON_MANAGED_BANNER,
21032
+ WAIRON_MANAGED_MARKER: () => WAIRON_MANAGED_MARKER,
21033
+ WAIRON_VERSION: () => WAIRON_VERSION,
21034
+ WaironError: () => WaironError,
21035
+ activeTargetTypes: () => activeTargetTypes,
21036
+ addFreeStandingDomain: () => addFreeStandingDomain,
21037
+ aiDir: () => aiDir,
21038
+ aiPathsAt: () => aiPathsAt,
21039
+ applySpecStatus: () => applySpecStatus,
21040
+ assertContainedProjectPath: () => assertContainedProjectPath,
21041
+ assertProjectInitialized: () => assertProjectInitialized,
21042
+ assertionFullCode: () => assertionFullCode,
21043
+ audienceRank: () => audienceRank,
21044
+ backendCommand: () => backendCommand,
21045
+ backfillChainedSubprojectConfigs: () => backfillChainedSubprojectConfigs,
21046
+ buildCanvasDataModel: () => buildCanvasDataModel,
21047
+ buildGraphModel: () => buildGraphModel,
21048
+ buildProjectGraph: () => buildProjectGraph,
21049
+ buildRuleContext: () => buildRuleContext,
21050
+ buildServerInstructions: () => buildServerInstructions2,
21051
+ buildTreeArchive: () => buildTreeArchive2,
21052
+ checkChildSurfaceFreshness: () => checkChildSurfaceFreshness,
21053
+ checkSkillFreshness: () => checkSkillFreshness,
21054
+ clearLoaderIssues: () => clearLoaderIssues,
21055
+ collectPromotableSpecs: () => collectPromotableSpecs,
21056
+ commitStagedTree: () => commitStagedTree,
21057
+ composeAgentBrief: () => composeAgentBrief,
21058
+ composeRuleSequence: () => composeRuleSequence,
21059
+ composeVariantGuidance: () => composeVariantGuidance,
21060
+ computeGateStateId: () => computeGateStateId,
21061
+ computePackDigest: () => computePackDigest,
21062
+ computeParentStateId: () => computeParentStateId,
21063
+ computeStateId: () => computeStateId,
21064
+ computeStateIdAt: () => computeStateIdAt,
21065
+ contextDir: () => contextDir,
21066
+ createAgentRecord: () => createAgentRecord,
21067
+ createChainedSubsystem: () => createChainedSubsystem,
21068
+ createEmptyRegistry: () => createEmptyRegistry,
21069
+ createEmptyTopologyConfig: () => createEmptyTopologyConfig,
21070
+ createStagingDir: () => createStagingDir,
21071
+ defaultPackSelections: () => defaultPackSelections,
21072
+ defaultTargetConfig: () => defaultTargetConfig,
21073
+ deleteComponentSpec: () => deleteComponentSpec,
21074
+ deleteGroupSpec: () => deleteGroupSpec,
21075
+ deleteImplementationSpec: () => deleteImplementationSpec,
21076
+ deleteInterfaceSpec: () => deleteInterfaceSpec,
21077
+ deleteSubsystemSpec: () => deleteSubsystemSpec,
21078
+ deleteTypeSpec: () => deleteTypeSpec,
21079
+ deriveSubsystemDomains: () => deriveSubsystemDomains,
21080
+ detectDomainCandidates: () => detectDomainCandidates,
21081
+ diagnoseProjectPacks: () => diagnoseProjectPacks,
21082
+ diagramSetIndex: () => diagramSetIndex,
21083
+ discardStagingDir: () => discardStagingDir,
21084
+ discoverPacks: () => discoverPacks,
21085
+ dryRunSerializeSpecs: () => dryRunSerializeSpecs,
21086
+ emptyExtensions: () => emptyExtensions,
21087
+ ensureDir: () => ensureDir,
21088
+ ensureProjectInitialized: () => ensureProjectInitialized,
21089
+ exportSddSkills: () => exportSddSkills,
21090
+ exportSpecTree: () => exportSpecTree,
21091
+ exportSurface: () => exportSurface,
21092
+ externalizeSubsystem: () => externalizeSubsystem,
21093
+ extractGenericTypeVariables: () => extractGenericTypeVariables,
21094
+ extractTreeArchive: () => extractTreeArchive2,
21095
+ extractTypeGenerics: () => extractTypeGenerics,
21096
+ extractTypeIdentifiers: () => extractTypeIdentifiers,
21097
+ extractTypesFromSignature: () => extractTypesFromSignature,
21098
+ findChainingParent: () => findChainingParent,
21099
+ findChainingSubprojectsMissingConfig: () => findChainingSubprojectsMissingConfig,
21100
+ findDomain: () => findDomain,
21101
+ findLegacySpecFiles: () => findLegacySpecFiles,
21102
+ findProjectRoot: () => findProjectRoot,
21103
+ findSystemRoot: () => findSystemRoot,
21104
+ fromOpenApi: () => fromOpenApi,
21105
+ fromProjectRoot: () => fromProjectRoot,
21106
+ generateAgent: () => generateAgent,
21107
+ generateAll: () => generateAll,
21108
+ generateChildSnapshots: () => generateChildSnapshots,
21109
+ generateComponentDiagram: () => generateComponentDiagram,
21110
+ generateDiagramSet: () => generateDiagramSet,
21111
+ generateSequenceDiagram: () => generateSequenceDiagram,
21112
+ getComponentPath: () => getComponentPath,
21113
+ getExporter: () => getExporter,
21114
+ getGroupPath: () => getGroupPath,
21115
+ getImplementationPath: () => getImplementationPath,
21116
+ getInterfacePath: () => getInterfacePath,
21117
+ getLoaderIssues: () => getLoaderIssues,
21118
+ getProjectRoot: () => getProjectRoot,
21119
+ getProjectRootOverride: () => getProjectRootOverride,
21120
+ getRequestProjectRoot: () => getRequestProjectRoot,
21121
+ getSnapshot: () => getSnapshot,
21122
+ getSubprojectPrefix: () => getSubprojectPrefix,
21123
+ getSubsystemPath: () => getSubsystemPath,
21124
+ getTypePath: () => getTypePath,
21125
+ globalPacksDir: () => globalPacksDir,
21126
+ globalPacksEnabled: () => globalPacksEnabled,
21127
+ globalTemplatesDir: () => globalTemplatesDir,
21128
+ globalVariantsDir: () => globalVariantsDir,
21129
+ hasArchitectureContext: () => hasArchitectureContext,
21130
+ hasAuthoredSpecs: () => hasAuthoredSpecs,
21131
+ hasContext: () => hasContext,
21132
+ hasSpecTree: () => hasSpecTree,
21133
+ hashGateState: () => hashGateState,
21134
+ importSpecTree: () => importSpecTree,
21135
+ importSurface: () => importSurface,
21136
+ inspectTreeArchive: () => inspectTreeArchive2,
21137
+ installPackFromDirectory: () => installPackFromDirectory,
21138
+ internalizeSubsystem: () => internalizeSubsystem,
21139
+ invalidateSpecCache: () => invalidateSpecCache,
21140
+ isOpenApiDocument: () => isOpenApiDocument,
21141
+ isProjectInitialized: () => isProjectInitialized,
21142
+ listChainedRoots: () => listChainedRoots,
21143
+ listDirectChainedSubprojects: () => listDirectChainedSubprojects,
21144
+ listExternalInterfaces: () => listExternalInterfaces,
21145
+ listFiles: () => listFiles,
21146
+ listFilesRecursive: () => listFilesRecursive,
21147
+ listFreeStandingDomains: () => listFreeStandingDomains,
21148
+ listInstalledPacks: () => listInstalledPacks,
21149
+ listResources: () => listResources,
21150
+ listRules: () => listRules,
21151
+ listSkillNames: () => listSkillNames,
21152
+ listSkillResources: () => listSkillResources,
21153
+ listSnapshots: () => listSnapshots,
21154
+ listTemplateIds: () => listTemplateIds,
21155
+ loadAgentOverride: () => loadAgentOverride,
17747
21156
  loadComponentSpec: () => loadComponentSpec,
17748
21157
  loadComponentSpecs: () => loadComponentSpecs,
17749
21158
  loadExtensionPacks: () => loadExtensionPacks,
@@ -18013,8 +21422,8 @@ function walkForPackages(projectRoot, currentDir, depth, results) {
18013
21422
  }
18014
21423
  }
18015
21424
  function pathToId(relPath) {
18016
- const basename10 = path18.basename(relPath);
18017
- return basename10.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
21425
+ const basename11 = path18.basename(relPath);
21426
+ return basename11.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
18018
21427
  }
18019
21428
  function pathToName(relPath) {
18020
21429
  const id = pathToId(relPath);
@@ -18771,6 +22180,7 @@ If \`.wai/specs/\` exists, the wairon SDD workflow is active; otherwise ignore i
18771
22180
  7. **Subprojects & Namespacing**: If a subsystem uses \`projectPath\` delegation, target its specs using namespaced IDs (e.g. \`subsystem::component\`). Use leading \`::\` to target root (e.g. \`::shared::type\`) and \`super::\` to go up a level (e.g. \`super::sibling\`). wairon automatically resolves the path and strips the prefix on writes.`;
18772
22181
 
18773
22182
  // src/core/context.ts
22183
+ init_domains();
18774
22184
  function contextDir(...segments) {
18775
22185
  return aiDir("context", ...segments);
18776
22186
  }
@@ -18800,15 +22210,12 @@ function writeArchitectureContext(content) {
18800
22210
  writeFile(CONTEXT_PATHS.architectureMd(), content);
18801
22211
  }
18802
22212
  function renderDomainsDoc() {
18803
- const { resolveDomains: resolveDomains2 } = (init_domains(), __toCommonJS(domains_exports));
18804
- const domains = resolveDomains2();
18805
- const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
22213
+ const domains = resolveDomains();
18806
22214
  const lines = [
18807
22215
  versionStamp(),
18808
22216
  `# Domains`,
18809
22217
  ``,
18810
22218
  `> Auto-generated by wairon. The human developer rebuilds this with \`wairon generate\`. `,
18811
- `> Last updated: ${today}`,
18812
22219
  ``
18813
22220
  ];
18814
22221
  if (domains.length === 0) {
@@ -18911,6 +22318,157 @@ function syncContextFiles() {
18911
22318
  init_surfaces();
18912
22319
  init_openapi();
18913
22320
  init_packstore();
22321
+
22322
+ // src/core/treetransfer.ts
22323
+ var fs16 = __toESM(require("fs"));
22324
+ var path22 = __toESM(require("path"));
22325
+ var sdkPortal = __toESM(require_dist());
22326
+ init_loader();
22327
+ init_fs();
22328
+ init_specs2();
22329
+ init_statehash();
22330
+ var STAGING_PREFIX = ".wai-staging-";
22331
+ var BACKUP_DIR = ".wai-backups";
22332
+ function buildTreeArchive2(roots, projectName, stateId, includeDerived) {
22333
+ return sdkPortal.buildTreeArchive(roots, projectName, stateId, includeDerived);
22334
+ }
22335
+ function inspectTreeArchive2(archive) {
22336
+ return sdkPortal.inspectTreeArchive(archive);
22337
+ }
22338
+ function extractTreeArchive2(archive, destDir, refuseExecutableEntries) {
22339
+ const limits = void 0;
22340
+ return sdkPortal.extractTreeArchive(archive, destDir, limits, refuseExecutableEntries);
22341
+ }
22342
+ function hasSpecTree(root) {
22343
+ if (pathExists(aiPathsAt(root).projectConfig())) {
22344
+ return true;
22345
+ }
22346
+ return false;
22347
+ }
22348
+ function hasAuthoredSpecs(root) {
22349
+ const paths = aiPathsAt(root);
22350
+ const specsDir = paths.specsDir();
22351
+ if (!pathExists(specsDir)) {
22352
+ return false;
22353
+ }
22354
+ const systemIndex = path22.resolve(paths.specsSystem());
22355
+ for (const file of listFilesRecursive(specsDir, ".yaml")) {
22356
+ if (path22.resolve(file) !== systemIndex) {
22357
+ return true;
22358
+ }
22359
+ }
22360
+ return false;
22361
+ }
22362
+ function createStagingDir(destDir) {
22363
+ const root = path22.resolve(destDir);
22364
+ fs16.mkdirSync(root, { recursive: true });
22365
+ const stagingDir = fs16.mkdtempSync(path22.join(root, STAGING_PREFIX));
22366
+ return stagingDir;
22367
+ }
22368
+ function commitStagedTree(stagingDir, destDir, roots, backupExisting) {
22369
+ const root = path22.resolve(destDir);
22370
+ const backupDir = path22.join(root, BACKUP_DIR, timestampSlug());
22371
+ let backedUp = false;
22372
+ for (const rootRel of roots) {
22373
+ const relative8 = rootRel === "." ? "" : rootRel;
22374
+ const stagedSpecDir = path22.join(stagingDir, relative8, ".wai");
22375
+ if (!fs16.existsSync(stagedSpecDir)) continue;
22376
+ const liveSpecDir = liveSpecDirFor(path22.join(root, relative8));
22377
+ if (backupExisting && liveSpecDir && fs16.existsSync(liveSpecDir)) {
22378
+ const backupTarget = path22.join(backupDir, relative8, path22.basename(liveSpecDir));
22379
+ fs16.mkdirSync(path22.dirname(backupTarget), { recursive: true });
22380
+ fs16.renameSync(liveSpecDir, backupTarget);
22381
+ backedUp = true;
22382
+ } else if (liveSpecDir && fs16.existsSync(liveSpecDir)) {
22383
+ fs16.rmSync(liveSpecDir, { recursive: true, force: true });
22384
+ }
22385
+ const target = path22.join(root, relative8, ".wai");
22386
+ fs16.mkdirSync(path22.dirname(target), { recursive: true });
22387
+ if (fs16.existsSync(target)) fs16.rmSync(target, { recursive: true, force: true });
22388
+ fs16.renameSync(stagedSpecDir, target);
22389
+ }
22390
+ if (backedUp) {
22391
+ return backupDir;
22392
+ }
22393
+ return "";
22394
+ }
22395
+ function discardStagingDir(stagingDir) {
22396
+ try {
22397
+ fs16.rmSync(stagingDir, { recursive: true, force: true });
22398
+ } catch {
22399
+ }
22400
+ }
22401
+ function exportSpecTree(includeDerived) {
22402
+ const system = loadSystemSpec();
22403
+ if (!system) {
22404
+ throw new Error("no spec tree to export at this project root");
22405
+ }
22406
+ const chained = listChainedRoots();
22407
+ const root = getProjectRoot();
22408
+ const candidates = [
22409
+ { relativePath: ".", waiDir: aiPathsAt(root).root() },
22410
+ ...chained.map((rel2) => ({ relativePath: rel2, waiDir: aiPathsAt(path22.resolve(root, rel2)).root() }))
22411
+ ];
22412
+ const roots = candidates.filter((source) => pathExists(source.waiDir));
22413
+ const stateId = computeStateId();
22414
+ const built = buildTreeArchive2(roots, system.name, stateId.digest, includeDerived);
22415
+ const result = {
22416
+ archive: built.archive,
22417
+ suggestedFileName: built.suggestedFileName,
22418
+ projectName: built.manifest.projectName,
22419
+ roots: built.manifest.roots,
22420
+ fileCount: built.fileCount,
22421
+ stateId: stateId.digest
22422
+ };
22423
+ return result;
22424
+ }
22425
+ function importSpecTree(archive, options) {
22426
+ const info = inspectTreeArchive2(archive);
22427
+ if (!info.compatible) {
22428
+ throw new Error("incompatible .waitree archive (format or minimum wairon version)");
22429
+ }
22430
+ const destDir = path22.resolve(options.destDir ?? getProjectRoot());
22431
+ const occupied = hasSpecTree(destDir);
22432
+ const authored = hasAuthoredSpecs(destDir);
22433
+ if (authored && options.replaceExisting !== true) {
22434
+ throw new Error(
22435
+ "the destination already holds an authored spec tree; pass replaceExisting to move it aside and import over it"
22436
+ );
22437
+ }
22438
+ const stagingDir = createStagingDir(destDir);
22439
+ let extraction;
22440
+ try {
22441
+ extraction = extractTreeArchive2(archive, stagingDir, options.refuseExecutableEntries);
22442
+ } catch (err) {
22443
+ discardStagingDir(stagingDir);
22444
+ throw err;
22445
+ }
22446
+ const backupPath = commitStagedTree(stagingDir, destDir, extraction.roots, occupied);
22447
+ discardStagingDir(stagingDir);
22448
+ invalidateSpecCache();
22449
+ const result = {
22450
+ destDir,
22451
+ projectName: extraction.manifest.projectName,
22452
+ roots: extraction.roots,
22453
+ fileCount: extraction.writtenPaths.length,
22454
+ replaced: occupied
22455
+ };
22456
+ if (backupPath) result.backupPath = backupPath;
22457
+ if (extraction.manifest.stateId) result.stateId = extraction.manifest.stateId;
22458
+ return result;
22459
+ }
22460
+ function liveSpecDirFor(rootDir) {
22461
+ const modern = path22.join(rootDir, ".wai");
22462
+ if (fs16.existsSync(modern)) return modern;
22463
+ const legacy = path22.join(rootDir, ".wairon");
22464
+ if (fs16.existsSync(legacy)) return legacy;
22465
+ return null;
22466
+ }
22467
+ function timestampSlug() {
22468
+ return (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
22469
+ }
22470
+
22471
+ // src/core/index.ts
18914
22472
  init_extensions();
18915
22473
  init_agent_resolver();
18916
22474
 
@@ -18919,7 +22477,7 @@ var WAIRON_MANAGED_MARKER = "wairon:managed";
18919
22477
  var WAIRON_MANAGED_BANNER = `<!-- ${WAIRON_MANAGED_MARKER} \u2014 generated by \`wairon generate\`; do not edit, changes are overwritten -->`;
18920
22478
 
18921
22479
  // src/exporters/claude.ts
18922
- var path22 = __toESM(require("path"));
22480
+ var path23 = __toESM(require("path"));
18923
22481
  init_fs();
18924
22482
  var ClaudeExporter = class {
18925
22483
  constructor() {
@@ -18928,7 +22486,7 @@ var ClaudeExporter = class {
18928
22486
  outputPath(ctx) {
18929
22487
  const { agent, target, projectRoot } = ctx;
18930
22488
  const outputDir = "outputDir" in target ? target.outputDir : ".claude/agents";
18931
- return path22.resolve(projectRoot, outputDir, `${agent.id.replace(/::/g, "--")}.md`);
22489
+ return path23.resolve(projectRoot, outputDir, `${agent.id.replace(/::/g, "--")}.md`);
18932
22490
  }
18933
22491
  export(ctx) {
18934
22492
  const { agent, renderedInstructions } = ctx;
@@ -18949,7 +22507,7 @@ var ClaudeExporter = class {
18949
22507
  };
18950
22508
 
18951
22509
  // src/exporters/custom.ts
18952
- var path23 = __toESM(require("path"));
22510
+ var path24 = __toESM(require("path"));
18953
22511
  init_fs();
18954
22512
  var CustomExporter = class {
18955
22513
  constructor() {
@@ -18960,7 +22518,7 @@ var CustomExporter = class {
18960
22518
  if (!("outputDir" in target)) {
18961
22519
  throw new Error("CustomExporter requires target.outputDir");
18962
22520
  }
18963
- return path23.resolve(projectRoot, target.outputDir, `${agent.id.replace(/::/g, "--")}.md`);
22521
+ return path24.resolve(projectRoot, target.outputDir, `${agent.id.replace(/::/g, "--")}.md`);
18964
22522
  }
18965
22523
  export(ctx) {
18966
22524
  const { agent, target, renderedInstructions } = ctx;
@@ -18983,7 +22541,7 @@ var CustomExporter = class {
18983
22541
  };
18984
22542
 
18985
22543
  // src/exporters/gemini.ts
18986
- var path24 = __toESM(require("path"));
22544
+ var path25 = __toESM(require("path"));
18987
22545
  init_fs();
18988
22546
  var GeminiExporter = class {
18989
22547
  constructor() {
@@ -18992,7 +22550,7 @@ var GeminiExporter = class {
18992
22550
  outputPath(ctx) {
18993
22551
  const { agent, target, projectRoot } = ctx;
18994
22552
  const outputDir = "outputDir" in target ? target.outputDir : ".gemini/agents";
18995
- return path24.resolve(projectRoot, outputDir, `${agent.id.replace(/::/g, "--")}.yaml`);
22553
+ return path25.resolve(projectRoot, outputDir, `${agent.id.replace(/::/g, "--")}.yaml`);
18996
22554
  }
18997
22555
  export(ctx) {
18998
22556
  const { agent, renderedInstructions } = ctx;
@@ -19017,7 +22575,7 @@ function yamlString(value) {
19017
22575
  }
19018
22576
 
19019
22577
  // src/exporters/generate.ts
19020
- var path25 = __toESM(require("path"));
22578
+ var path26 = __toESM(require("path"));
19021
22579
  init_fs();
19022
22580
 
19023
22581
  // src/exporters/registry.ts
@@ -19084,7 +22642,7 @@ function resolveExpectedOutputPaths(agents, projectConfig, projectRoot = getProj
19084
22642
  const targetConfig = resolveTargetConfig(agentTarget, projectConfig);
19085
22643
  if (!targetConfig) continue;
19086
22644
  const ctx = { agent, projectRoot, target: targetConfig };
19087
- expected.add(path25.resolve(getExporter(targetConfig).outputPath(ctx)));
22645
+ expected.add(path26.resolve(getExporter(targetConfig).outputPath(ctx)));
19088
22646
  }
19089
22647
  }
19090
22648
  return expected;
@@ -19298,10 +22856,12 @@ init_yaml();
19298
22856
  buildProjectGraph,
19299
22857
  buildRuleContext,
19300
22858
  buildServerInstructions,
22859
+ buildTreeArchive,
19301
22860
  checkChildSurfaceFreshness,
19302
22861
  checkSkillFreshness,
19303
22862
  clearLoaderIssues,
19304
22863
  collectPromotableSpecs,
22864
+ commitStagedTree,
19305
22865
  composeAgentBrief,
19306
22866
  composeRuleSequence,
19307
22867
  composeVariantGuidance,
@@ -19315,6 +22875,7 @@ init_yaml();
19315
22875
  createChainedSubsystem,
19316
22876
  createEmptyRegistry,
19317
22877
  createEmptyTopologyConfig,
22878
+ createStagingDir,
19318
22879
  defaultPackSelections,
19319
22880
  defaultTargetConfig,
19320
22881
  deleteComponentSpec,
@@ -19327,15 +22888,18 @@ init_yaml();
19327
22888
  detectDomainCandidates,
19328
22889
  diagnoseProjectPacks,
19329
22890
  diagramSetIndex,
22891
+ discardStagingDir,
19330
22892
  discoverPacks,
19331
22893
  dryRunSerializeSpecs,
19332
22894
  emptyExtensions,
19333
22895
  ensureDir,
19334
22896
  ensureProjectInitialized,
19335
22897
  exportSddSkills,
22898
+ exportSpecTree,
19336
22899
  exportSurface,
19337
22900
  externalizeSubsystem,
19338
22901
  extractGenericTypeVariables,
22902
+ extractTreeArchive,
19339
22903
  extractTypeGenerics,
19340
22904
  extractTypeIdentifiers,
19341
22905
  extractTypesFromSignature,
@@ -19371,14 +22935,19 @@ init_yaml();
19371
22935
  globalTemplatesDir,
19372
22936
  globalVariantsDir,
19373
22937
  hasArchitectureContext,
22938
+ hasAuthoredSpecs,
19374
22939
  hasContext,
22940
+ hasSpecTree,
19375
22941
  hashGateState,
22942
+ importSpecTree,
19376
22943
  importSurface,
22944
+ inspectTreeArchive,
19377
22945
  installPackFromDirectory,
19378
22946
  internalizeSubsystem,
19379
22947
  invalidateSpecCache,
19380
22948
  isOpenApiDocument,
19381
22949
  isProjectInitialized,
22950
+ listChainedRoots,
19382
22951
  listDirectChainedSubprojects,
19383
22952
  listExternalInterfaces,
19384
22953
  listFiles,