@lucern/mcp 0.3.0-alpha.0 → 0.3.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/runtime.js CHANGED
@@ -2,7 +2,8 @@ import * as fs from 'fs';
2
2
  import * as path2 from 'path';
3
3
  import { basename, extname } from 'path';
4
4
  import { z } from 'zod';
5
- import { internal, components, api as api$1 } from '@lucern/reasoning-kernel/_generated/api';
5
+ import { v } from 'convex/values';
6
+ import { internal, components, api as api$1 } from '@lucern/reasoning-kernel/adapters/convex';
6
7
  import 'stream';
7
8
  import { AsyncLocalStorage } from 'async_hooks';
8
9
  import { ConvexHttpClient } from 'convex/browser';
@@ -609,6 +610,28 @@ defineTable({
609
610
  { kind: "index", name: "by_createdAt", columns: ["createdAt"] }
610
611
  ]
611
612
  });
613
+ defineTable({
614
+ name: "neo4jSyncQueue",
615
+ component: "kernel",
616
+ category: "infra",
617
+ shape: z.object({
618
+ "entityType": z.enum(["node", "edge"]),
619
+ "entityId": z.string(),
620
+ "operation": z.enum(["upsert", "delete"]),
621
+ "attempts": z.number(),
622
+ "maxAttempts": z.number(),
623
+ "lastAttemptAt": z.number().optional(),
624
+ "lastError": z.string().optional(),
625
+ "status": z.enum(["pending", "in_progress", "failed", "succeeded"]),
626
+ "createdAt": z.number(),
627
+ "updatedAt": z.number()
628
+ }),
629
+ indices: [
630
+ { kind: "index", name: "by_status", columns: ["status"] },
631
+ { kind: "index", name: "by_entity", columns: ["entityType", "entityId"] },
632
+ { kind: "index", name: "by_status_attempts", columns: ["status", "attempts"] }
633
+ ]
634
+ });
612
635
  defineTable({
613
636
  name: "backgroundJobRuns",
614
637
  component: "kernel",
@@ -678,9 +701,9 @@ defineTable({
678
701
  category: "epistemic",
679
702
  shape: z.object({
680
703
  "beliefId": z.string(),
681
- "belief": z.number().optional(),
682
- "disbelief": z.number().optional(),
683
- "uncertainty": z.number().optional(),
704
+ "belief": z.number(),
705
+ "disbelief": z.number(),
706
+ "uncertainty": z.number(),
684
707
  "baseRate": z.number(),
685
708
  "slOperator": z.string().optional(),
686
709
  "confidence": z.number(),
@@ -689,10 +712,12 @@ defineTable({
689
712
  "certainty": z.number().optional(),
690
713
  "assessedAt": z.number(),
691
714
  "assessedBy": z.string(),
692
- "trigger": z.enum(["initial", "evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "manual", "decay", "propagation", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction", "backfill_synthetic"]),
715
+ "trigger": z.enum(["initial", "evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "propagation", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction", "backfill_synthetic"]),
693
716
  "rationale": z.string().optional(),
694
717
  "triggeringEvidenceId": z.string().optional(),
695
718
  "triggeringEvidenceIds": z.array(z.string()).optional(),
719
+ "triggeringQuestionId": z.string().optional(),
720
+ "triggeringAnswerId": z.string().optional(),
696
721
  "triggeringContradictionId": idOf("contradictions").optional(),
697
722
  "triggeringWorktreeId": z.string().optional(),
698
723
  "triggeringAgentId": z.string().optional(),
@@ -1375,7 +1400,7 @@ defineTable({
1375
1400
  "credentialRef": z.string(),
1376
1401
  "tenantId": idOf("tenants"),
1377
1402
  "target": z.enum(["kernelDeployment", "appDeployment"]),
1378
- "environment": z.enum(["dev", "prod"]),
1403
+ "environment": z.enum(["dev", "staging", "prod"]),
1379
1404
  "encryptedDeployKey": z.string(),
1380
1405
  "encryptionVersion": z.string(),
1381
1406
  "keyFingerprint": z.string(),
@@ -4044,13 +4069,13 @@ defineTable({
4044
4069
  "rationale": z.string().optional(),
4045
4070
  "confidenceImpact": z.enum(["high", "medium", "low"]).optional(),
4046
4071
  "hypothesis": z.string().optional(),
4047
- "executionOrder": z.number().optional(),
4048
4072
  "dependsOn": z.array(idOf("worktrees")).optional(),
4049
4073
  "blocks": z.array(idOf("worktrees")).optional(),
4050
4074
  "gate": z.string().optional(),
4051
- "track": z.string().optional(),
4052
- "trackPosition": z.number().optional(),
4053
- "executionBand": z.number().optional(),
4075
+ "campaign": z.number().optional(),
4076
+ "lane": z.string().optional(),
4077
+ "laneOrderInCampaign": z.number().optional(),
4078
+ "orderInLane": z.number().optional(),
4054
4079
  "startDate": z.number(),
4055
4080
  "endDate": z.number(),
4056
4081
  "durationWeeks": z.number(),
@@ -4298,10 +4323,469 @@ defineTable({
4298
4323
  { kind: "index", name: "by_topicId_index", columns: ["topicId", "index"] },
4299
4324
  { kind: "index", name: "by_worktreeType", columns: ["topicId", "worktreeType"] },
4300
4325
  { kind: "index", name: "by_topicId_priority", columns: ["topicId", "priority"] },
4326
+ { kind: "index", name: "by_topicId_campaign_lane_order", columns: ["topicId", "campaign", "laneOrderInCampaign", "orderInLane"] },
4327
+ { kind: "index", name: "by_topicId_lane_order", columns: ["topicId", "lane", "orderInLane"] },
4301
4328
  { kind: "index", name: "by_topicId_branch", columns: ["topicId", "targetBranch"] },
4302
4329
  { kind: "index", name: "by_topicId_scope", columns: ["topicId", "worktreeScope"] }
4303
4330
  ]
4304
4331
  });
4332
+ z.object({
4333
+ manifestVersion: z.string(),
4334
+ componentName: z.enum(["kernel", "identity"]),
4335
+ tier: z.enum(["K", "I"]),
4336
+ packageVersion: z.string(),
4337
+ tables: z.array(
4338
+ z.object({
4339
+ name: z.string(),
4340
+ fields: z.array(
4341
+ z.object({
4342
+ name: z.string(),
4343
+ type: z.string(),
4344
+ optional: z.boolean(),
4345
+ validator: z.string().optional()
4346
+ })
4347
+ )
4348
+ })
4349
+ )
4350
+ });
4351
+ var SL_EPSILON = 1e-9;
4352
+ z.object({
4353
+ belief: z.number(),
4354
+ disbelief: z.number(),
4355
+ uncertainty: z.number(),
4356
+ baseRate: z.number()
4357
+ }).refine(
4358
+ (o) => Math.abs(o.belief + o.disbelief + o.uncertainty - 1) < SL_EPSILON,
4359
+ {
4360
+ message: "SL invariant b+d+u=1 violated at API boundary"
4361
+ }
4362
+ );
4363
+ var EpistemicNodeTypeSchema = z.enum([
4364
+ "belief",
4365
+ "evidence",
4366
+ "question",
4367
+ "answer",
4368
+ "topic",
4369
+ "edge",
4370
+ "ontology",
4371
+ "lens",
4372
+ "contradiction"
4373
+ ]);
4374
+ var GraphRefSchema = z.discriminatedUnion("kind", [
4375
+ z.object({
4376
+ kind: z.literal("epistemic_node"),
4377
+ nodeId: z.string(),
4378
+ nodeType: EpistemicNodeTypeSchema
4379
+ }),
4380
+ z.object({
4381
+ kind: z.literal("external_belief"),
4382
+ ref: z.object({
4383
+ tenantId: z.string(),
4384
+ beliefId: z.string()
4385
+ })
4386
+ })
4387
+ ]);
4388
+ var graphRefKind = z.enum(["epistemic_node", "external_belief"]);
4389
+ var EdgePolicyEntrySchema = z.object({
4390
+ edgeType: z.string(),
4391
+ fromKinds: z.array(graphRefKind),
4392
+ fromNodeTypes: z.array(EpistemicNodeTypeSchema).optional(),
4393
+ toKinds: z.array(graphRefKind),
4394
+ toNodeTypes: z.array(EpistemicNodeTypeSchema).optional(),
4395
+ description: z.string()
4396
+ });
4397
+ z.object({
4398
+ manifestVersion: z.literal("1.0.0"),
4399
+ policies: z.array(EdgePolicyEntrySchema)
4400
+ });
4401
+ function findEdgePolicy(manifest, edgeType) {
4402
+ return manifest.policies.find((policy) => policy.edgeType === edgeType);
4403
+ }
4404
+ function nodeTypeAllowed(allowed, ref) {
4405
+ return ref.kind !== "epistemic_node" || !allowed || allowed.includes(ref.nodeType);
4406
+ }
4407
+ function assertEdgePolicyAllowed(manifest, edgeType, from, to) {
4408
+ const policy = findEdgePolicy(manifest, edgeType);
4409
+ const allowed = Boolean(policy) && policy.fromKinds.includes(from.kind) && policy.toKinds.includes(to.kind) && nodeTypeAllowed(policy.fromNodeTypes, from) && nodeTypeAllowed(policy.toNodeTypes, to);
4410
+ if (!allowed) {
4411
+ const error = new Error(
4412
+ `Edge policy violation for ${edgeType}: ${from.kind} -> ${to.kind}`
4413
+ );
4414
+ error.code = "POLICY_VIOLATION";
4415
+ error.details = { code: "POLICY_VIOLATION", edgeType, from, to };
4416
+ throw error;
4417
+ }
4418
+ }
4419
+
4420
+ // ../contracts/src/manifests/edge-policy-manifest.data.ts
4421
+ var edgePolicyManifest = {
4422
+ policies: [
4423
+ {
4424
+ edgeType: "evidence_derived_from_evidence",
4425
+ fromKinds: ["epistemic_node"],
4426
+ fromNodeTypes: ["evidence"],
4427
+ toKinds: ["epistemic_node"],
4428
+ toNodeTypes: ["evidence"],
4429
+ description: "Evidence E2 was synthesized from evidence E1 by a transformation. Provides chain-of-evidence lineage."
4430
+ },
4431
+ {
4432
+ edgeType: "evidence_supports_belief",
4433
+ fromKinds: ["epistemic_node"],
4434
+ fromNodeTypes: ["evidence"],
4435
+ toKinds: ["epistemic_node"],
4436
+ toNodeTypes: ["belief"],
4437
+ description: "Existing link_evidence_to_belief semantics promoted to the create_edge policy source."
4438
+ },
4439
+ {
4440
+ edgeType: "evidence_supports_question",
4441
+ fromKinds: ["epistemic_node"],
4442
+ fromNodeTypes: ["evidence"],
4443
+ toKinds: ["epistemic_node"],
4444
+ toNodeTypes: ["question"],
4445
+ description: "Existing link_evidence_to_question semantics promoted to the create_edge policy source."
4446
+ }
4447
+ ]
4448
+ };
4449
+ z.object({
4450
+ manifestVersion: z.literal("1.0.0"),
4451
+ rules: z.array(
4452
+ z.object({
4453
+ invariant: z.string(),
4454
+ description: z.string(),
4455
+ checker: z.enum(["ast", "manifest", "runtime"]),
4456
+ severity: z.enum(["block_publish", "block_pr", "warn"])
4457
+ })
4458
+ )
4459
+ });
4460
+
4461
+ // ../contracts/src/projections/projection-dsl.ts
4462
+ function defineProjection(def) {
4463
+ return def;
4464
+ }
4465
+
4466
+ // ../contracts/src/projections/create-evidence.projection.ts
4467
+ var jsonRecordSchema = z.record(z.unknown());
4468
+ var createEvidenceInputSchemaBase = z.object({
4469
+ projectId: z.string().optional(),
4470
+ topicId: z.string().optional(),
4471
+ text: z.string().optional(),
4472
+ canonicalText: z.string().optional(),
4473
+ title: z.string().optional(),
4474
+ content: z.string().optional(),
4475
+ contentType: z.string().optional(),
4476
+ kind: z.string().optional(),
4477
+ tags: z.array(z.string()).optional(),
4478
+ source: z.string().optional(),
4479
+ sourceUrl: z.string().optional(),
4480
+ sourceType: z.string().optional(),
4481
+ externalSourceType: z.string().optional(),
4482
+ sourceQuestionId: z.string().optional(),
4483
+ methodology: z.string().optional(),
4484
+ informationAsymmetry: z.string().optional(),
4485
+ sourceDescription: z.string().optional(),
4486
+ targetId: z.string().optional(),
4487
+ targetNodeId: z.string().optional(),
4488
+ linkedBeliefNodeId: z.string().optional(),
4489
+ evidenceRelation: z.enum(["supports", "contradicts", "neutral"]).optional(),
4490
+ confidence: z.number().optional(),
4491
+ weight: z.number().optional(),
4492
+ reasoning: z.string().optional(),
4493
+ rationale: z.string(),
4494
+ metadata: jsonRecordSchema.optional(),
4495
+ trustedBypassAccessCheck: z.boolean().optional()
4496
+ }).passthrough();
4497
+ var createEvidenceInputSchema = createEvidenceInputSchemaBase.refine(
4498
+ (input) => Boolean(input.text ?? input.canonicalText),
4499
+ {
4500
+ message: "create_evidence requires text",
4501
+ path: ["text"]
4502
+ }
4503
+ );
4504
+ function compactRecord(input) {
4505
+ return Object.fromEntries(
4506
+ Object.entries(input).filter(([, value]) => value !== void 0)
4507
+ );
4508
+ }
4509
+ function recordValue(value) {
4510
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
4511
+ }
4512
+ var createEvidenceProjection = defineProjection({
4513
+ contractName: "create_evidence",
4514
+ inputSchema: createEvidenceInputSchema,
4515
+ project: (input) => {
4516
+ const text = input.text ?? input.canonicalText;
4517
+ const weight = typeof input.weight === "number" ? input.weight : void 0;
4518
+ return compactRecord({
4519
+ projectId: input.projectId,
4520
+ topicId: input.topicId,
4521
+ text,
4522
+ title: input.title ?? text,
4523
+ content: input.content ?? text,
4524
+ contentType: input.contentType,
4525
+ kind: input.kind,
4526
+ tags: input.tags,
4527
+ sourceType: input.sourceType,
4528
+ externalSourceType: input.externalSourceType,
4529
+ sourceUrl: input.sourceUrl ?? input.source,
4530
+ sourceQuestionId: input.sourceQuestionId,
4531
+ methodology: input.methodology,
4532
+ informationAsymmetry: input.informationAsymmetry,
4533
+ sourceDescription: input.sourceDescription,
4534
+ metadata: compactRecord({
4535
+ ...recordValue(input.metadata),
4536
+ source: input.source,
4537
+ targetId: input.targetId,
4538
+ targetNodeId: input.targetNodeId,
4539
+ weight,
4540
+ reasoning: input.reasoning,
4541
+ rationale: input.rationale
4542
+ }),
4543
+ linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
4544
+ evidenceRelation: input.evidenceRelation ?? (weight === void 0 ? void 0 : weight < 0 ? "contradicts" : "supports"),
4545
+ confidence: input.confidence ?? (weight === void 0 ? void 0 : Math.min(1, Math.max(0, Math.abs(weight)))),
4546
+ rationale: input.rationale,
4547
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
4548
+ });
4549
+ },
4550
+ convexArgsValidator: v.object({
4551
+ projectId: v.optional(v.string()),
4552
+ topicId: v.optional(v.string()),
4553
+ text: v.string(),
4554
+ title: v.optional(v.string()),
4555
+ content: v.optional(v.string()),
4556
+ contentType: v.optional(v.string()),
4557
+ kind: v.optional(v.string()),
4558
+ tags: v.optional(v.array(v.string())),
4559
+ sourceType: v.optional(v.string()),
4560
+ externalSourceType: v.optional(v.string()),
4561
+ sourceUrl: v.optional(v.string()),
4562
+ sourceQuestionId: v.optional(v.string()),
4563
+ methodology: v.optional(v.string()),
4564
+ informationAsymmetry: v.optional(v.string()),
4565
+ sourceDescription: v.optional(v.string()),
4566
+ metadata: v.optional(v.record(v.string(), v.any())),
4567
+ linkedBeliefNodeId: v.optional(v.string()),
4568
+ evidenceRelation: v.optional(
4569
+ v.union(
4570
+ v.literal("supports"),
4571
+ v.literal("contradicts"),
4572
+ v.literal("neutral")
4573
+ )
4574
+ ),
4575
+ confidence: v.optional(v.number()),
4576
+ rationale: v.string(),
4577
+ trustedBypassAccessCheck: v.optional(v.boolean())
4578
+ })
4579
+ });
4580
+ var beliefStatusSchema = z.enum(["active", "superseded", "archived", "unscored", "scored"]).optional().describe("Filter by belief lifecycle or scoring status");
4581
+ var listBeliefsInputSchema = z.object({
4582
+ topicId: z.string().describe("Topic scope"),
4583
+ worktreeId: z.string().optional().describe("Filter to worktree scope"),
4584
+ status: beliefStatusSchema,
4585
+ minConfidence: z.number().optional().describe("Minimum confidence threshold"),
4586
+ limit: z.number().optional().describe("Maximum results"),
4587
+ includeEdgeAssociated: z.boolean().optional().describe("Include beliefs associated to the topic through edges")
4588
+ });
4589
+ function kernelStatus(status) {
4590
+ return status === "active" || status === "superseded" || status === "archived" ? status : void 0;
4591
+ }
4592
+ function compactRecord2(input) {
4593
+ return Object.fromEntries(
4594
+ Object.entries(input).filter(([, value]) => value !== void 0)
4595
+ );
4596
+ }
4597
+ var listBeliefsProjection = defineProjection({
4598
+ contractName: "list_beliefs",
4599
+ inputSchema: listBeliefsInputSchema,
4600
+ project: (input) => compactRecord2({
4601
+ topicId: input.topicId,
4602
+ status: kernelStatus(input.status),
4603
+ limit: input.limit,
4604
+ includeEdgeAssociated: input.includeEdgeAssociated
4605
+ }),
4606
+ convexArgsValidator: v.object({
4607
+ topicId: v.string(),
4608
+ status: v.optional(
4609
+ v.union(
4610
+ v.literal("active"),
4611
+ v.literal("superseded"),
4612
+ v.literal("archived")
4613
+ )
4614
+ ),
4615
+ limit: v.optional(v.number()),
4616
+ includeEdgeAssociated: v.optional(v.boolean())
4617
+ })
4618
+ });
4619
+ var taskStatusSchema = z.enum(["todo", "in_progress", "blocked", "done"]).optional().describe("Filter by task status");
4620
+ var listTasksInputSchema = z.object({
4621
+ topicId: z.string().describe("Topic scope"),
4622
+ worktreeId: z.string().optional().describe("Alias for linkedWorktreeId"),
4623
+ linkedWorktreeId: z.string().optional().describe("Filter to tasks linked to this worktree"),
4624
+ status: taskStatusSchema,
4625
+ limit: z.number().optional().describe("Maximum results")
4626
+ });
4627
+ function compactRecord3(input) {
4628
+ return Object.fromEntries(
4629
+ Object.entries(input).filter(([, value]) => value !== void 0)
4630
+ );
4631
+ }
4632
+ var listTasksProjection = defineProjection({
4633
+ contractName: "list_tasks",
4634
+ inputSchema: listTasksInputSchema,
4635
+ project: (input) => compactRecord3({
4636
+ topicId: input.topicId,
4637
+ status: input.status,
4638
+ userId: void 0,
4639
+ limit: input.limit,
4640
+ linkedWorktreeId: input.linkedWorktreeId ?? input.worktreeId
4641
+ }),
4642
+ convexArgsValidator: v.object({
4643
+ topicId: v.string(),
4644
+ status: v.optional(
4645
+ v.union(
4646
+ v.literal("todo"),
4647
+ v.literal("in_progress"),
4648
+ v.literal("blocked"),
4649
+ v.literal("done")
4650
+ )
4651
+ ),
4652
+ limit: v.optional(v.number()),
4653
+ linkedWorktreeId: v.optional(v.string())
4654
+ })
4655
+ });
4656
+ var confidenceTriggerSchema = z.enum([
4657
+ "evidence_added",
4658
+ "evidence_removed",
4659
+ "contradiction_resolved",
4660
+ "agent_assessment",
4661
+ "worktree_outcome",
4662
+ "worktree_completed",
4663
+ "contradiction_detected",
4664
+ "answer_recorded",
4665
+ "fusion",
4666
+ "discount",
4667
+ "deduction",
4668
+ "backfill_synthetic"
4669
+ ]);
4670
+ var provenanceSchema = z.object({
4671
+ evidence: z.string().optional(),
4672
+ question: z.string().optional(),
4673
+ answer: z.string().optional(),
4674
+ contradiction: z.string().optional(),
4675
+ worktree: z.string().optional()
4676
+ });
4677
+ var slOpinionProjectionSchema = z.object({
4678
+ belief: z.number(),
4679
+ disbelief: z.number(),
4680
+ uncertainty: z.number(),
4681
+ baseRate: z.number()
4682
+ });
4683
+ var modulateConfidenceInputObjectSchema = z.object({
4684
+ nodeId: z.string().optional(),
4685
+ beliefNodeId: z.string().optional(),
4686
+ worktreeId: z.string().optional(),
4687
+ opinion: slOpinionProjectionSchema.optional(),
4688
+ belief: z.number().optional(),
4689
+ disbelief: z.number().optional(),
4690
+ uncertainty: z.number().optional(),
4691
+ baseRate: z.number().optional(),
4692
+ trigger: confidenceTriggerSchema,
4693
+ provenance: provenanceSchema.optional(),
4694
+ triggeringEvidenceId: z.string().optional(),
4695
+ triggeringQuestionId: z.string().optional(),
4696
+ triggeringAnswerId: z.string().optional(),
4697
+ triggeringContradictionId: z.string().optional(),
4698
+ triggeringWorktreeId: z.string().optional(),
4699
+ rationale: z.string(),
4700
+ trustedBypassAccessCheck: z.boolean().optional()
4701
+ });
4702
+ var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
4703
+ if (hasProvenance(input)) {
4704
+ return;
4705
+ }
4706
+ ctx.addIssue({
4707
+ code: z.ZodIssueCode.custom,
4708
+ message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
4709
+ path: ["provenance"]
4710
+ });
4711
+ });
4712
+ var modulateConfidenceProjection = defineProjection({
4713
+ contractName: "modulate_confidence",
4714
+ inputSchema: modulateConfidenceInputSchema,
4715
+ project: (input) => {
4716
+ const nodeId = input.beliefNodeId ?? input.nodeId;
4717
+ if (!nodeId) {
4718
+ throw new Error("modulate_confidence requires beliefNodeId or nodeId");
4719
+ }
4720
+ const opinion = input.opinion ?? {
4721
+ belief: requireNumber(input.belief, "belief"),
4722
+ disbelief: requireNumber(input.disbelief, "disbelief"),
4723
+ uncertainty: requireNumber(input.uncertainty, "uncertainty"),
4724
+ baseRate: requireNumber(input.baseRate, "baseRate")
4725
+ };
4726
+ assertProvenance(input);
4727
+ return {
4728
+ nodeId,
4729
+ worktreeId: input.worktreeId,
4730
+ belief: opinion.belief,
4731
+ disbelief: opinion.disbelief,
4732
+ uncertainty: opinion.uncertainty,
4733
+ baseRate: opinion.baseRate,
4734
+ trigger: input.trigger === "answer_recorded" ? "agent_assessment" : input.trigger,
4735
+ triggeringEvidenceId: input.provenance?.evidence ?? input.triggeringEvidenceId,
4736
+ triggeringQuestionId: input.provenance?.question ?? input.triggeringQuestionId,
4737
+ triggeringAnswerId: input.provenance?.answer ?? input.triggeringAnswerId,
4738
+ triggeringContradictionId: input.provenance?.contradiction ?? input.triggeringContradictionId,
4739
+ triggeringWorktreeId: input.provenance?.worktree ?? input.triggeringWorktreeId,
4740
+ rationale: input.rationale,
4741
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
4742
+ };
4743
+ },
4744
+ convexArgsValidator: v.object({
4745
+ nodeId: v.string(),
4746
+ worktreeId: v.optional(v.string()),
4747
+ belief: v.number(),
4748
+ disbelief: v.number(),
4749
+ uncertainty: v.number(),
4750
+ baseRate: v.number(),
4751
+ trigger: v.union(
4752
+ v.literal("evidence_added"),
4753
+ v.literal("evidence_removed"),
4754
+ v.literal("worktree_completed"),
4755
+ v.literal("contradiction_detected"),
4756
+ v.literal("contradiction_resolved"),
4757
+ v.literal("agent_assessment"),
4758
+ v.literal("worktree_outcome"),
4759
+ v.literal("fusion"),
4760
+ v.literal("discount"),
4761
+ v.literal("deduction"),
4762
+ v.literal("backfill_synthetic")
4763
+ ),
4764
+ triggeringEvidenceId: v.optional(v.string()),
4765
+ triggeringQuestionId: v.optional(v.string()),
4766
+ triggeringAnswerId: v.optional(v.string()),
4767
+ triggeringContradictionId: v.optional(v.string()),
4768
+ triggeringWorktreeId: v.optional(v.string()),
4769
+ rationale: v.string(),
4770
+ trustedBypassAccessCheck: v.optional(v.boolean())
4771
+ })
4772
+ });
4773
+ function requireNumber(value, field) {
4774
+ if (value === void 0) {
4775
+ throw new Error(`modulate_confidence requires ${field}`);
4776
+ }
4777
+ return value;
4778
+ }
4779
+ function assertProvenance(input) {
4780
+ if (!hasProvenance(input)) {
4781
+ throw new Error(
4782
+ "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
4783
+ );
4784
+ }
4785
+ }
4786
+ function hasProvenance(input) {
4787
+ return input.trigger === "backfill_synthetic" || Boolean(input.provenance && Object.values(input.provenance).some(Boolean)) || Boolean(input.triggeringEvidenceId) || Boolean(input.triggeringQuestionId) || Boolean(input.triggeringAnswerId) || Boolean(input.triggeringContradictionId) || Boolean(input.triggeringWorktreeId);
4788
+ }
4305
4789
 
4306
4790
  // ../contracts/src/lens-filter.contract.ts
4307
4791
  function isLensFilterCriteria(value) {
@@ -4383,7 +4867,7 @@ var LENS_PERSPECTIVE_TYPES = [
4383
4867
  // ../contracts/src/tool-contracts.ts
4384
4868
  var CREATE_BELIEF = {
4385
4869
  name: "create_belief",
4386
- description: "Commit a new belief (knowledge unit) to the reasoning graph. Like `git commit` \u2014 creates an atomic, traceable knowledge object with a mandatory prior. Creation stores the vacuous opinion `(0, 0, 1, a)`; use modulate_confidence to record the first evidential update.",
4870
+ description: "Commit a new belief (knowledge unit) to the reasoning graph. Like `git commit` \u2014 creates an atomic, traceable knowledge object with a prior. Creation stores the vacuous opinion `(0, 0, 1, a)`; use modulate_confidence to record the first evidential update.",
4387
4871
  parameters: {
4388
4872
  canonicalText: {
4389
4873
  type: "string",
@@ -4395,7 +4879,7 @@ var CREATE_BELIEF = {
4395
4879
  },
4396
4880
  baseRate: {
4397
4881
  type: "number",
4398
- description: "Required prior probability used to seed the vacuous opinion `(0, 0, 1, a)` at creation time."
4882
+ description: "Prior probability used to seed the vacuous opinion `(0, 0, 1, a)` at creation time. Defaults to 0.5 when omitted."
4399
4883
  },
4400
4884
  beliefType: {
4401
4885
  type: "string",
@@ -4406,7 +4890,7 @@ var CREATE_BELIEF = {
4406
4890
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'] } for coding intelligence)"
4407
4891
  }
4408
4892
  },
4409
- required: ["canonicalText", "baseRate"],
4893
+ required: ["canonicalText"],
4410
4894
  response: {
4411
4895
  description: "The created canonical belief record",
4412
4896
  fields: {
@@ -4469,7 +4953,7 @@ var REFINE_BELIEF = {
4469
4953
  };
4470
4954
  var MODULATE_CONFIDENCE = {
4471
4955
  name: "modulate_confidence",
4472
- description: "Record a confidence change for a belief. Like `git commit` to the credence log \u2014 an atomic, append-only write. Each modulation is a new entry in the history, not an overwrite. Scoring happens via merge; this tool records the individual data points. Pass the full subjective-logic tuple (`belief`, `disbelief`, `uncertainty`, `baseRate`) directly. If a caller only has a scalar probability, use `@lucern/sdk` helpers `opinionFromBaseRate`, `opinionFromDogmatic`, or `opinionFromProjected` to name the intended interpretation before calling this tool. Triggers: evidence_added, evidence_removed, contradiction_detected, contradiction_resolved, agent_assessment, worktree_outcome, worktree_completed, fusion, discount, deduction, manual, decay.",
4956
+ description: "Record a confidence change for a belief. Like `git commit` to the credence log \u2014 an atomic, append-only write. Each modulation is a new entry in the history, not an overwrite. Scoring happens via merge; this tool records the individual data points. Pass the full subjective-logic tuple (`belief`, `disbelief`, `uncertainty`, `baseRate`) directly. If a caller only has a scalar probability, use `@lucern/sdk` helpers `opinionFromBaseRate`, `opinionFromDogmatic`, or `opinionFromProjected` to name the intended interpretation before calling this tool. Every modulation must cite a truth-bearing artifact: triggeringEvidenceId, triggeringQuestionId, triggeringAnswerId, triggeringContradictionId, or triggeringWorktreeId. Triggers: evidence_added, evidence_removed, contradiction_detected, contradiction_resolved, agent_assessment, worktree_outcome, worktree_completed, fusion, discount, deduction.",
4473
4957
  parameters: {
4474
4958
  nodeId: { type: "string", description: "The belief to score" },
4475
4959
  belief: {
@@ -4488,9 +4972,9 @@ var MODULATE_CONFIDENCE = {
4488
4972
  type: "number",
4489
4973
  description: "Subjective-logic base rate `a` in [0, 1]. Required for tuple payloads."
4490
4974
  },
4491
- confidence: {
4492
- type: "number",
4493
- description: "Deprecated scalar confidence value in [0, 1]. Scalar-only payloads are rejected as AMBIGUOUS_SCALAR."
4975
+ worktreeId: {
4976
+ type: "string",
4977
+ description: "Completed worktree that tested this belief when confidence policy requires merge-backed scoring."
4494
4978
  },
4495
4979
  trigger: {
4496
4980
  type: "string",
@@ -4505,17 +4989,43 @@ var MODULATE_CONFIDENCE = {
4505
4989
  "worktree_completed",
4506
4990
  "fusion",
4507
4991
  "discount",
4508
- "deduction",
4509
- "manual",
4510
- "decay"
4992
+ "deduction"
4511
4993
  ]
4512
4994
  },
4995
+ triggeringEvidenceId: {
4996
+ type: "string",
4997
+ description: "Evidence node that caused an evidence-triggered modulation"
4998
+ },
4999
+ triggeringQuestionId: {
5000
+ type: "string",
5001
+ description: "Answered question whose resolution supports this modulation"
5002
+ },
5003
+ triggeringAnswerId: {
5004
+ type: "string",
5005
+ description: "Answer node whose content supports this modulation"
5006
+ },
5007
+ triggeringContradictionId: {
5008
+ type: "string",
5009
+ description: "Contradiction record that caused a contradiction-triggered modulation"
5010
+ },
5011
+ triggeringWorktreeId: {
5012
+ type: "string",
5013
+ description: "Completed worktree whose outcome caused a worktree-triggered modulation"
5014
+ },
4513
5015
  rationale: {
4514
5016
  type: "string",
4515
5017
  description: "Human-readable explanation of why confidence changed"
4516
5018
  }
4517
5019
  },
4518
- required: ["nodeId", "trigger", "rationale"],
5020
+ required: [
5021
+ "nodeId",
5022
+ "belief",
5023
+ "disbelief",
5024
+ "uncertainty",
5025
+ "baseRate",
5026
+ "trigger",
5027
+ "rationale"
5028
+ ],
4519
5029
  response: {
4520
5030
  description: "Confidence modulation result",
4521
5031
  fields: {
@@ -4709,7 +5219,7 @@ var ADD_EVIDENCE = {
4709
5219
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'], failedApproach: true } for coding intelligence)"
4710
5220
  }
4711
5221
  },
4712
- required: ["canonicalText", "targetNodeId"],
5222
+ required: ["canonicalText", "targetNodeId", "reasoning"],
4713
5223
  response: {
4714
5224
  description: "The created evidence node and its edge",
4715
5225
  fields: {
@@ -4790,9 +5300,21 @@ var ADD_WORKTREE = {
4790
5300
  type: "string",
4791
5301
  description: "Optional domain pack whose shaping hooks should influence generated questions and tasks"
4792
5302
  },
4793
- executionOrder: {
5303
+ campaign: {
5304
+ type: "number",
5305
+ description: "Top-level pipeline campaign number. Campaigns define the outer execution slice."
5306
+ },
5307
+ lane: {
5308
+ type: "string",
5309
+ description: "GitButler-aligned workstream lane name inside the campaign."
5310
+ },
5311
+ laneOrderInCampaign: {
5312
+ type: "number",
5313
+ description: "Ordering for this lane within its campaign."
5314
+ },
5315
+ orderInLane: {
4794
5316
  type: "number",
4795
- description: "Global execution order for this worktree"
5317
+ description: "Position of this worktree inside its lane."
4796
5318
  },
4797
5319
  dependsOn: {
4798
5320
  type: "array",
@@ -5450,6 +5972,10 @@ var CREATE_EVIDENCE = {
5450
5972
  type: "object",
5451
5973
  description: "Optional metadata merged into the canonical evidence node"
5452
5974
  },
5975
+ rationale: {
5976
+ type: "string",
5977
+ description: "Why this evidence should enter the reasoning graph"
5978
+ },
5453
5979
  title: { type: "string", description: "Optional short title" },
5454
5980
  content: { type: "string", description: "Optional long-form content" },
5455
5981
  contentType: {
@@ -5458,7 +5984,7 @@ var CREATE_EVIDENCE = {
5458
5984
  },
5459
5985
  kind: { type: "string", description: "Optional evidence kind" }
5460
5986
  },
5461
- required: ["text"],
5987
+ required: ["text", "rationale"],
5462
5988
  response: {
5463
5989
  description: "The created canonical evidence record",
5464
5990
  fields: {
@@ -5506,7 +6032,7 @@ var LIST_EVIDENCE = {
5506
6032
  limit: { type: "number", description: "Max results" },
5507
6033
  cursor: { type: "string", description: "Pagination cursor" }
5508
6034
  },
5509
- required: [],
6035
+ required: ["topicId"],
5510
6036
  response: {
5511
6037
  description: "Canonical evidence page",
5512
6038
  fields: {
@@ -5691,6 +6217,7 @@ var ANSWER_QUESTION = {
5691
6217
  description: "Answer a question with optional evidence links. Like `git commit` on the question thread \u2014 records the answer and closes the loop with a canonical answered state.",
5692
6218
  parameters: {
5693
6219
  id: { type: "string", description: "Canonical question ID" },
6220
+ topicId: { type: "string", description: "Topic scope for the answer" },
5694
6221
  text: { type: "string", description: "Answer text" },
5695
6222
  confidence: {
5696
6223
  type: "string",
@@ -5703,7 +6230,7 @@ var ANSWER_QUESTION = {
5703
6230
  },
5704
6231
  rationale: { type: "string", description: "Why this answer is credible" }
5705
6232
  },
5706
- required: ["id", "text"],
6233
+ required: ["id", "topicId", "text"],
5707
6234
  response: {
5708
6235
  description: "Answer result",
5709
6236
  fields: {
@@ -5922,6 +6449,10 @@ var LIST_BELIEFS = {
5922
6449
  minConfidence: {
5923
6450
  type: "number",
5924
6451
  description: "Minimum confidence threshold"
6452
+ },
6453
+ limit: {
6454
+ type: "number",
6455
+ description: "Maximum results"
5925
6456
  }
5926
6457
  },
5927
6458
  required: ["topicId"],
@@ -5938,20 +6469,37 @@ var LIST_BELIEFS = {
5938
6469
  };
5939
6470
  var LIST_WORKTREES = {
5940
6471
  name: "list_worktrees",
5941
- description: "List all worktrees for a topic. Like `git worktree list` \u2014 shows active and completed investigation branches with their phase, status, and belief counts.",
6472
+ description: "List all worktrees for a topic. Like `git worktree list` \u2014 shows active and completed investigation branches with lifecycle phase, pipeline campaign/lane, status, and belief counts.",
5942
6473
  parameters: {
5943
6474
  topicId: { type: "string", description: "Topic scope" },
5944
6475
  status: {
5945
6476
  type: "string",
5946
6477
  description: "Filter: active, merged, abandoned",
5947
6478
  enum: ["active", "merged", "abandoned"]
6479
+ },
6480
+ groupBy: {
6481
+ type: "string",
6482
+ description: "Optional grouping mode for the response.",
6483
+ enum: ["campaign", "lane", "flat"]
6484
+ },
6485
+ lane: {
6486
+ type: "string",
6487
+ description: "Filter by GitButler-aligned lane name."
6488
+ },
6489
+ campaign: {
6490
+ type: "number",
6491
+ description: "Filter by top-level pipeline campaign number."
6492
+ },
6493
+ limit: {
6494
+ type: "number",
6495
+ description: "Maximum results to return."
5948
6496
  }
5949
6497
  },
5950
6498
  required: ["topicId"],
5951
6499
  response: {
5952
- description: "Worktrees with phase, status, belief count, and creation time",
6500
+ description: "Worktrees with lifecycle phase, campaign, lane, status, belief count, and creation time",
5953
6501
  fields: {
5954
- worktrees: "array \u2014 { worktreeId, title, phase, status, beliefCount, createdAt }"
6502
+ worktrees: "array \u2014 { worktreeId, title, phase, campaign, lane, laneOrderInCampaign, orderInLane, status, beliefCount, createdAt }"
5955
6503
  }
5956
6504
  },
5957
6505
  ownerModule: "workflow-engine",
@@ -5960,7 +6508,7 @@ var LIST_WORKTREES = {
5960
6508
  };
5961
6509
  var LIST_ALL_WORKTREES = {
5962
6510
  name: "list_all_worktrees",
5963
- description: "List ALL worktrees across ALL topics in one query. No topic scope required. Like `git worktree list --all` \u2014 returns the complete pipeline inventory with track, trackPosition, executionBand, dependencies, and status. Supports filtering by status, track, and executionBand. This is the PM's primary pipeline query \u2014 one call, full picture.",
6511
+ description: "List ALL worktrees across ALL topics in one query. No topic scope required. Like `git worktree list --all` \u2014 returns the complete pipeline inventory with campaign, lane, lane order, dependencies, and status. Supports filtering by status, lane, and campaign. This is the PM's primary pipeline query \u2014 one call, full picture.",
5964
6512
  parameters: {
5965
6513
  status: {
5966
6514
  type: "string",
@@ -5978,13 +6526,18 @@ var LIST_ALL_WORKTREES = {
5978
6526
  "dismissed"
5979
6527
  ]
5980
6528
  },
5981
- track: {
6529
+ lane: {
5982
6530
  type: "string",
5983
- description: "Filter by track name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity')"
6531
+ description: "Filter by lane name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity')"
5984
6532
  },
5985
- executionBand: {
6533
+ campaign: {
5986
6534
  type: "number",
5987
- description: "Filter by execution band number (e.g., 1, 2, 3). Returns only worktrees in that parallel execution group."
6535
+ description: "Filter by campaign number (e.g., 1, 2, 3). Returns only worktrees in that campaign."
6536
+ },
6537
+ groupBy: {
6538
+ type: "string",
6539
+ description: "Optional grouping mode for the response.",
6540
+ enum: ["campaign", "lane", "flat"]
5988
6541
  },
5989
6542
  limit: {
5990
6543
  type: "number",
@@ -5995,10 +6548,39 @@ var LIST_ALL_WORKTREES = {
5995
6548
  response: {
5996
6549
  description: "All worktrees across all topics with full pipeline metadata",
5997
6550
  fields: {
5998
- worktrees: "array \u2014 { worktreeId, title, topicId, topicName, phase, status, hypothesis, track, trackPosition, executionBand, executionOrder, dependsOn, blocks, gate, createdAt }",
6551
+ worktrees: "array \u2014 { worktreeId, title, topicId, topicName, phase, status, hypothesis, campaign, lane, laneOrderInCampaign, orderInLane, dependsOn, blocks, gate, createdAt }",
5999
6552
  total: "number \u2014 total count after filtering",
6000
- tracks: "object \u2014 { trackName: count } summary of worktrees per track",
6001
- bands: "object \u2014 { bandNumber: count } summary of worktrees per execution band"
6553
+ lanes: "object \u2014 { laneName: count } summary of worktrees per lane",
6554
+ campaigns: "object \u2014 { campaignNumber: count } summary of worktrees per campaign"
6555
+ }
6556
+ },
6557
+ ownerModule: "workflow-engine",
6558
+ ontologyPrimitive: "worktree",
6559
+ tier: "showcase"
6560
+ };
6561
+ var LIST_CAMPAIGNS = {
6562
+ name: "list_campaigns",
6563
+ description: "List compact pipeline campaigns with their nested lanes. Use this to see the top-level campaign > lane > worktree shape without pulling the full worktree inventory.",
6564
+ parameters: {
6565
+ topicId: {
6566
+ type: "string",
6567
+ description: "Optional topic scope."
6568
+ },
6569
+ status: {
6570
+ type: "string",
6571
+ description: "Optional worktree status filter before grouping campaigns and lanes."
6572
+ },
6573
+ limit: {
6574
+ type: "number",
6575
+ description: "Maximum worktrees to scan before grouping."
6576
+ }
6577
+ },
6578
+ required: [],
6579
+ response: {
6580
+ description: "Pipeline campaigns with nested lane summaries.",
6581
+ fields: {
6582
+ campaigns: "array \u2014 { campaign, lanes: [{ lane, laneOrderInCampaign, worktreeCount, activeCount, readyCount, blockedCount, completedCount, nextWorktree }] }",
6583
+ totalWorktrees: "number \u2014 total worktrees scanned after filtering"
6002
6584
  }
6003
6585
  },
6004
6586
  ownerModule: "workflow-engine",
@@ -6061,16 +6643,28 @@ var UPDATE_WORKTREE_TARGETS = {
6061
6643
  };
6062
6644
  var UPDATE_WORKTREE_METADATA = {
6063
6645
  name: "update_worktree_metadata",
6064
- description: "Update worktree sequencing metadata \u2014 execution order, dependencies, blocking relations, and gates. Like `git config` for a worktree \u2014 sets the scheduling and dependency metadata that determines when this worktree can activate relative to others. Use to backfill or correct sequencing data.",
6646
+ description: "Update worktree sequencing metadata \u2014 campaign, lane, dependencies, blocking relations, and gates. Like `git config` for a worktree \u2014 sets the scheduling and dependency metadata that determines when this worktree can activate relative to others. Use to backfill or correct sequencing data.",
6065
6647
  parameters: {
6066
6648
  worktreeId: { type: "string", description: "The worktree to update" },
6067
6649
  hypothesis: {
6068
6650
  type: "string",
6069
6651
  description: "Testable claim this worktree investigates"
6070
6652
  },
6071
- executionOrder: {
6653
+ campaign: {
6654
+ type: "number",
6655
+ description: "Top-level pipeline campaign number."
6656
+ },
6657
+ lane: {
6658
+ type: "string",
6659
+ description: "GitButler-aligned workstream lane name inside the campaign."
6660
+ },
6661
+ laneOrderInCampaign: {
6662
+ type: "number",
6663
+ description: "Ordering for this lane within the campaign."
6664
+ },
6665
+ orderInLane: {
6072
6666
  type: "number",
6073
- description: "Global execution order (1 = first, higher = later)"
6667
+ description: "Position of this worktree inside its lane."
6074
6668
  },
6075
6669
  dependsOn: {
6076
6670
  type: "array",
@@ -6108,18 +6702,6 @@ var UPDATE_WORKTREE_METADATA = {
6108
6702
  type: "object",
6109
6703
  description: "Calibrated auto-fix policy controlling dry-run vs safe execution, per-run action caps, and permitted mutation tiers."
6110
6704
  },
6111
- track: {
6112
- type: "string",
6113
- description: "Parallel workstream name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity', 'execution-program'). Groups worktrees into named lanes for pipeline visualization and PM analysis."
6114
- },
6115
- trackPosition: {
6116
- type: "number",
6117
- description: "Position within the track (1-indexed). E.g., TC-A=1, TC-B=2, TC-C=3 within the 'tc-scope' track."
6118
- },
6119
- executionBand: {
6120
- type: "number",
6121
- description: "Parallel execution band number. All worktrees in the same band can run simultaneously. Band 2 = OE-B + TC-A, Band 3 = TC-B + 11D-R + S2-13A, etc."
6122
- },
6123
6705
  status: {
6124
6706
  type: "string",
6125
6707
  description: "Override the worktree status. Use for lifecycle transitions like marking a worktree superseded, long-term, or as a raw idea.",
@@ -6489,6 +7071,10 @@ var LIST_TASKS = {
6489
7071
  type: "string",
6490
7072
  description: "Filter to tasks linked to this worktree"
6491
7073
  },
7074
+ worktreeId: {
7075
+ type: "string",
7076
+ description: "Alias for linkedWorktreeId"
7077
+ },
6492
7078
  status: {
6493
7079
  type: "string",
6494
7080
  description: "Filter by status: todo, in_progress, blocked, done",
@@ -6576,7 +7162,7 @@ var GET_TOPIC = {
6576
7162
  description: "Legacy alias for topicId"
6577
7163
  }
6578
7164
  },
6579
- required: [],
7165
+ required: ["topicId"],
6580
7166
  response: {
6581
7167
  description: "Single topic record",
6582
7168
  fields: {
@@ -6931,7 +7517,7 @@ var GET_ONTOLOGY = {
6931
7517
  description: "Tenant scope for key lookup. Omit for platform-level."
6932
7518
  }
6933
7519
  },
6934
- required: [],
7520
+ required: ["id"],
6935
7521
  response: {
6936
7522
  description: "Ontology definition with latest published version",
6937
7523
  fields: {
@@ -6998,7 +7584,7 @@ var MATCH_ENTITY_TYPE = {
6998
7584
  description: "Optional maximum number of ranked matches to return"
6999
7585
  }
7000
7586
  },
7001
- required: ["text"],
7587
+ required: ["text", "ontologyId"],
7002
7588
  response: {
7003
7589
  description: "Ranked ontology entity type matches",
7004
7590
  fields: {
@@ -7252,7 +7838,7 @@ var RECORD_SCOPE_LEARNING = {
7252
7838
  };
7253
7839
  var PIPELINE_SNAPSHOT = {
7254
7840
  name: "pipeline_snapshot",
7255
- description: "Summarize a topic's worktree pipeline in band-and-lane form. Like `git status --short` for Lucern execution \u2014 returns the hinge worktree, next planned wave, blockers, critical path, superseded work, and graph hygiene debt.",
7841
+ description: "Summarize a topic's worktree pipeline in campaign-and-lane form. Like `git status --short` for Lucern execution \u2014 returns the hinge worktree, next planned wave, blockers, critical path, superseded work, and graph hygiene debt.",
7256
7842
  parameters: {
7257
7843
  topicId: { type: "string", description: "Topic scope ID" }
7258
7844
  },
@@ -7262,14 +7848,14 @@ var PIPELINE_SNAPSHOT = {
7262
7848
  fields: {
7263
7849
  topicId: "string",
7264
7850
  topicName: "string",
7265
- currentBand: "number | null",
7266
- nextBand: "number | null",
7851
+ currentCampaign: "number | null",
7852
+ nextCampaign: "number | null",
7267
7853
  activeWorktrees: "array \u2014 current hinge worktree(s)",
7268
- nextWave: "array \u2014 worktrees in the next planned band",
7854
+ nextWave: "array \u2014 worktrees in the next planned campaign",
7269
7855
  readyNow: "array \u2014 planning worktrees with dependencies completed",
7270
7856
  blockedBy: "array \u2014 grouped blockers",
7271
7857
  criticalPath: "array \u2014 ordered incomplete worktree chain",
7272
- bands: "array \u2014 incomplete worktrees grouped by executionBand",
7858
+ campaigns: "array \u2014 incomplete worktrees grouped by campaign",
7273
7859
  superseded: "array \u2014 worktrees marked superseded or not for activation",
7274
7860
  graphHygiene: "object \u2014 untargeted and taskless worktree debt",
7275
7861
  riskQuestions: "array \u2014 critical/high open questions",
@@ -7858,6 +8444,7 @@ var MCP_TOOL_CONTRACTS = {
7858
8444
  list_beliefs: LIST_BELIEFS,
7859
8445
  list_worktrees: LIST_WORKTREES,
7860
8446
  list_all_worktrees: LIST_ALL_WORKTREES,
8447
+ list_campaigns: LIST_CAMPAIGNS,
7861
8448
  activate_worktree: ACTIVATE_WORKTREE,
7862
8449
  update_worktree_targets: UPDATE_WORKTREE_TARGETS,
7863
8450
  update_worktree_metadata: UPDATE_WORKTREE_METADATA,
@@ -8040,6 +8627,7 @@ var MCP_WORKFLOW_PLATFORM_OPERATION_NAMES = [
8040
8627
  "activate_worktree",
8041
8628
  "list_worktrees",
8042
8629
  "list_all_worktrees",
8630
+ "list_campaigns",
8043
8631
  "update_worktree_targets",
8044
8632
  "update_worktree_metadata",
8045
8633
  "create_task",
@@ -8247,6 +8835,7 @@ var LUCERN_OPERATION_MANIFEST = {
8247
8835
 
8248
8836
  // ../contracts/src/function-registry/helpers.ts
8249
8837
  var jsonObjectSchema = z.record(z.unknown());
8838
+ var sdkSessionIdSchema = z.string().optional();
8250
8839
  function mcpContractShape(contract) {
8251
8840
  const required = new Set(contract.required);
8252
8841
  return Object.fromEntries(
@@ -8281,10 +8870,40 @@ function argsSchemaFromMcpContract(contract) {
8281
8870
  return z.object(mcpContractShape(contract));
8282
8871
  }
8283
8872
  function inputSchemaFromMcpContract(contract) {
8284
- return argsSchemaFromMcpContract(contract).passthrough();
8873
+ return withInternalSurfaceFields(argsSchemaFromMcpContract(contract));
8874
+ }
8875
+ function withInternalSurfaceFields(schema) {
8876
+ return schema.extend({ __sdkSessionId: sdkSessionIdSchema }).strict();
8877
+ }
8878
+ function normalizeInputSchema(schema) {
8879
+ if (schema instanceof z.ZodObject) {
8880
+ return withInternalSurfaceFields(schema);
8881
+ }
8882
+ return schema;
8883
+ }
8884
+ function unwrapObjectSchema(schema) {
8885
+ let current = schema;
8886
+ while (true) {
8887
+ switch (current._def.typeName) {
8888
+ case z.ZodFirstPartyTypeKind.ZodEffects:
8889
+ current = current._def.schema;
8890
+ continue;
8891
+ case z.ZodFirstPartyTypeKind.ZodBranded:
8892
+ current = current._def.type;
8893
+ continue;
8894
+ default:
8895
+ return current instanceof z.ZodObject ? current : void 0;
8896
+ }
8897
+ }
8285
8898
  }
8286
8899
  function getObjectShape(schema) {
8287
- const shape = typeof schema._def.shape === "function" ? schema._def.shape() : schema._def.shape;
8900
+ const objectSchema = unwrapObjectSchema(schema);
8901
+ if (!objectSchema) {
8902
+ throw new Error(
8903
+ `Expected a Zod object schema, received ${schema._def.typeName}.`
8904
+ );
8905
+ }
8906
+ const shape = typeof objectSchema._def.shape === "function" ? objectSchema._def.shape() : objectSchema._def.shape;
8288
8907
  return shape;
8289
8908
  }
8290
8909
  function unwrapMcpParameterSchema(schema) {
@@ -8305,6 +8924,9 @@ function unwrapMcpParameterSchema(schema) {
8305
8924
  case z.ZodFirstPartyTypeKind.ZodBranded:
8306
8925
  current = current._def.type;
8307
8926
  continue;
8927
+ case z.ZodFirstPartyTypeKind.ZodEffects:
8928
+ current = current._def.schema;
8929
+ continue;
8308
8930
  default:
8309
8931
  return { schema: current, required, description: description ?? current.description };
8310
8932
  }
@@ -8324,6 +8946,7 @@ function mcpParameterFromZod(fieldName, schema, contractName) {
8324
8946
  return { parameter: { type: "array", description }, required };
8325
8947
  case z.ZodFirstPartyTypeKind.ZodObject:
8326
8948
  case z.ZodFirstPartyTypeKind.ZodRecord:
8949
+ case z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
8327
8950
  return { parameter: { type: "object", description }, required };
8328
8951
  case z.ZodFirstPartyTypeKind.ZodEnum:
8329
8952
  return {
@@ -8385,6 +9008,14 @@ function withCreatedBy(input, context) {
8385
9008
  createdBy: typeof input.createdBy === "string" ? input.createdBy : authUserId(context)
8386
9009
  };
8387
9010
  }
9011
+ function compactRecord4(input) {
9012
+ return Object.fromEntries(
9013
+ Object.entries(input).filter(([, value]) => value !== void 0)
9014
+ );
9015
+ }
9016
+ function recordValue2(value) {
9017
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
9018
+ }
8388
9019
  function surfaceMcpContract(name) {
8389
9020
  const contract = MCP_TOOL_CONTRACTS[name];
8390
9021
  if (!contract) {
@@ -8429,7 +9060,9 @@ function surfaceContract(args) {
8429
9060
  const canonicalArgs = args.args ?? argsSchemaFromMcpContract(baseMcp);
8430
9061
  const mcp = args.args ? mcpContractFromArgsSchema(baseMcp, canonicalArgs, args.name) : baseMcp;
8431
9062
  const canonicalReturns = args.returns ?? jsonObjectSchema;
8432
- const input = args.input ?? inputSchemaFromMcpContract(mcp);
9063
+ const input = normalizeInputSchema(
9064
+ args.input ?? inputSchemaFromMcpContract(mcp)
9065
+ );
8433
9066
  const output = args.output ?? canonicalReturns;
8434
9067
  return defineFunctionContract({
8435
9068
  name: args.name,
@@ -8491,20 +9124,26 @@ function assertSurfaceCoverage(contracts) {
8491
9124
 
8492
9125
  // ../contracts/src/function-registry/context.ts
8493
9126
  var observationInput = (input, context) => withUserId(
8494
- {
8495
- ...input,
9127
+ compactRecord4({
9128
+ projectId: input.projectId,
9129
+ topicId: input.topicId,
8496
9130
  text: input.text ?? input.summary,
8497
9131
  title: input.title ?? input.summary,
8498
9132
  content: input.content ?? input.summary,
9133
+ contentType: input.contentType,
8499
9134
  kind: input.kind ?? input.observationType ?? "observation",
8500
- sourceType: input.sourceType ?? input.source ?? "agent",
8501
- metadata: {
8502
- ...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {},
9135
+ tags: input.tags,
9136
+ sourceType: input.sourceType,
9137
+ externalSourceType: input.externalSourceType,
9138
+ sourceUrl: input.sourceUrl,
9139
+ metadata: compactRecord4({
9140
+ ...recordValue2(input.metadata),
8503
9141
  observationType: input.observationType,
8504
9142
  source: input.source
8505
- },
9143
+ }),
9144
+ rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded observation",
8506
9145
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8507
- },
9146
+ }),
8508
9147
  context
8509
9148
  );
8510
9149
  var contextContracts = [
@@ -8556,7 +9195,13 @@ var contextContracts = [
8556
9195
  convex: {
8557
9196
  module: "evidence",
8558
9197
  functionName: "getByTopic",
8559
- kind: "query"
9198
+ kind: "query",
9199
+ inputProjection: (input) => compactRecord4({
9200
+ topicId: input.topicId,
9201
+ limit: input.limit,
9202
+ status: input.status,
9203
+ userId: input.userId
9204
+ })
8560
9205
  }
8561
9206
  })
8562
9207
  ];
@@ -8622,42 +9267,62 @@ var identityContracts = [
8622
9267
  ];
8623
9268
 
8624
9269
  // ../contracts/src/function-registry/beliefs.ts
8625
- var withBeliefId = (input) => ({
8626
- ...input,
9270
+ var beliefLookupInput = (input) => compactRecord4({
8627
9271
  nodeId: input.nodeId ?? input.id ?? input.beliefId,
8628
- beliefId: input.beliefId ?? input.id ?? input.nodeId
9272
+ beliefId: input.beliefId
8629
9273
  });
8630
- var createBeliefInput = (input, context) => withUserId(
8631
- {
8632
- ...input,
8633
- formulation: input.formulation ?? input.canonicalText,
8634
- baseRate: input.baseRate ?? 0.5,
8635
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8636
- },
8637
- context
8638
- );
9274
+ var beliefNodeInput = (input) => compactRecord4({
9275
+ nodeId: input.nodeId ?? input.id ?? input.beliefId
9276
+ });
9277
+ var beliefTopicInput = (input) => {
9278
+ const parsed = listBeliefsProjection.inputSchema.safeParse(input);
9279
+ if (!parsed.success) {
9280
+ throw new Error(
9281
+ `list_beliefs projection input rejected: ${parsed.error.message}`
9282
+ );
9283
+ }
9284
+ return compactRecord4(listBeliefsProjection.project(parsed.data));
9285
+ };
9286
+ var createBeliefInput = (input, context) => {
9287
+ return withUserId(
9288
+ compactRecord4({
9289
+ projectId: input.projectId,
9290
+ topicId: input.topicId,
9291
+ formulation: input.formulation ?? input.canonicalText,
9292
+ beliefType: input.beliefType,
9293
+ rationale: input.rationale,
9294
+ pillar: input.pillar,
9295
+ worktreeId: input.worktreeId,
9296
+ sourceBeliefIds: input.sourceBeliefIds,
9297
+ sourceType: input.sourceType,
9298
+ reversibility: input.reversibility,
9299
+ predictionMeta: input.predictionMeta,
9300
+ baseRate: input.baseRate ?? 0.5,
9301
+ metadata: input.metadata,
9302
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9303
+ }),
9304
+ context
9305
+ );
9306
+ };
8639
9307
  var forkBeliefInput = (input, context) => withUserId(
8640
- {
8641
- ...input,
9308
+ compactRecord4({
8642
9309
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
9310
+ newFormulation: input.newFormulation,
9311
+ forkReason: input.forkReason,
9312
+ rationale: input.rationale,
8643
9313
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8644
- },
9314
+ }),
8645
9315
  context
8646
9316
  );
8647
9317
  var confidenceInput = (input, context) => {
8648
- const confidence = typeof input.confidence === "number" ? input.confidence : void 0;
8649
- const belief = typeof input.belief === "number" ? input.belief : confidence ?? 0.5;
8650
- const disbelief = typeof input.disbelief === "number" ? input.disbelief : 0;
8651
- const uncertainty = typeof input.uncertainty === "number" ? input.uncertainty : Math.max(0, 1 - belief - disbelief);
9318
+ const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
9319
+ if (!parsed.success) {
9320
+ throw new Error(
9321
+ `modulate_confidence projection input rejected: ${parsed.error.message}`
9322
+ );
9323
+ }
8652
9324
  return withUserId(
8653
- {
8654
- ...input,
8655
- belief,
8656
- disbelief,
8657
- uncertainty,
8658
- baseRate: input.baseRate ?? 0.5,
8659
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8660
- },
9325
+ compactRecord4(modulateConfidenceProjection.project(parsed.data)),
8661
9326
  context
8662
9327
  );
8663
9328
  };
@@ -8692,7 +9357,7 @@ var beliefsContracts = [
8692
9357
  module: "beliefs",
8693
9358
  functionName: "getById",
8694
9359
  kind: "query",
8695
- inputProjection: withBeliefId
9360
+ inputProjection: beliefLookupInput
8696
9361
  }
8697
9362
  }),
8698
9363
  surfaceContract({
@@ -8708,8 +9373,10 @@ var beliefsContracts = [
8708
9373
  convex: {
8709
9374
  module: "beliefs",
8710
9375
  functionName: "getByTopic",
8711
- kind: "query"
8712
- }
9376
+ kind: "query",
9377
+ inputProjection: beliefTopicInput
9378
+ },
9379
+ args: listBeliefsInputSchema
8713
9380
  }),
8714
9381
  surfaceContract({
8715
9382
  name: "refine_belief",
@@ -8727,7 +9394,7 @@ var beliefsContracts = [
8727
9394
  kind: "mutation",
8728
9395
  inputProjection: (input, context) => withUserId(
8729
9396
  {
8730
- ...withBeliefId(input),
9397
+ ...beliefLookupInput(input),
8731
9398
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8732
9399
  },
8733
9400
  context
@@ -8748,7 +9415,8 @@ var beliefsContracts = [
8748
9415
  functionName: "modulateConfidence",
8749
9416
  kind: "mutation",
8750
9417
  inputProjection: confidenceInput
8751
- }
9418
+ },
9419
+ args: modulateConfidenceInputSchema
8752
9420
  }),
8753
9421
  surfaceContract({
8754
9422
  name: "fork_belief",
@@ -8781,10 +9449,10 @@ var beliefsContracts = [
8781
9449
  functionName: "archive",
8782
9450
  kind: "mutation",
8783
9451
  inputProjection: (input, context) => withUserId(
8784
- {
8785
- ...withBeliefId(input),
9452
+ compactRecord4({
9453
+ ...beliefNodeInput(input),
8786
9454
  reason: input.reason ?? input.rationale
8787
- },
9455
+ }),
8788
9456
  context
8789
9457
  )
8790
9458
  }
@@ -8802,10 +9470,12 @@ var beliefsContracts = [
8802
9470
  module: "nodes",
8803
9471
  functionName: "search",
8804
9472
  kind: "query",
8805
- inputProjection: (input) => ({
8806
- ...input,
9473
+ inputProjection: (input) => compactRecord4({
8807
9474
  searchQuery: input.searchQuery ?? input.query,
8808
- nodeType: "belief"
9475
+ projectId: input.projectId,
9476
+ topicId: input.topicId,
9477
+ nodeType: "belief",
9478
+ limit: input.limit
8809
9479
  })
8810
9480
  }
8811
9481
  }),
@@ -8822,7 +9492,7 @@ var beliefsContracts = [
8822
9492
  module: "beliefs",
8823
9493
  functionName: "getConfidenceHistory",
8824
9494
  kind: "query",
8825
- inputProjection: withBeliefId
9495
+ inputProjection: beliefNodeInput
8826
9496
  }
8827
9497
  }),
8828
9498
  surfaceContract({
@@ -8839,25 +9509,69 @@ var beliefsContracts = [
8839
9509
  module: "beliefs",
8840
9510
  functionName: "getConfidenceHistory",
8841
9511
  kind: "query",
8842
- inputProjection: withBeliefId
9512
+ inputProjection: beliefNodeInput
8843
9513
  }
8844
9514
  })
8845
9515
  ];
8846
9516
 
8847
9517
  // ../contracts/src/function-registry/evidence.ts
8848
- var evidenceIdInput = (input) => ({
8849
- ...input,
8850
- evidenceId: input.evidenceId ?? input.id ?? input.nodeId,
9518
+ var evidenceIdInput = (input) => compactRecord4({
9519
+ evidenceId: input.evidenceId,
9520
+ insightId: input.insightId,
8851
9521
  nodeId: input.nodeId ?? input.id ?? input.evidenceId
8852
9522
  });
8853
- var createEvidenceInput = (input, context) => withUserId(
8854
- {
8855
- ...input,
8856
- title: input.title ?? input.text,
8857
- content: input.content ?? input.text,
8858
- sourceType: input.sourceType ?? input.source ?? "agent",
9523
+ var evidenceTopicInput = (input) => compactRecord4({
9524
+ topicId: input.topicId,
9525
+ status: input.status,
9526
+ userId: input.userId,
9527
+ limit: input.limit
9528
+ });
9529
+ var createEvidenceInput = (input, context) => {
9530
+ const parsed = createEvidenceProjection.inputSchema.safeParse(input);
9531
+ if (!parsed.success) {
9532
+ throw new Error(
9533
+ `create_evidence projection input rejected: ${parsed.error.message}`
9534
+ );
9535
+ }
9536
+ return withUserId(
9537
+ compactRecord4(createEvidenceProjection.project(parsed.data)),
9538
+ context
9539
+ );
9540
+ };
9541
+ var linkEvidenceToBeliefEdgeInput = (input, context) => withCreatedBy(
9542
+ compactRecord4({
9543
+ fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
9544
+ toNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
9545
+ edgeType: "evidence_supports_belief",
9546
+ globalId: input.globalId ?? `edge:${String(
9547
+ input.insightId ?? input.evidenceNodeId ?? input.evidenceId
9548
+ )}:${String(
9549
+ input.beliefNodeId ?? input.beliefId ?? input.targetId
9550
+ )}:evidence_supports_belief`,
9551
+ weight: typeof input.weight === "number" ? input.weight : input.type === "contradicting" ? -1 : 1,
9552
+ context: input.rationale ?? input.context,
9553
+ skipLayerValidation: true,
9554
+ topicId: input.topicId,
8859
9555
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8860
- },
9556
+ }),
9557
+ context
9558
+ );
9559
+ var linkEvidenceToQuestionEdgeInput = (input, context) => withCreatedBy(
9560
+ compactRecord4({
9561
+ fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
9562
+ toNodeId: input.questionId ?? input.questionNodeId ?? input.targetId,
9563
+ edgeType: "evidence_supports_question",
9564
+ globalId: input.globalId ?? `edge:${String(
9565
+ input.insightId ?? input.evidenceNodeId ?? input.evidenceId
9566
+ )}:${String(
9567
+ input.questionId ?? input.questionNodeId ?? input.targetId
9568
+ )}:evidence_supports_question`,
9569
+ weight: input.impactScore ?? input.weight,
9570
+ context: input.rationale ?? input.context,
9571
+ skipLayerValidation: true,
9572
+ topicId: input.topicId,
9573
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9574
+ }),
8861
9575
  context
8862
9576
  );
8863
9577
  var evidenceContracts = [
@@ -8901,8 +9615,9 @@ var evidenceContracts = [
8901
9615
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
8902
9616
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
8903
9617
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
9618
+ rationale: input.reasoning,
8904
9619
  metadata: {
8905
- ...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {},
9620
+ ...recordValue2(input.metadata),
8906
9621
  reasoning: input.reasoning,
8907
9622
  sourceUrl: input.sourceUrl
8908
9623
  }
@@ -8942,7 +9657,8 @@ var evidenceContracts = [
8942
9657
  convex: {
8943
9658
  module: "evidence",
8944
9659
  functionName: "getByTopic",
8945
- kind: "query"
9660
+ kind: "query",
9661
+ inputProjection: evidenceTopicInput
8946
9662
  }
8947
9663
  }),
8948
9664
  surfaceContract({
@@ -8958,10 +9674,12 @@ var evidenceContracts = [
8958
9674
  module: "nodes",
8959
9675
  functionName: "search",
8960
9676
  kind: "query",
8961
- inputProjection: (input) => ({
8962
- ...input,
9677
+ inputProjection: (input) => compactRecord4({
8963
9678
  searchQuery: input.searchQuery ?? input.q ?? input.query,
8964
- nodeType: "evidence"
9679
+ projectId: input.projectId,
9680
+ topicId: input.topicId,
9681
+ nodeType: "evidence",
9682
+ limit: input.limit
8965
9683
  })
8966
9684
  }
8967
9685
  }),
@@ -8975,17 +9693,10 @@ var evidenceContracts = [
8975
9693
  sdkMethod: "linkEvidenceToBelief",
8976
9694
  summary: "Link evidence to a belief.",
8977
9695
  convex: {
8978
- module: "beliefs",
8979
- functionName: "linkEvidence",
9696
+ module: "edges",
9697
+ functionName: "create",
8980
9698
  kind: "mutation",
8981
- inputProjection: (input, context) => withUserId(
8982
- {
8983
- ...input,
8984
- beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
8985
- evidenceNodeId: input.evidenceNodeId ?? input.evidenceId
8986
- },
8987
- context
8988
- )
9699
+ inputProjection: linkEvidenceToBeliefEdgeInput
8989
9700
  }
8990
9701
  }),
8991
9702
  surfaceContract({
@@ -8998,18 +9709,10 @@ var evidenceContracts = [
8998
9709
  sdkMethod: "linkEvidenceToQuestion",
8999
9710
  summary: "Link evidence to a question.",
9000
9711
  convex: {
9001
- module: "questionLinks",
9712
+ module: "edges",
9002
9713
  functionName: "create",
9003
9714
  kind: "mutation",
9004
- inputProjection: (input, context) => withCreatedBy(
9005
- {
9006
- ...input,
9007
- questionId: input.questionId,
9008
- insightId: input.insightId ?? input.evidenceId,
9009
- helpsAnswer: input.helpsAnswer ?? true
9010
- },
9011
- context
9012
- )
9715
+ inputProjection: linkEvidenceToQuestionEdgeInput
9013
9716
  }
9014
9717
  }),
9015
9718
  surfaceContract({
@@ -9022,35 +9725,46 @@ var evidenceContracts = [
9022
9725
  sdkMethod: "linkEvidence",
9023
9726
  summary: "Link evidence to a target node.",
9024
9727
  convex: {
9025
- module: "beliefs",
9026
- functionName: "linkEvidence",
9728
+ module: "edges",
9729
+ functionName: "create",
9027
9730
  kind: "mutation",
9028
- inputProjection: (input, context) => withUserId(
9029
- {
9030
- ...input,
9031
- beliefNodeId: input.beliefNodeId ?? input.targetId,
9032
- evidenceNodeId: input.evidenceNodeId ?? input.evidenceId
9033
- },
9034
- context
9035
- )
9731
+ inputProjection: linkEvidenceToBeliefEdgeInput
9036
9732
  }
9037
9733
  })
9038
9734
  ];
9039
9735
 
9040
9736
  // ../contracts/src/function-registry/questions.ts
9041
- var questionIdInput = (input) => ({
9042
- ...input,
9043
- questionId: input.questionId ?? input.id ?? input.nodeId,
9044
- nodeId: input.nodeId ?? input.id ?? input.questionId
9737
+ var questionNodeInput = (input) => compactRecord4({
9738
+ nodeId: input.nodeId ?? input.id ?? input.questionId,
9739
+ questionId: input.questionId
9045
9740
  });
9046
- var createQuestionInput = (input, context) => withUserId(
9047
- {
9048
- ...input,
9049
- text: input.text ?? input.question,
9050
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9051
- },
9052
- context
9053
- );
9741
+ var questionTopicInput = (input) => compactRecord4({
9742
+ topicId: input.topicId,
9743
+ status: input.status,
9744
+ userId: input.userId,
9745
+ limit: input.limit
9746
+ });
9747
+ var createQuestionInput = (input, context) => {
9748
+ const priority = input.priority === "urgent" ? "high" : input.priority;
9749
+ return withUserId(
9750
+ compactRecord4({
9751
+ topicId: input.topicId,
9752
+ question: input.question ?? input.text,
9753
+ category: input.category,
9754
+ priority,
9755
+ source: input.source,
9756
+ linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.linkedBeliefId,
9757
+ testType: input.testType,
9758
+ importance: input.importance,
9759
+ epistemicUnlock: input.epistemicUnlock,
9760
+ sourceQuestionIds: input.sourceQuestionIds,
9761
+ linkedWorktreeId: input.linkedWorktreeId,
9762
+ questionType: input.questionType,
9763
+ questionPriority: input.questionPriority
9764
+ }),
9765
+ context
9766
+ );
9767
+ };
9054
9768
  var questionsContracts = [
9055
9769
  surfaceContract({
9056
9770
  name: "create_question",
@@ -9082,7 +9796,7 @@ var questionsContracts = [
9082
9796
  module: "questions",
9083
9797
  functionName: "getById",
9084
9798
  kind: "query",
9085
- inputProjection: questionIdInput
9799
+ inputProjection: questionNodeInput
9086
9800
  }
9087
9801
  }),
9088
9802
  surfaceContract({
@@ -9098,7 +9812,8 @@ var questionsContracts = [
9098
9812
  convex: {
9099
9813
  module: "questions",
9100
9814
  functionName: "getByTopic",
9101
- kind: "query"
9815
+ kind: "query",
9816
+ inputProjection: questionTopicInput
9102
9817
  }
9103
9818
  }),
9104
9819
  surfaceContract({
@@ -9115,7 +9830,12 @@ var questionsContracts = [
9115
9830
  module: "questions",
9116
9831
  functionName: "updateQuestion",
9117
9832
  kind: "mutation",
9118
- inputProjection: (input, context) => withUserId({ ...questionIdInput(input), text: input.text }, context)
9833
+ inputProjection: (input) => compactRecord4({
9834
+ questionId: input.questionId ?? input.id ?? input.nodeId,
9835
+ question: input.question ?? input.text,
9836
+ category: input.category,
9837
+ priority: input.priority
9838
+ })
9119
9839
  }
9120
9840
  }),
9121
9841
  surfaceContract({
@@ -9132,7 +9852,16 @@ var questionsContracts = [
9132
9852
  module: "questions",
9133
9853
  functionName: "updateStatus",
9134
9854
  kind: "mutation",
9135
- inputProjection: (input, context) => withUserId(questionIdInput(input), context)
9855
+ inputProjection: (input, context) => withUserId(
9856
+ compactRecord4({
9857
+ questionId: input.questionId ?? input.id,
9858
+ nodeId: input.nodeId,
9859
+ status: input.status,
9860
+ answer: input.answer,
9861
+ answerStatus: input.answerStatus
9862
+ }),
9863
+ context
9864
+ )
9136
9865
  }
9137
9866
  }),
9138
9867
  surfaceContract({
@@ -9149,7 +9878,12 @@ var questionsContracts = [
9149
9878
  module: "questions",
9150
9879
  functionName: "deleteQuestion",
9151
9880
  kind: "mutation",
9152
- inputProjection: questionIdInput
9881
+ inputProjection: (input, context) => withUserId(
9882
+ compactRecord4({
9883
+ questionId: input.questionId ?? input.id ?? input.nodeId
9884
+ }),
9885
+ context
9886
+ )
9153
9887
  }
9154
9888
  }),
9155
9889
  surfaceContract({
@@ -9166,10 +9900,16 @@ var questionsContracts = [
9166
9900
  functionName: "create",
9167
9901
  kind: "mutation",
9168
9902
  inputProjection: (input, context) => withUserId(
9169
- {
9170
- ...input,
9171
- questionNodeId: input.questionNodeId ?? input.questionId
9172
- },
9903
+ compactRecord4({
9904
+ topicId: input.topicId,
9905
+ questionNodeId: input.questionNodeId ?? input.questionId,
9906
+ answerText: input.answerText,
9907
+ confidence: input.confidence,
9908
+ evidenceNodeIds: input.evidenceNodeIds,
9909
+ answerSource: input.answerSource,
9910
+ worktreeId: input.worktreeId,
9911
+ sprintId: input.sprintId
9912
+ }),
9173
9913
  context
9174
9914
  )
9175
9915
  }
@@ -9189,13 +9929,16 @@ var questionsContracts = [
9189
9929
  functionName: "create",
9190
9930
  kind: "mutation",
9191
9931
  inputProjection: (input, context) => withUserId(
9192
- {
9193
- ...input,
9932
+ compactRecord4({
9933
+ topicId: input.topicId,
9194
9934
  questionNodeId: input.questionNodeId ?? input.questionId ?? input.id,
9195
9935
  answerText: input.answerText ?? input.text,
9196
9936
  evidenceNodeIds: input.evidenceNodeIds ?? input.evidenceIds,
9197
- answerSource: input.answerSource ?? "human"
9198
- },
9937
+ answerSource: input.answerSource ?? "human",
9938
+ confidence: input.confidence,
9939
+ worktreeId: input.worktreeId,
9940
+ sprintId: input.sprintId
9941
+ }),
9199
9942
  context
9200
9943
  )
9201
9944
  }
@@ -9228,7 +9971,8 @@ var questionsContracts = [
9228
9971
  convex: {
9229
9972
  module: "questions",
9230
9973
  functionName: "getByTopic",
9231
- kind: "query"
9974
+ kind: "query",
9975
+ inputProjection: questionTopicInput
9232
9976
  }
9233
9977
  }),
9234
9978
  surfaceContract({
@@ -9243,7 +9987,11 @@ var questionsContracts = [
9243
9987
  convex: {
9244
9988
  module: "questions",
9245
9989
  functionName: "getByTopic",
9246
- kind: "query"
9990
+ kind: "query",
9991
+ inputProjection: (input) => compactRecord4({
9992
+ ...questionTopicInput(input),
9993
+ status: input.includeAnswered === true ? void 0 : "open"
9994
+ })
9247
9995
  }
9248
9996
  }),
9249
9997
  surfaceContract({
@@ -9258,16 +10006,28 @@ var questionsContracts = [
9258
10006
  convex: {
9259
10007
  module: "questions",
9260
10008
  functionName: "getByTopic",
9261
- kind: "query"
10009
+ kind: "query",
10010
+ inputProjection: questionTopicInput
9262
10011
  }
9263
10012
  })
9264
10013
  ];
9265
10014
 
9266
10015
  // ../contracts/src/function-registry/topics.ts
9267
- var topicIdInput = (input) => ({
9268
- ...input,
10016
+ var topicIdInput = (input) => compactRecord4({
9269
10017
  id: input.id ?? input.topicId
9270
10018
  });
10019
+ var updateTopicInput = (input) => compactRecord4({
10020
+ id: input.id ?? input.topicId,
10021
+ name: input.name,
10022
+ description: input.description,
10023
+ type: input.type,
10024
+ status: input.status,
10025
+ visibility: input.visibility,
10026
+ ontologyId: input.ontologyId,
10027
+ clearOntologyId: input.clearOntologyId,
10028
+ graphScopeProjectId: input.graphScopeProjectId,
10029
+ metadata: input.metadata
10030
+ });
9271
10031
  var topicsContracts = [
9272
10032
  surfaceContract({
9273
10033
  name: "create_topic",
@@ -9332,7 +10092,7 @@ var topicsContracts = [
9332
10092
  module: "topics",
9333
10093
  functionName: "update",
9334
10094
  kind: "mutation",
9335
- inputProjection: topicIdInput
10095
+ inputProjection: updateTopicInput
9336
10096
  }
9337
10097
  }),
9338
10098
  surfaceContract({
@@ -9354,6 +10114,27 @@ var topicsContracts = [
9354
10114
  ];
9355
10115
 
9356
10116
  // ../contracts/src/function-registry/lenses.ts
10117
+ var createLensInput = (input, context) => compactRecord4({
10118
+ name: input.name,
10119
+ description: input.description,
10120
+ workspaceId: input.workspaceId,
10121
+ topicId: input.topicId,
10122
+ perspectiveType: input.perspectiveType,
10123
+ promptTemplates: input.promptTemplates,
10124
+ workflowTemplates: input.workflowTemplates,
10125
+ taskTemplates: input.taskTemplates,
10126
+ questionTemplates: input.questionTemplates,
10127
+ filterCriteria: input.filterCriteria,
10128
+ metadata: input.metadata,
10129
+ createdBy: authUserId(context)
10130
+ });
10131
+ var lensListInput = (input, context) => compactRecord4({
10132
+ actorId: input.actorId ?? authUserId(context),
10133
+ workspaceId: input.workspaceId,
10134
+ topicId: input.topicId,
10135
+ status: input.status,
10136
+ perspectiveType: input.perspectiveType
10137
+ });
9357
10138
  var lensesContracts = [
9358
10139
  surfaceContract({
9359
10140
  name: "create_lens",
@@ -9367,7 +10148,8 @@ var lensesContracts = [
9367
10148
  convex: {
9368
10149
  module: "lenses",
9369
10150
  functionName: "create",
9370
- kind: "mutation"
10151
+ kind: "mutation",
10152
+ inputProjection: createLensInput
9371
10153
  }
9372
10154
  }),
9373
10155
  surfaceContract({
@@ -9383,7 +10165,8 @@ var lensesContracts = [
9383
10165
  convex: {
9384
10166
  module: "lenses",
9385
10167
  functionName: "list",
9386
- kind: "query"
10168
+ kind: "query",
10169
+ inputProjection: lensListInput
9387
10170
  }
9388
10171
  }),
9389
10172
  surfaceContract({
@@ -9398,7 +10181,13 @@ var lensesContracts = [
9398
10181
  convex: {
9399
10182
  module: "lenses",
9400
10183
  functionName: "applyToTopic",
9401
- kind: "mutation"
10184
+ kind: "mutation",
10185
+ inputProjection: (input, context) => compactRecord4({
10186
+ lensId: input.lensId,
10187
+ topicId: input.topicId,
10188
+ metadata: input.metadata,
10189
+ appliedBy: authUserId(context)
10190
+ })
9402
10191
  }
9403
10192
  }),
9404
10193
  surfaceContract({
@@ -9414,12 +10203,28 @@ var lensesContracts = [
9414
10203
  convex: {
9415
10204
  module: "lenses",
9416
10205
  functionName: "removeFromTopic",
9417
- kind: "mutation"
10206
+ kind: "mutation",
10207
+ inputProjection: (input, context) => compactRecord4({
10208
+ lensId: input.lensId,
10209
+ topicId: input.topicId,
10210
+ removedBy: authUserId(context)
10211
+ })
9418
10212
  }
9419
10213
  })
9420
10214
  ];
9421
10215
 
9422
10216
  // ../contracts/src/function-registry/ontologies.ts
10217
+ var ontologyIdInput = (input) => compactRecord4({
10218
+ id: input.id ?? input.ontologyId
10219
+ });
10220
+ var ontologyVersionIdInput = (input) => compactRecord4({
10221
+ id: input.id ?? input.versionId,
10222
+ ontologyId: input.ontologyId,
10223
+ actorId: input.actorId
10224
+ });
10225
+ var effectiveOntologyInput = (input) => compactRecord4({
10226
+ ontologyId: input.ontologyId ?? input.id
10227
+ });
9423
10228
  var ontologiesContracts = [
9424
10229
  surfaceContract({
9425
10230
  name: "create_ontology",
@@ -9450,10 +10255,7 @@ var ontologiesContracts = [
9450
10255
  module: "ontologies",
9451
10256
  functionName: "getOntologyDefinition",
9452
10257
  kind: "query",
9453
- inputProjection: (input) => ({
9454
- ...input,
9455
- id: input.id ?? input.ontologyId
9456
- })
10258
+ inputProjection: ontologyIdInput
9457
10259
  }
9458
10260
  }),
9459
10261
  surfaceContract({
@@ -9486,9 +10288,13 @@ var ontologiesContracts = [
9486
10288
  module: "ontologies",
9487
10289
  functionName: "updateOntologyDefinition",
9488
10290
  kind: "mutation",
9489
- inputProjection: (input) => ({
9490
- ...input,
9491
- id: input.id ?? input.ontologyId
10291
+ inputProjection: (input) => compactRecord4({
10292
+ id: input.id ?? input.ontologyId,
10293
+ name: input.name,
10294
+ description: input.description,
10295
+ parentOntologyId: input.parentOntologyId,
10296
+ status: input.status,
10297
+ actorId: input.actorId
9492
10298
  })
9493
10299
  }
9494
10300
  }),
@@ -9506,10 +10312,7 @@ var ontologiesContracts = [
9506
10312
  module: "ontologies",
9507
10313
  functionName: "archiveOntologyDefinition",
9508
10314
  kind: "mutation",
9509
- inputProjection: (input) => ({
9510
- ...input,
9511
- id: input.id ?? input.ontologyId
9512
- })
10315
+ inputProjection: ontologyIdInput
9513
10316
  }
9514
10317
  }),
9515
10318
  surfaceContract({
@@ -9540,8 +10343,7 @@ var ontologiesContracts = [
9540
10343
  module: "topics",
9541
10344
  functionName: "update",
9542
10345
  kind: "mutation",
9543
- inputProjection: (input) => ({
9544
- ...input,
10346
+ inputProjection: (input) => compactRecord4({
9545
10347
  id: input.topicId ?? input.id,
9546
10348
  ontologyId: input.ontologyId ?? input.id
9547
10349
  })
@@ -9559,7 +10361,8 @@ var ontologiesContracts = [
9559
10361
  convex: {
9560
10362
  module: "ontologies",
9561
10363
  functionName: "resolveEffectiveOntology",
9562
- kind: "query"
10364
+ kind: "query",
10365
+ inputProjection: effectiveOntologyInput
9563
10366
  }
9564
10367
  }),
9565
10368
  surfaceContract({
@@ -9575,10 +10378,7 @@ var ontologiesContracts = [
9575
10378
  module: "ontologies",
9576
10379
  functionName: "publishOntologyVersion",
9577
10380
  kind: "mutation",
9578
- inputProjection: (input) => ({
9579
- ...input,
9580
- id: input.id ?? input.versionId
9581
- })
10381
+ inputProjection: ontologyVersionIdInput
9582
10382
  }
9583
10383
  }),
9584
10384
  surfaceContract({
@@ -9594,10 +10394,7 @@ var ontologiesContracts = [
9594
10394
  module: "ontologies",
9595
10395
  functionName: "deprecateOntologyVersion",
9596
10396
  kind: "mutation",
9597
- inputProjection: (input) => ({
9598
- ...input,
9599
- id: input.id ?? input.versionId
9600
- })
10397
+ inputProjection: ontologyVersionIdInput
9601
10398
  }
9602
10399
  }),
9603
10400
  surfaceContract({
@@ -9612,16 +10409,51 @@ var ontologiesContracts = [
9612
10409
  convex: {
9613
10410
  module: "ontologies",
9614
10411
  functionName: "resolveEffectiveOntology",
9615
- kind: "query"
10412
+ kind: "query",
10413
+ inputProjection: effectiveOntologyInput
9616
10414
  }
9617
10415
  })
9618
10416
  ];
9619
10417
 
9620
10418
  // ../contracts/src/function-registry/worktrees.ts
9621
- var worktreeInput = (input) => ({
9622
- ...input,
10419
+ var worktreeIdInput = (input) => compactRecord4({
9623
10420
  worktreeId: input.worktreeId ?? input.id
9624
10421
  });
10422
+ var activateWorktreeInput = (input, context) => withUserId(worktreeIdInput(input), context);
10423
+ var worktreeTargetsInput = (input) => compactRecord4({
10424
+ worktreeId: input.worktreeId ?? input.id,
10425
+ addBeliefIds: input.addBeliefIds,
10426
+ removeBeliefIds: input.removeBeliefIds,
10427
+ addQuestionIds: input.addQuestionIds,
10428
+ removeQuestionIds: input.removeQuestionIds
10429
+ });
10430
+ var worktreeMetadataInput = (input) => compactRecord4({
10431
+ worktreeId: input.worktreeId ?? input.id,
10432
+ topicId: input.topicId,
10433
+ additionalTopicIds: input.additionalTopicIds,
10434
+ status: input.status,
10435
+ campaign: input.campaign,
10436
+ lane: input.lane,
10437
+ laneOrderInCampaign: input.laneOrderInCampaign,
10438
+ orderInLane: input.orderInLane,
10439
+ gate: input.gate,
10440
+ hypothesis: input.hypothesis,
10441
+ objective: input.objective,
10442
+ rationale: input.rationale,
10443
+ proofArtifacts: input.proofArtifacts,
10444
+ staffingHint: input.staffingHint,
10445
+ blocks: input.blocks,
10446
+ dependsOn: input.dependsOn,
10447
+ lensId: input.lensId,
10448
+ autoFixPolicy: input.autoFixPolicy,
10449
+ lastReconciledAt: input.lastReconciledAt
10450
+ });
10451
+ var listAllWorktreesInput = (input) => compactRecord4({
10452
+ status: input.status,
10453
+ lane: input.lane,
10454
+ campaign: input.campaign,
10455
+ limit: input.limit
10456
+ });
9625
10457
  var worktreesContracts = [
9626
10458
  surfaceContract({
9627
10459
  name: "add_worktree",
@@ -9637,11 +10469,43 @@ var worktreesContracts = [
9637
10469
  functionName: "create",
9638
10470
  kind: "mutation",
9639
10471
  inputProjection: (input, context) => withCreatedBy(
9640
- {
9641
- ...input,
10472
+ compactRecord4({
9642
10473
  name: input.name ?? input.title,
9643
- targetBeliefIds: input.targetBeliefIds ?? input.beliefIds
9644
- },
10474
+ topicId: input.topicId,
10475
+ worktreeType: input.worktreeType,
10476
+ objective: input.objective,
10477
+ gate: input.gate,
10478
+ hypothesis: input.hypothesis,
10479
+ rationale: input.rationale,
10480
+ signal: input.signal,
10481
+ startDate: input.startDate,
10482
+ endDate: input.endDate,
10483
+ durationWeeks: input.durationWeeks,
10484
+ confidenceImpact: input.confidenceImpact,
10485
+ autoShape: input.autoShape,
10486
+ autoFixPolicy: input.autoFixPolicy,
10487
+ beliefFocus: input.beliefFocus,
10488
+ targetQuestionIds: input.targetQuestionIds,
10489
+ targetBeliefIds: input.targetBeliefIds ?? input.beliefIds,
10490
+ keyQuestions: input.keyQuestions,
10491
+ proofArtifacts: input.proofArtifacts,
10492
+ decisionGate: input.decisionGate ?? (input.goCriteria || input.noGoSignals ? compactRecord4({
10493
+ goCriteria: input.goCriteria,
10494
+ noGoSignals: input.noGoSignals
10495
+ }) : void 0),
10496
+ evidenceSignals: input.evidenceSignals,
10497
+ dependsOn: input.dependsOn,
10498
+ blocks: input.blocks,
10499
+ campaign: input.campaign,
10500
+ lane: input.lane,
10501
+ laneOrderInCampaign: input.laneOrderInCampaign,
10502
+ orderInLane: input.orderInLane,
10503
+ staffingHint: input.staffingHint,
10504
+ domainPackId: input.domainPackId,
10505
+ lensId: input.lensId,
10506
+ linkedQuestionId: input.linkedQuestionId,
10507
+ lastReconciledAt: input.lastReconciledAt
10508
+ }),
9645
10509
  context
9646
10510
  )
9647
10511
  }
@@ -9659,7 +10523,7 @@ var worktreesContracts = [
9659
10523
  module: "worktrees",
9660
10524
  functionName: "activate",
9661
10525
  kind: "mutation",
9662
- inputProjection: worktreeInput
10526
+ inputProjection: activateWorktreeInput
9663
10527
  }
9664
10528
  }),
9665
10529
  surfaceContract({
@@ -9675,7 +10539,36 @@ var worktreesContracts = [
9675
10539
  convex: {
9676
10540
  module: "worktrees",
9677
10541
  functionName: "list",
9678
- kind: "query"
10542
+ kind: "query",
10543
+ inputProjection: (input) => compactRecord4({
10544
+ topicId: input.topicId,
10545
+ status: input.status,
10546
+ groupBy: input.groupBy,
10547
+ lane: input.lane,
10548
+ campaign: input.campaign,
10549
+ limit: input.limit
10550
+ })
10551
+ }
10552
+ }),
10553
+ surfaceContract({
10554
+ name: "list_campaigns",
10555
+ kind: "query",
10556
+ domain: "worktrees",
10557
+ surfaceClass: "platform_public",
10558
+ method: "GET",
10559
+ path: "/worktrees/campaigns",
10560
+ sdkNamespace: "worktrees",
10561
+ sdkMethod: "listCampaigns",
10562
+ summary: "List compact pipeline campaigns with nested lanes.",
10563
+ convex: {
10564
+ module: "worktrees",
10565
+ functionName: "listCampaigns",
10566
+ kind: "query",
10567
+ inputProjection: (input) => compactRecord4({
10568
+ topicId: input.topicId,
10569
+ status: input.status,
10570
+ limit: input.limit
10571
+ })
9679
10572
  }
9680
10573
  }),
9681
10574
  surfaceContract({
@@ -9691,7 +10584,8 @@ var worktreesContracts = [
9691
10584
  convex: {
9692
10585
  module: "worktrees",
9693
10586
  functionName: "listAll",
9694
- kind: "query"
10587
+ kind: "query",
10588
+ inputProjection: listAllWorktreesInput
9695
10589
  }
9696
10590
  }),
9697
10591
  surfaceContract({
@@ -9708,7 +10602,7 @@ var worktreesContracts = [
9708
10602
  module: "worktrees",
9709
10603
  functionName: "updateTargets",
9710
10604
  kind: "mutation",
9711
- inputProjection: worktreeInput
10605
+ inputProjection: worktreeTargetsInput
9712
10606
  }
9713
10607
  }),
9714
10608
  surfaceContract({
@@ -9725,7 +10619,7 @@ var worktreesContracts = [
9725
10619
  module: "worktrees",
9726
10620
  functionName: "updateMetadata",
9727
10621
  kind: "mutation",
9728
- inputProjection: worktreeInput
10622
+ inputProjection: worktreeMetadataInput
9729
10623
  }
9730
10624
  }),
9731
10625
  surfaceContract({
@@ -9741,12 +10635,17 @@ var worktreesContracts = [
9741
10635
  module: "worktrees",
9742
10636
  functionName: "complete",
9743
10637
  kind: "mutation",
9744
- inputProjection: (input) => ({
9745
- ...worktreeInput(input),
9746
- keyFindings: input.keyFindings ?? [input.summary ?? "Merged worktree"],
9747
- decisionsReached: input.decisionsReached ?? [],
9748
- nextSteps: input.nextSteps ?? []
9749
- })
10638
+ inputProjection: (input, context) => withUserId(
10639
+ {
10640
+ ...worktreeIdInput(input),
10641
+ keyFindings: input.keyFindings ?? [
10642
+ input.summary ?? "Merged worktree"
10643
+ ],
10644
+ decisionsReached: input.decisionsReached ?? [],
10645
+ nextSteps: input.nextSteps ?? []
10646
+ },
10647
+ context
10648
+ )
9750
10649
  }
9751
10650
  }),
9752
10651
  surfaceContract({
@@ -9762,11 +10661,7 @@ var worktreesContracts = [
9762
10661
  module: "worktrees",
9763
10662
  functionName: "updateMetadata",
9764
10663
  kind: "mutation",
9765
- inputProjection: (input) => ({
9766
- ...worktreeInput(input),
9767
- lastPushTargetContext: input.targetContext,
9768
- lastPushBeliefIds: input.beliefIds
9769
- })
10664
+ inputProjection: worktreeMetadataInput
9770
10665
  }
9771
10666
  }),
9772
10667
  surfaceContract({
@@ -9782,20 +10677,30 @@ var worktreesContracts = [
9782
10677
  module: "worktrees",
9783
10678
  functionName: "updateMetadata",
9784
10679
  kind: "mutation",
9785
- inputProjection: (input) => ({
9786
- ...worktreeInput(input),
9787
- lastPullRequestSummary: input.summary,
9788
- lastPullRequestReviewers: input.reviewers
9789
- })
10680
+ inputProjection: worktreeMetadataInput
9790
10681
  }
9791
10682
  })
9792
10683
  ];
9793
10684
 
9794
10685
  // ../contracts/src/function-registry/tasks.ts
9795
- var taskInput = (input) => ({
10686
+ var taskInput = (input) => compactRecord4({
9796
10687
  ...input,
9797
10688
  taskId: input.taskId ?? input.id
9798
10689
  });
10690
+ var taskTopicInput = (input) => {
10691
+ const parsed = listTasksProjection.inputSchema.safeParse(input);
10692
+ if (!parsed.success) {
10693
+ throw new Error(
10694
+ `list_tasks projection input rejected: ${parsed.error.message}`
10695
+ );
10696
+ }
10697
+ return compactRecord4(listTasksProjection.project(parsed.data));
10698
+ };
10699
+ var completeTaskInput = (input) => compactRecord4({
10700
+ taskId: input.taskId ?? input.id,
10701
+ outputSummary: input.outputSummary ?? input.summary,
10702
+ userId: input.userId
10703
+ });
9799
10704
  var tasksContracts = [
9800
10705
  surfaceContract({
9801
10706
  name: "create_task",
@@ -9825,8 +10730,10 @@ var tasksContracts = [
9825
10730
  convex: {
9826
10731
  module: "tasks",
9827
10732
  functionName: "getByTopic",
9828
- kind: "query"
9829
- }
10733
+ kind: "query",
10734
+ inputProjection: taskTopicInput
10735
+ },
10736
+ args: listTasksInputSchema
9830
10737
  }),
9831
10738
  surfaceContract({
9832
10739
  name: "update_task",
@@ -9858,12 +10765,29 @@ var tasksContracts = [
9858
10765
  module: "tasks",
9859
10766
  functionName: "complete",
9860
10767
  kind: "mutation",
9861
- inputProjection: taskInput
10768
+ inputProjection: completeTaskInput
9862
10769
  }
9863
10770
  })
9864
10771
  ];
9865
-
9866
- // ../contracts/src/function-registry/edges.ts
10772
+ var createEdgeArgs = z.object({
10773
+ from: GraphRefSchema,
10774
+ to: GraphRefSchema,
10775
+ edgeType: z.string(),
10776
+ globalId: z.string().optional(),
10777
+ weight: z.number().optional(),
10778
+ confidence: z.number().optional(),
10779
+ context: z.string().optional(),
10780
+ reasoning: z.string().optional(),
10781
+ derivationType: z.string().optional(),
10782
+ topicId: z.string().optional(),
10783
+ trustedBypassAccessCheck: z.boolean().optional()
10784
+ });
10785
+ function graphRefNodeId(ref) {
10786
+ if (ref.kind === "epistemic_node") {
10787
+ return ref.nodeId;
10788
+ }
10789
+ return `external_belief:${ref.ref.tenantId}:${ref.ref.beliefId}`;
10790
+ }
9867
10791
  var edgesContracts = [
9868
10792
  surfaceContract({
9869
10793
  name: "create_edge",
@@ -9878,16 +10802,35 @@ var edgesContracts = [
9878
10802
  module: "edges",
9879
10803
  functionName: "create",
9880
10804
  kind: "mutation",
9881
- inputProjection: (input, context) => withCreatedBy(
9882
- {
9883
- ...input,
9884
- fromNodeId: input.fromNodeId ?? input.sourceId,
9885
- toNodeId: input.toNodeId ?? input.targetId,
9886
- context: input.context ?? input.reasoning
9887
- },
9888
- context
9889
- )
9890
- }
10805
+ inputProjection: (input, context) => {
10806
+ const parsed = createEdgeArgs.parse(input);
10807
+ assertEdgePolicyAllowed(
10808
+ edgePolicyManifest,
10809
+ parsed.edgeType,
10810
+ parsed.from,
10811
+ parsed.to
10812
+ );
10813
+ const fromNodeId = graphRefNodeId(parsed.from);
10814
+ const toNodeId = graphRefNodeId(parsed.to);
10815
+ return withCreatedBy(
10816
+ compactRecord4({
10817
+ fromNodeId,
10818
+ toNodeId,
10819
+ edgeType: parsed.edgeType,
10820
+ globalId: parsed.globalId ?? `edge:${fromNodeId}:${toNodeId}:${parsed.edgeType}`,
10821
+ weight: parsed.weight,
10822
+ confidence: parsed.confidence,
10823
+ context: parsed.context ?? parsed.reasoning,
10824
+ derivationType: parsed.derivationType,
10825
+ skipLayerValidation: true,
10826
+ topicId: parsed.topicId,
10827
+ trustedBypassAccessCheck: parsed.trustedBypassAccessCheck
10828
+ }),
10829
+ context
10830
+ );
10831
+ }
10832
+ },
10833
+ args: createEdgeArgs
9891
10834
  }),
9892
10835
  surfaceContract({
9893
10836
  name: "query_lineage",
@@ -9902,9 +10845,12 @@ var edgesContracts = [
9902
10845
  module: "edges",
9903
10846
  functionName: "getLineage",
9904
10847
  kind: "query",
9905
- inputProjection: (input) => ({
9906
- ...input,
9907
- maxDepth: input.maxDepth ?? input.depth
10848
+ inputProjection: (input) => compactRecord4({
10849
+ nodeId: input.nodeId ?? input.startNode,
10850
+ maxDepth: input.maxDepth ?? input.depth,
10851
+ mode: input.mode,
10852
+ minLayer: input.minLayer,
10853
+ maxLayer: input.maxLayer
9908
10854
  })
9909
10855
  }
9910
10856
  })
@@ -9924,8 +10870,7 @@ var contradictionSeverity = (value) => {
9924
10870
  return "significant";
9925
10871
  }
9926
10872
  };
9927
- var flagContradictionInput = (input, context) => ({
9928
- ...input,
10873
+ var flagContradictionInput = (input, context) => compactRecord4({
9929
10874
  beliefId: input.beliefId ?? input.beliefA,
9930
10875
  supportingInsightIds: Array.isArray(input.supportingInsightIds) ? input.supportingInsightIds : [],
9931
10876
  contradictingInsightIds: Array.isArray(input.contradictingInsightIds) ? input.contradictingInsightIds : [input.beliefB].filter((value) => typeof value === "string"),
@@ -9939,6 +10884,18 @@ var flagContradictionInput = (input, context) => ({
9939
10884
  },
9940
10885
  createdBy: authUserId(context)
9941
10886
  });
10887
+ var lineageInput = (input) => compactRecord4({
10888
+ nodeId: input.nodeId ?? input.startNode ?? input.entityId,
10889
+ maxDepth: input.maxDepth ?? input.depth,
10890
+ mode: input.mode,
10891
+ minLayer: input.minLayer,
10892
+ maxLayer: input.maxLayer
10893
+ });
10894
+ var topicEdgesInput = (input) => compactRecord4({
10895
+ topicId: input.topicId,
10896
+ userId: input.userId,
10897
+ limit: input.limit
10898
+ });
9942
10899
  var graphContracts = [
9943
10900
  surfaceContract({
9944
10901
  name: "traverse_graph",
@@ -9952,7 +10909,8 @@ var graphContracts = [
9952
10909
  convex: {
9953
10910
  module: "edges",
9954
10911
  functionName: "getLineage",
9955
- kind: "query"
10912
+ kind: "query",
10913
+ inputProjection: lineageInput
9956
10914
  }
9957
10915
  }),
9958
10916
  surfaceContract({
@@ -9967,7 +10925,8 @@ var graphContracts = [
9967
10925
  convex: {
9968
10926
  module: "edges",
9969
10927
  functionName: "getByTopic",
9970
- kind: "query"
10928
+ kind: "query",
10929
+ inputProjection: topicEdgesInput
9971
10930
  }
9972
10931
  }),
9973
10932
  surfaceContract({
@@ -9997,7 +10956,10 @@ var graphContracts = [
9997
10956
  convex: {
9998
10957
  module: "edges",
9999
10958
  functionName: "findContradictions",
10000
- kind: "query"
10959
+ kind: "query",
10960
+ inputProjection: (input) => compactRecord4({
10961
+ nodeId: input.nodeId ?? input.beliefId
10962
+ })
10001
10963
  }
10002
10964
  }),
10003
10965
  surfaceContract({
@@ -10102,8 +11064,9 @@ var graphContracts = [
10102
11064
  summary: "Discover graph connections for an entity.",
10103
11065
  convex: {
10104
11066
  module: "edges",
10105
- functionName: "getByTopic",
10106
- kind: "query"
11067
+ functionName: "getLineage",
11068
+ kind: "query",
11069
+ inputProjection: lineageInput
10107
11070
  }
10108
11071
  }),
10109
11072
  surfaceContract({
@@ -10134,10 +11097,7 @@ var graphContracts = [
10134
11097
  module: "edges",
10135
11098
  functionName: "getLineage",
10136
11099
  kind: "query",
10137
- inputProjection: (input) => ({
10138
- ...input,
10139
- nodeId: input.nodeId ?? input.entityId
10140
- })
11100
+ inputProjection: lineageInput
10141
11101
  }
10142
11102
  })
10143
11103
  ];
@@ -10207,19 +11167,21 @@ var judgmentsContracts = [
10207
11167
  functionName: "create",
10208
11168
  kind: "mutation",
10209
11169
  inputProjection: (input, context) => withUserId(
10210
- {
10211
- ...input,
11170
+ compactRecord4({
11171
+ projectId: input.projectId,
11172
+ topicId: input.topicId,
10212
11173
  text: input.rationale,
10213
11174
  title: input.title,
10214
11175
  content: input.rationale,
10215
11176
  kind: "judgment",
10216
- sourceType: "agent",
10217
- metadata: {
11177
+ sourceType: "ai_generated",
11178
+ metadata: compactRecord4({
10218
11179
  confidence: input.confidence,
10219
11180
  beliefIds: input.beliefIds
10220
- },
11181
+ }),
11182
+ rationale: input.rationale ?? input.reasoning ?? "Recorded judgment evidence",
10221
11183
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10222
- },
11184
+ }),
10223
11185
  context
10224
11186
  )
10225
11187
  }
@@ -10237,9 +11199,12 @@ var judgmentsContracts = [
10237
11199
  module: "edges",
10238
11200
  functionName: "getLineage",
10239
11201
  kind: "query",
10240
- inputProjection: (input) => ({
10241
- ...input,
10242
- nodeId: input.nodeId ?? input.id
11202
+ inputProjection: (input) => compactRecord4({
11203
+ nodeId: input.nodeId ?? input.id,
11204
+ maxDepth: input.maxDepth ?? input.depth,
11205
+ mode: input.mode,
11206
+ minLayer: input.minLayer,
11207
+ maxLayer: input.maxLayer
10243
11208
  })
10244
11209
  }
10245
11210
  })
@@ -10365,7 +11330,10 @@ var coordinationContracts = [
10365
11330
  module: "coordination",
10366
11331
  functionName: "getInbox",
10367
11332
  kind: "query",
10368
- injectSessionId: "sessionId"
11333
+ injectSessionId: "sessionId",
11334
+ inputProjection: (input) => compactRecord4({
11335
+ limit: input.limit
11336
+ })
10369
11337
  }
10370
11338
  }),
10371
11339
  surfaceContract({
@@ -10383,7 +11351,6 @@ var coordinationContracts = [
10383
11351
  kind: "mutation",
10384
11352
  injectSessionId: "sessionId",
10385
11353
  inputProjection: (input) => ({
10386
- ...input,
10387
11354
  touchedFiles: stringArray(input.touchedFiles) ?? stringArray(input.files) ?? stringArray(input.paths) ?? []
10388
11355
  })
10389
11356
  }
@@ -10400,7 +11367,10 @@ var coordinationContracts = [
10400
11367
  convex: {
10401
11368
  module: "worktrees",
10402
11369
  functionName: "get",
10403
- kind: "query"
11370
+ kind: "query",
11371
+ inputProjection: (input) => compactRecord4({
11372
+ worktreeId: input.worktreeId ?? input.id
11373
+ })
10404
11374
  }
10405
11375
  })
10406
11376
  ];
@@ -10419,7 +11389,13 @@ var pipelineContracts = [
10419
11389
  convex: {
10420
11390
  module: "worktrees",
10421
11391
  functionName: "listAll",
10422
- kind: "query"
11392
+ kind: "query",
11393
+ inputProjection: (input) => compactRecord4({
11394
+ status: input.status,
11395
+ lane: input.lane,
11396
+ campaign: input.campaign,
11397
+ limit: input.limit
11398
+ })
10423
11399
  }
10424
11400
  }),
10425
11401
  surfaceContract({
@@ -10469,43 +11445,63 @@ var recordScopeLearningArgs = z.object({
10469
11445
  linkedBeliefNodeId: z.string().optional().describe("Optional belief to attach evidence to"),
10470
11446
  evidenceRelation: z.enum(["supports", "contradicts"]).optional().describe("Relation to linked belief"),
10471
11447
  confidence: z.number().optional().describe("Optional confidence in [0,1]"),
11448
+ rationale: z.string().optional().describe("Why this learning should enter the reasoning graph"),
10472
11449
  createQuestionText: z.string().optional().describe("Optional follow-up question text"),
10473
11450
  createBeliefText: z.string().optional().describe("Optional new belief text"),
10474
11451
  beliefType: z.string().optional().describe("Optional belief type for createBeliefText")
10475
11452
  });
10476
- var learningInput = (input, context) => withUserId(
10477
- {
10478
- ...input,
10479
- text: input.summary ?? input.text,
10480
- title: input.title ?? input.summary ?? "Scope learning",
10481
- content: input.body ?? input.content ?? input.summary,
10482
- kind: input.kind ?? input.sourceKind ?? "learning",
10483
- tags: input.tags ?? [],
10484
- metadata: {
10485
- sourceRef: input.sourceRef,
10486
- sourceKind: input.sourceKind,
10487
- touchedPaths: input.touchedPaths
10488
- },
10489
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10490
- },
10491
- context
10492
- );
11453
+ var learningInput = (input, context) => {
11454
+ const sourceKind = input.sourceKind ?? input.externalSourceType;
11455
+ return withUserId(
11456
+ compactRecord4({
11457
+ projectId: input.projectId,
11458
+ topicId: input.topicId,
11459
+ text: input.summary ?? input.text,
11460
+ title: input.title ?? input.summary ?? "Scope learning",
11461
+ content: input.body ?? input.content ?? input.summary,
11462
+ contentType: input.contentType,
11463
+ kind: input.kind ?? "learning",
11464
+ tags: input.tags ?? [],
11465
+ sourceType: input.sourceType,
11466
+ externalSourceType: input.externalSourceType ?? input.sourceKind,
11467
+ sourceUrl: input.sourceUrl,
11468
+ metadata: compactRecord4({
11469
+ ...recordValue2(input.metadata),
11470
+ sourceRef: input.sourceRef,
11471
+ sourceKind,
11472
+ touchedPaths: input.touchedPaths,
11473
+ createQuestionText: input.createQuestionText,
11474
+ createBeliefText: input.createBeliefText,
11475
+ beliefType: input.beliefType
11476
+ }),
11477
+ linkedBeliefNodeId: input.linkedBeliefNodeId,
11478
+ evidenceRelation: input.evidenceRelation,
11479
+ confidence: input.confidence,
11480
+ rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded scope learning",
11481
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
11482
+ }),
11483
+ context
11484
+ );
11485
+ };
10493
11486
  var attemptInput = (input, context) => withUserId(
10494
- {
10495
- ...input,
11487
+ compactRecord4({
11488
+ projectId: input.projectId,
11489
+ topicId: input.topicId,
10496
11490
  text: input.description,
10497
11491
  title: input.title ?? input.description,
10498
11492
  content: input.errorMessage ?? input.description,
10499
11493
  kind: "code_attempt",
10500
11494
  tags: ["code_attempt"],
10501
- metadata: {
11495
+ metadata: compactRecord4({
11496
+ ...recordValue2(input.metadata),
10502
11497
  filePaths: input.filePaths,
10503
11498
  filePath: input.filePath,
10504
11499
  errorMessage: input.errorMessage,
10505
11500
  linkedBeliefId: input.linkedBeliefId
10506
- },
11501
+ }),
11502
+ rationale: input.rationale ?? input.reasoning ?? input.errorMessage ?? input.description ?? "Recorded implementation attempt",
10507
11503
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10508
- },
11504
+ }),
10509
11505
  context
10510
11506
  );
10511
11507
  var codingContracts = [
@@ -10562,7 +11558,13 @@ var codingContracts = [
10562
11558
  convex: {
10563
11559
  module: "evidence",
10564
11560
  functionName: "getByTopic",
10565
- kind: "query"
11561
+ kind: "query",
11562
+ inputProjection: (input) => compactRecord4({
11563
+ topicId: input.topicId,
11564
+ limit: input.limit,
11565
+ status: input.status,
11566
+ userId: input.userId
11567
+ })
10566
11568
  }
10567
11569
  }),
10568
11570
  surfaceContract({
@@ -10577,7 +11579,13 @@ var codingContracts = [
10577
11579
  convex: {
10578
11580
  module: "evidence",
10579
11581
  functionName: "getByTopic",
10580
- kind: "query"
11582
+ kind: "query",
11583
+ inputProjection: (input) => compactRecord4({
11584
+ topicId: input.topicId,
11585
+ limit: input.limit,
11586
+ status: input.status,
11587
+ userId: input.userId
11588
+ })
10581
11589
  }
10582
11590
  }),
10583
11591
  surfaceContract({
@@ -10609,9 +11617,11 @@ var codingContracts = [
10609
11617
  module: "evidence",
10610
11618
  functionName: "getByTopic",
10611
11619
  kind: "query",
10612
- inputProjection: (input) => ({
10613
- ...input,
10614
- topicId: input.topicId ?? input.query
11620
+ inputProjection: (input) => compactRecord4({
11621
+ topicId: input.topicId ?? input.query,
11622
+ limit: input.limit,
11623
+ status: input.status,
11624
+ userId: input.userId
10615
11625
  })
10616
11626
  }
10617
11627
  })
@@ -10671,11 +11681,124 @@ new Map(
10671
11681
  var ROOT_TOPIC_ID = "n17tm38rwet7wqgzrmwahyt1z582590y";
10672
11682
 
10673
11683
  // ../server-core/src/kernelApi.ts
11684
+ var REQUIRED_KERNEL_API_REF_SUFFIXES = [
11685
+ "contradictions.create",
11686
+ "contradictions.getById",
11687
+ "contradictions.getByTopic",
11688
+ "epistemicAnswers.create",
11689
+ "epistemicAnswers.getLatestForQuestion",
11690
+ "epistemicBeliefs.archive",
11691
+ "epistemicBeliefs.batchUpdateCriticality",
11692
+ "epistemicBeliefs.create",
11693
+ "epistemicBeliefs.forkBelief",
11694
+ "epistemicBeliefs.getById",
11695
+ "epistemicBeliefs.getByTopic",
11696
+ "epistemicBeliefs.getConfidenceHistory",
11697
+ "epistemicBeliefs.getLineage",
11698
+ "epistemicBeliefs.getRelationships",
11699
+ "epistemicBeliefs.linkBeliefs",
11700
+ "epistemicBeliefs.linkEvidence",
11701
+ "epistemicBeliefs.modulateConfidence",
11702
+ "epistemicBeliefs.reassignBeliefsTopic",
11703
+ "epistemicBeliefs.refineBelief",
11704
+ "epistemicBeliefs.unlinkEvidence",
11705
+ "epistemicBeliefs.updateCriticality",
11706
+ "epistemicBeliefs.updateRationale",
11707
+ "epistemicBeliefs.updateStatus",
11708
+ "epistemicContracts.createEpistemicContract",
11709
+ "epistemicContracts.evaluateContract",
11710
+ "epistemicContracts.getContractStatus",
11711
+ "epistemicEdges.batchCreate",
11712
+ "epistemicEdges.create",
11713
+ "epistemicEdges.deleteEdges",
11714
+ "epistemicEdges.getBySourceNode",
11715
+ "epistemicEdges.getByTopicAndType",
11716
+ "epistemicEdges.remove",
11717
+ "epistemicEdges.removeBetween",
11718
+ "epistemicEdges.update",
11719
+ "epistemicEvidence.create",
11720
+ "epistemicEvidence.flagAsIncorrect",
11721
+ "epistemicEvidence.getById",
11722
+ "epistemicEvidence.getByTopic",
11723
+ "epistemicEvidence.getForBelief",
11724
+ "epistemicEvidence.remove",
11725
+ "epistemicEvidence.update",
11726
+ "epistemicEvidence.updateStatus",
11727
+ "epistemicEvidence.updateVerificationStatus",
11728
+ "epistemicNodes.get",
11729
+ "epistemicNodes.getByGlobalId",
11730
+ "epistemicQuestions.addQuestion",
11731
+ "epistemicQuestions.advanceToConviction",
11732
+ "epistemicQuestions.create",
11733
+ "epistemicQuestions.createBatch",
11734
+ "epistemicQuestions.deleteQuestion",
11735
+ "epistemicQuestions.finalizeConviction",
11736
+ "epistemicQuestions.getById",
11737
+ "epistemicQuestions.getByTopic",
11738
+ "epistemicQuestions.internalCreate",
11739
+ "epistemicQuestions.updateConviction",
11740
+ "epistemicQuestions.updatePriority",
11741
+ "epistemicQuestions.updateQuestion",
11742
+ "epistemicQuestions.updateStatus",
11743
+ "evidenceClassifier.classifyEvidence",
11744
+ "evidenceClassifier.classifyEvidenceBatch",
11745
+ "graphAnalysisCache.getCachedAnalysis",
11746
+ "graphIntelligence.analyzeProject",
11747
+ "neo4jEdgeAPI.getGraphNeighborhood",
11748
+ "neo4jQueries.getConfirmationBiasScore",
11749
+ "ontologyDefinitions.archiveOntologyDefinition",
11750
+ "ontologyDefinitions.createOntologyDefinition",
11751
+ "ontologyDefinitions.createOntologyVersion",
11752
+ "ontologyDefinitions.deprecateOntologyVersion",
11753
+ "ontologyDefinitions.getOntologyDefinition",
11754
+ "ontologyDefinitions.getOntologyDefinitionByKey",
11755
+ "ontologyDefinitions.getPublishedVersion",
11756
+ "ontologyDefinitions.listOntologyDefinitions",
11757
+ "ontologyDefinitions.publishOntologyVersion",
11758
+ "ontologyDefinitions.resolveEffectiveOntology",
11759
+ "ontologyDefinitions.updateOntologyDefinition",
11760
+ "policy.filterByPermission",
11761
+ "questionEvidenceLinks.create",
11762
+ "questionEvidenceLinks.getEvidenceWithDetails",
11763
+ "tasks.complete",
11764
+ "tasks.create",
11765
+ "tasks.get",
11766
+ "tasks.getByTopic",
11767
+ "tasks.getByWorktree",
11768
+ "tasks.update",
11769
+ "topics.bulkCreate",
11770
+ "topics.checkAccess",
11771
+ "topics.create",
11772
+ "topics.get",
11773
+ "topics.getTree",
11774
+ "topics.list",
11775
+ "topics.listByOntology",
11776
+ "topics.remove",
11777
+ "topics.resolveTopicOntology",
11778
+ "topics.update",
11779
+ "worktrees.activate",
11780
+ "worktrees.advancePhase",
11781
+ "worktrees.bulkCreate",
11782
+ "worktrees.complete",
11783
+ "worktrees.create",
11784
+ "worktrees.get",
11785
+ "worktrees.list",
11786
+ "worktrees.listAll",
11787
+ "worktrees.patchState",
11788
+ "worktrees.setPhase",
11789
+ "worktrees.updateMetadata",
11790
+ "worktrees.updateTargets"
11791
+ ];
11792
+ var KERNEL_API_REF_MANIFEST = REQUIRED_KERNEL_API_REF_SUFFIXES.map((path3) => ({
11793
+ path: `api.${path3}`,
11794
+ componentPath: `components.lucern.${path3}`
11795
+ }));
10674
11796
  var GLOBAL_KEY = "__LUCERN_SERVER_CORE_KERNEL_API_BINDING__";
10675
11797
  function store() {
10676
11798
  return globalThis;
10677
11799
  }
10678
11800
  function registerKernelApi(nextBinding) {
11801
+ assertKernelApiBinding(nextBinding);
10679
11802
  store()[GLOBAL_KEY] = nextBinding;
10680
11803
  }
10681
11804
  function getBinding() {
@@ -10687,10 +11810,55 @@ function getBinding() {
10687
11810
  }
10688
11811
  return current;
10689
11812
  }
10690
- function makeProxy(which) {
11813
+ function readPath(root, path3) {
11814
+ let cursor = root;
11815
+ for (const part of path3) {
11816
+ if (cursor == null || typeof cursor !== "object") {
11817
+ return void 0;
11818
+ }
11819
+ cursor = cursor[part];
11820
+ }
11821
+ return cursor;
11822
+ }
11823
+ function resolveApiPath(binding, which, path3) {
11824
+ return readPath(binding[which], path3);
11825
+ }
11826
+ function validateKernelApiBinding(binding) {
11827
+ const missing = [];
11828
+ const resolved = [];
11829
+ for (const entry of KERNEL_API_REF_MANIFEST) {
11830
+ const suffix = entry.path.split(".").slice(1);
11831
+ const reference = resolveApiPath(binding, "api", suffix);
11832
+ if (reference === void 0) {
11833
+ missing.push(entry);
11834
+ } else {
11835
+ resolved.push(entry);
11836
+ }
11837
+ }
11838
+ return {
11839
+ ok: missing.length === 0,
11840
+ missing,
11841
+ resolved
11842
+ };
11843
+ }
11844
+ function assertKernelApiBinding(binding) {
11845
+ const result = validateKernelApiBinding(binding);
11846
+ if (!result.ok) {
11847
+ const refs = result.missing.map((entry) => entry.path).join(", ");
11848
+ throw new Error(
11849
+ `Server-core kernelApi binding is missing required refs: ${refs}`
11850
+ );
11851
+ }
11852
+ }
11853
+ function makeProxy(which, path3 = []) {
10691
11854
  return new Proxy({}, {
10692
11855
  get(_target, prop) {
10693
- return getBinding()[which][prop];
11856
+ if (typeof prop !== "string") {
11857
+ return void 0;
11858
+ }
11859
+ const nextPath = [...path3, prop];
11860
+ const resolved = resolveApiPath(getBinding(), which, nextPath);
11861
+ return resolved === void 0 ? makeProxy(which, nextPath) : resolved;
10694
11862
  }
10695
11863
  });
10696
11864
  }
@@ -10794,10 +11962,7 @@ async function resolveMutationRuntimeFields(toolName) {
10794
11962
  let cached = mutationRuntimeCache.get(normalizedToolName);
10795
11963
  if (!cached) {
10796
11964
  cached = (async () => {
10797
- const tools = await getLucernClient().query(
10798
- api2.toolAccess.getExecutableTools,
10799
- {}
10800
- );
11965
+ const tools = await adminQuery("toolAccess:listToolRegistry", {});
10801
11966
  const tool = tools.find(
10802
11967
  (candidate) => candidate?.toolName === normalizedToolName && candidate?.isActive !== false && candidate?.status !== "deprecated" && candidate?.status !== "disabled"
10803
11968
  );
@@ -10915,7 +12080,7 @@ async function tryGetTopicById(topicId) {
10915
12080
  }
10916
12081
  async function tryGetNodeById(nodeId) {
10917
12082
  try {
10918
- const node = await adminQuery(components2.lucern.epistemicNodes.getInternal, {
12083
+ const node = await adminQuery(api2.epistemicNodes.getInternal, {
10919
12084
  nodeId
10920
12085
  });
10921
12086
  return node || null;
@@ -11002,10 +12167,10 @@ function readOpinionTuple(args) {
11002
12167
  );
11003
12168
  }
11004
12169
  return {
11005
- b: belief ?? 0,
11006
- d: disbelief ?? 0,
11007
- u: uncertainty ?? 0,
11008
- a: baseRate ?? 0.5
12170
+ b: belief,
12171
+ d: disbelief,
12172
+ u: uncertainty,
12173
+ a: baseRate
11009
12174
  };
11010
12175
  }
11011
12176
  var beliefHandlers = {
@@ -11073,6 +12238,11 @@ var beliefHandlers = {
11073
12238
  opinion,
11074
12239
  trigger: readString(args.trigger),
11075
12240
  rationale: readString(args.rationale) ?? "",
12241
+ triggeringEvidenceId: readString(args.triggeringEvidenceId),
12242
+ triggeringQuestionId: readString(args.triggeringQuestionId),
12243
+ triggeringAnswerId: readString(args.triggeringAnswerId),
12244
+ triggeringContradictionId: readString(args.triggeringContradictionId),
12245
+ triggeringWorktreeId: readString(args.triggeringWorktreeId),
11076
12246
  maxInlinePropagationTargets: readNumber(
11077
12247
  args.maxInlinePropagationTargets
11078
12248
  )
@@ -11161,7 +12331,7 @@ async function resolveBeliefs(nodeIds) {
11161
12331
  const results = [];
11162
12332
  for (const nodeId of nodeIds) {
11163
12333
  try {
11164
- const node = await adminQuery(components2.lucern.epistemicNodes.get, {
12334
+ const node = await adminQuery(api2.epistemicNodes.get, {
11165
12335
  nodeId
11166
12336
  });
11167
12337
  if (!node) {
@@ -11181,7 +12351,7 @@ async function resolveQuestions(nodeIds) {
11181
12351
  const results = [];
11182
12352
  for (const nodeId of nodeIds) {
11183
12353
  try {
11184
- const node = await adminQuery(components2.lucern.epistemicNodes.get, {
12354
+ const node = await adminQuery(api2.epistemicNodes.get, {
11185
12355
  nodeId
11186
12356
  });
11187
12357
  if (!node) {
@@ -11217,9 +12387,10 @@ async function beginBuildSession(args) {
11217
12387
  }
11218
12388
  const worktreeName = String(worktree.name || "Untitled");
11219
12389
  const topicId = String(worktree.topicId || "");
11220
- const track = String(worktree.track || "untracked");
11221
- const trackPosition = worktree.trackPosition ?? 0;
11222
- const executionBand = worktree.executionBand ?? 0;
12390
+ const campaign = typeof worktree.campaign === "number" ? worktree.campaign : null;
12391
+ const lane = String(worktree.lane || "unlaned");
12392
+ const laneOrderInCampaign = typeof worktree.laneOrderInCampaign === "number" ? worktree.laneOrderInCampaign : null;
12393
+ const orderInLane = typeof worktree.orderInLane === "number" ? worktree.orderInLane : null;
11223
12394
  const gate = String(worktree.gate || "");
11224
12395
  const hypothesis = String(worktree.hypothesis || worktree.beliefFocus || "");
11225
12396
  let status = String(worktree.status || "planning");
@@ -11269,7 +12440,7 @@ async function beginBuildSession(args) {
11269
12440
  }
11270
12441
  } catch {
11271
12442
  try {
11272
- const node = await adminQuery(components2.lucern.epistemicNodes.get, {
12443
+ const node = await adminQuery(api2.epistemicNodes.get, {
11273
12444
  nodeId: question.nodeId
11274
12445
  });
11275
12446
  if (node?._id) {
@@ -11301,7 +12472,7 @@ async function beginBuildSession(args) {
11301
12472
  });
11302
12473
  }
11303
12474
  try {
11304
- const topicQuestions = await adminQuery(components2.lucern.epistemicQuestions.getByTopic, {
12475
+ const topicQuestions = await adminQuery(api2.epistemicQuestions.getByTopic, {
11305
12476
  topicId,
11306
12477
  userId: "system",
11307
12478
  limit: 20
@@ -11435,9 +12606,10 @@ async function beginBuildSession(args) {
11435
12606
  branch: effectiveBranch,
11436
12607
  branchBase,
11437
12608
  prBase,
11438
- track,
11439
- trackPosition,
11440
- executionBand,
12609
+ campaign,
12610
+ lane,
12611
+ laneOrderInCampaign,
12612
+ orderInLane,
11441
12613
  gate,
11442
12614
  hypothesis,
11443
12615
  focus,
@@ -12469,6 +13641,14 @@ var generatedFunctionSurfaceHandlers = {
12469
13641
  )
12470
13642
  );
12471
13643
  },
13644
+ async list_campaigns(args, ctx) {
13645
+ return formatSdkResult(
13646
+ await getSdkClient(ctx).raw.functionSurface.listCampaigns(
13647
+ stripInternalArgs(args),
13648
+ idempotencyKeyFrom(args)
13649
+ )
13650
+ );
13651
+ },
12472
13652
  async list_evidence(args, ctx) {
12473
13653
  return formatSdkResult(
12474
13654
  await getSdkClient(ctx).raw.functionSurface.listEvidence(
@@ -13846,7 +15026,7 @@ var researchVerificationHandlers = {
13846
15026
  async evaluate_research_contract(args, ctx) {
13847
15027
  const inputData = buildInputData(args);
13848
15028
  const result = await adminMutation(
13849
- api2.epistemicContracts.evaluateContractsForTrigger,
15029
+ api2.contracts.evaluateContractsForTrigger,
13850
15030
  {
13851
15031
  beliefNodeId: args.beliefNodeId,
13852
15032
  trigger: typeof args.trigger === "string" && args.trigger.length > 0 ? args.trigger : "event_driven",
@@ -14146,7 +15326,7 @@ var worktreeHandlers = {
14146
15326
  summary: objective ?? hypothesis ?? title,
14147
15327
  tags: [
14148
15328
  ...readStringArray(args.tags) ?? [],
14149
- ...readString(args.track) ? [readString(args.track)] : [],
15329
+ ...readString(args.lane) ? [readString(args.lane)] : [],
14150
15330
  ...readString(args.gate) ? [readString(args.gate)] : []
14151
15331
  ],
14152
15332
  sourceRef: title,
@@ -14161,7 +15341,10 @@ var worktreeHandlers = {
14161
15341
  beliefIds: readStringArray(args.beliefIds) ?? readStringArray(args.beliefs),
14162
15342
  autoShape: typeof args.autoShape === "boolean" ? args.autoShape : void 0,
14163
15343
  domainPackId: readString(args.domainPackId),
14164
- executionOrder: readNumber(args.executionOrder),
15344
+ campaign: readNumber(args.campaign),
15345
+ lane: readString(args.lane),
15346
+ laneOrderInCampaign: readNumber(args.laneOrderInCampaign),
15347
+ orderInLane: readNumber(args.orderInLane),
14165
15348
  dependsOn: readStringArray(args.dependsOn),
14166
15349
  blocks: readStringArray(args.blocks),
14167
15350
  gate: readString(args.gate),
@@ -14177,6 +15360,18 @@ var worktreeHandlers = {
14177
15360
  await getSdkClient(ctx).worktrees.list({
14178
15361
  topicId: readString(args.topicId ?? args.projectId) ?? "",
14179
15362
  status: readString(args.status),
15363
+ groupBy: readString(args.groupBy),
15364
+ lane: readString(args.lane),
15365
+ campaign: readNumber(args.campaign),
15366
+ limit: readNumber(args.limit)
15367
+ })
15368
+ );
15369
+ },
15370
+ async list_campaigns(args, ctx) {
15371
+ return formatSdkResult(
15372
+ await getSdkClient(ctx).worktrees.listCampaigns({
15373
+ topicId: readString(args.topicId ?? args.projectId),
15374
+ status: readString(args.status),
14180
15375
  limit: readNumber(args.limit)
14181
15376
  })
14182
15377
  );
@@ -14195,10 +15390,10 @@ var worktreeHandlers = {
14195
15390
  objective: readString(args.objective),
14196
15391
  hypothesis: readString(args.hypothesis),
14197
15392
  rationale: readString(args.rationale),
14198
- track: readString(args.track),
14199
- trackPosition: readNumber(args.trackPosition),
14200
- executionBand: readNumber(args.executionBand),
14201
- executionOrder: readNumber(args.executionOrder),
15393
+ campaign: readNumber(args.campaign),
15394
+ lane: readString(args.lane),
15395
+ laneOrderInCampaign: readNumber(args.laneOrderInCampaign),
15396
+ orderInLane: readNumber(args.orderInLane),
14202
15397
  dependsOn: readStringArray(args.dependsOn),
14203
15398
  blocks: readStringArray(args.blocks),
14204
15399
  gate: readString(args.gate),
@@ -14236,8 +15431,9 @@ var worktreeHandlers = {
14236
15431
  return formatSdkResult(
14237
15432
  await getSdkClient(ctx).worktrees.listAll({
14238
15433
  status: readString(args.status),
14239
- track: readString(args.track),
14240
- executionBand: readNumber(args.executionBand),
15434
+ lane: readString(args.lane),
15435
+ campaign: readNumber(args.campaign),
15436
+ groupBy: readString(args.groupBy),
14241
15437
  limit: readNumber(args.limit)
14242
15438
  })
14243
15439
  );
@@ -14427,7 +15623,7 @@ async function checkWritePolicy(toolName, topicId, authCtx) {
14427
15623
  return { allowed: true, permission: "allow", reason: "read_only_tool" };
14428
15624
  }
14429
15625
  try {
14430
- const result = await adminQuery(api2.mcpWritePolicy.checkAccess, {
15626
+ const result = await adminQuery("mcpWritePolicy:checkAccess", {
14431
15627
  topicId: topicId ?? void 0,
14432
15628
  role: authCtx.role,
14433
15629
  toolName