@lucern/events 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/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { v } from 'convex/values';
2
3
 
3
4
  // src/matching.ts
4
5
  function escapeRegex(value) {
@@ -559,6 +560,28 @@ defineTable({
559
560
  { kind: "index", name: "by_createdAt", columns: ["createdAt"] }
560
561
  ]
561
562
  });
563
+ defineTable({
564
+ name: "neo4jSyncQueue",
565
+ component: "kernel",
566
+ category: "infra",
567
+ shape: z.object({
568
+ "entityType": z.enum(["node", "edge"]),
569
+ "entityId": z.string(),
570
+ "operation": z.enum(["upsert", "delete"]),
571
+ "attempts": z.number(),
572
+ "maxAttempts": z.number(),
573
+ "lastAttemptAt": z.number().optional(),
574
+ "lastError": z.string().optional(),
575
+ "status": z.enum(["pending", "in_progress", "failed", "succeeded"]),
576
+ "createdAt": z.number(),
577
+ "updatedAt": z.number()
578
+ }),
579
+ indices: [
580
+ { kind: "index", name: "by_status", columns: ["status"] },
581
+ { kind: "index", name: "by_entity", columns: ["entityType", "entityId"] },
582
+ { kind: "index", name: "by_status_attempts", columns: ["status", "attempts"] }
583
+ ]
584
+ });
562
585
  defineTable({
563
586
  name: "backgroundJobRuns",
564
587
  component: "kernel",
@@ -628,9 +651,9 @@ defineTable({
628
651
  category: "epistemic",
629
652
  shape: z.object({
630
653
  "beliefId": z.string(),
631
- "belief": z.number().optional(),
632
- "disbelief": z.number().optional(),
633
- "uncertainty": z.number().optional(),
654
+ "belief": z.number(),
655
+ "disbelief": z.number(),
656
+ "uncertainty": z.number(),
634
657
  "baseRate": z.number(),
635
658
  "slOperator": z.string().optional(),
636
659
  "confidence": z.number(),
@@ -639,10 +662,12 @@ defineTable({
639
662
  "certainty": z.number().optional(),
640
663
  "assessedAt": z.number(),
641
664
  "assessedBy": z.string(),
642
- "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"]),
665
+ "trigger": z.enum(["initial", "evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "propagation", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction", "backfill_synthetic"]),
643
666
  "rationale": z.string().optional(),
644
667
  "triggeringEvidenceId": z.string().optional(),
645
668
  "triggeringEvidenceIds": z.array(z.string()).optional(),
669
+ "triggeringQuestionId": z.string().optional(),
670
+ "triggeringAnswerId": z.string().optional(),
646
671
  "triggeringContradictionId": idOf("contradictions").optional(),
647
672
  "triggeringWorktreeId": z.string().optional(),
648
673
  "triggeringAgentId": z.string().optional(),
@@ -1325,7 +1350,7 @@ defineTable({
1325
1350
  "credentialRef": z.string(),
1326
1351
  "tenantId": idOf("tenants"),
1327
1352
  "target": z.enum(["kernelDeployment", "appDeployment"]),
1328
- "environment": z.enum(["dev", "prod"]),
1353
+ "environment": z.enum(["dev", "staging", "prod"]),
1329
1354
  "encryptedDeployKey": z.string(),
1330
1355
  "encryptionVersion": z.string(),
1331
1356
  "keyFingerprint": z.string(),
@@ -3994,13 +4019,13 @@ defineTable({
3994
4019
  "rationale": z.string().optional(),
3995
4020
  "confidenceImpact": z.enum(["high", "medium", "low"]).optional(),
3996
4021
  "hypothesis": z.string().optional(),
3997
- "executionOrder": z.number().optional(),
3998
4022
  "dependsOn": z.array(idOf("worktrees")).optional(),
3999
4023
  "blocks": z.array(idOf("worktrees")).optional(),
4000
4024
  "gate": z.string().optional(),
4001
- "track": z.string().optional(),
4002
- "trackPosition": z.number().optional(),
4003
- "executionBand": z.number().optional(),
4025
+ "campaign": z.number().optional(),
4026
+ "lane": z.string().optional(),
4027
+ "laneOrderInCampaign": z.number().optional(),
4028
+ "orderInLane": z.number().optional(),
4004
4029
  "startDate": z.number(),
4005
4030
  "endDate": z.number(),
4006
4031
  "durationWeeks": z.number(),
@@ -4248,10 +4273,469 @@ defineTable({
4248
4273
  { kind: "index", name: "by_topicId_index", columns: ["topicId", "index"] },
4249
4274
  { kind: "index", name: "by_worktreeType", columns: ["topicId", "worktreeType"] },
4250
4275
  { kind: "index", name: "by_topicId_priority", columns: ["topicId", "priority"] },
4276
+ { kind: "index", name: "by_topicId_campaign_lane_order", columns: ["topicId", "campaign", "laneOrderInCampaign", "orderInLane"] },
4277
+ { kind: "index", name: "by_topicId_lane_order", columns: ["topicId", "lane", "orderInLane"] },
4251
4278
  { kind: "index", name: "by_topicId_branch", columns: ["topicId", "targetBranch"] },
4252
4279
  { kind: "index", name: "by_topicId_scope", columns: ["topicId", "worktreeScope"] }
4253
4280
  ]
4254
4281
  });
4282
+ z.object({
4283
+ manifestVersion: z.string(),
4284
+ componentName: z.enum(["kernel", "identity"]),
4285
+ tier: z.enum(["K", "I"]),
4286
+ packageVersion: z.string(),
4287
+ tables: z.array(
4288
+ z.object({
4289
+ name: z.string(),
4290
+ fields: z.array(
4291
+ z.object({
4292
+ name: z.string(),
4293
+ type: z.string(),
4294
+ optional: z.boolean(),
4295
+ validator: z.string().optional()
4296
+ })
4297
+ )
4298
+ })
4299
+ )
4300
+ });
4301
+ var SL_EPSILON = 1e-9;
4302
+ z.object({
4303
+ belief: z.number(),
4304
+ disbelief: z.number(),
4305
+ uncertainty: z.number(),
4306
+ baseRate: z.number()
4307
+ }).refine(
4308
+ (o) => Math.abs(o.belief + o.disbelief + o.uncertainty - 1) < SL_EPSILON,
4309
+ {
4310
+ message: "SL invariant b+d+u=1 violated at API boundary"
4311
+ }
4312
+ );
4313
+ var EpistemicNodeTypeSchema = z.enum([
4314
+ "belief",
4315
+ "evidence",
4316
+ "question",
4317
+ "answer",
4318
+ "topic",
4319
+ "edge",
4320
+ "ontology",
4321
+ "lens",
4322
+ "contradiction"
4323
+ ]);
4324
+ var GraphRefSchema = z.discriminatedUnion("kind", [
4325
+ z.object({
4326
+ kind: z.literal("epistemic_node"),
4327
+ nodeId: z.string(),
4328
+ nodeType: EpistemicNodeTypeSchema
4329
+ }),
4330
+ z.object({
4331
+ kind: z.literal("external_belief"),
4332
+ ref: z.object({
4333
+ tenantId: z.string(),
4334
+ beliefId: z.string()
4335
+ })
4336
+ })
4337
+ ]);
4338
+ var graphRefKind = z.enum(["epistemic_node", "external_belief"]);
4339
+ var EdgePolicyEntrySchema = z.object({
4340
+ edgeType: z.string(),
4341
+ fromKinds: z.array(graphRefKind),
4342
+ fromNodeTypes: z.array(EpistemicNodeTypeSchema).optional(),
4343
+ toKinds: z.array(graphRefKind),
4344
+ toNodeTypes: z.array(EpistemicNodeTypeSchema).optional(),
4345
+ description: z.string()
4346
+ });
4347
+ z.object({
4348
+ manifestVersion: z.literal("1.0.0"),
4349
+ policies: z.array(EdgePolicyEntrySchema)
4350
+ });
4351
+ function findEdgePolicy(manifest, edgeType) {
4352
+ return manifest.policies.find((policy) => policy.edgeType === edgeType);
4353
+ }
4354
+ function nodeTypeAllowed(allowed, ref) {
4355
+ return ref.kind !== "epistemic_node" || !allowed || allowed.includes(ref.nodeType);
4356
+ }
4357
+ function assertEdgePolicyAllowed(manifest, edgeType, from, to) {
4358
+ const policy = findEdgePolicy(manifest, edgeType);
4359
+ const allowed = Boolean(policy) && policy.fromKinds.includes(from.kind) && policy.toKinds.includes(to.kind) && nodeTypeAllowed(policy.fromNodeTypes, from) && nodeTypeAllowed(policy.toNodeTypes, to);
4360
+ if (!allowed) {
4361
+ const error = new Error(
4362
+ `Edge policy violation for ${edgeType}: ${from.kind} -> ${to.kind}`
4363
+ );
4364
+ error.code = "POLICY_VIOLATION";
4365
+ error.details = { code: "POLICY_VIOLATION", edgeType, from, to };
4366
+ throw error;
4367
+ }
4368
+ }
4369
+
4370
+ // ../contracts/src/manifests/edge-policy-manifest.data.ts
4371
+ var edgePolicyManifest = {
4372
+ policies: [
4373
+ {
4374
+ edgeType: "evidence_derived_from_evidence",
4375
+ fromKinds: ["epistemic_node"],
4376
+ fromNodeTypes: ["evidence"],
4377
+ toKinds: ["epistemic_node"],
4378
+ toNodeTypes: ["evidence"],
4379
+ description: "Evidence E2 was synthesized from evidence E1 by a transformation. Provides chain-of-evidence lineage."
4380
+ },
4381
+ {
4382
+ edgeType: "evidence_supports_belief",
4383
+ fromKinds: ["epistemic_node"],
4384
+ fromNodeTypes: ["evidence"],
4385
+ toKinds: ["epistemic_node"],
4386
+ toNodeTypes: ["belief"],
4387
+ description: "Existing link_evidence_to_belief semantics promoted to the create_edge policy source."
4388
+ },
4389
+ {
4390
+ edgeType: "evidence_supports_question",
4391
+ fromKinds: ["epistemic_node"],
4392
+ fromNodeTypes: ["evidence"],
4393
+ toKinds: ["epistemic_node"],
4394
+ toNodeTypes: ["question"],
4395
+ description: "Existing link_evidence_to_question semantics promoted to the create_edge policy source."
4396
+ }
4397
+ ]
4398
+ };
4399
+ z.object({
4400
+ manifestVersion: z.literal("1.0.0"),
4401
+ rules: z.array(
4402
+ z.object({
4403
+ invariant: z.string(),
4404
+ description: z.string(),
4405
+ checker: z.enum(["ast", "manifest", "runtime"]),
4406
+ severity: z.enum(["block_publish", "block_pr", "warn"])
4407
+ })
4408
+ )
4409
+ });
4410
+
4411
+ // ../contracts/src/projections/projection-dsl.ts
4412
+ function defineProjection(def) {
4413
+ return def;
4414
+ }
4415
+
4416
+ // ../contracts/src/projections/create-evidence.projection.ts
4417
+ var jsonRecordSchema = z.record(z.unknown());
4418
+ var createEvidenceInputSchemaBase = z.object({
4419
+ projectId: z.string().optional(),
4420
+ topicId: z.string().optional(),
4421
+ text: z.string().optional(),
4422
+ canonicalText: z.string().optional(),
4423
+ title: z.string().optional(),
4424
+ content: z.string().optional(),
4425
+ contentType: z.string().optional(),
4426
+ kind: z.string().optional(),
4427
+ tags: z.array(z.string()).optional(),
4428
+ source: z.string().optional(),
4429
+ sourceUrl: z.string().optional(),
4430
+ sourceType: z.string().optional(),
4431
+ externalSourceType: z.string().optional(),
4432
+ sourceQuestionId: z.string().optional(),
4433
+ methodology: z.string().optional(),
4434
+ informationAsymmetry: z.string().optional(),
4435
+ sourceDescription: z.string().optional(),
4436
+ targetId: z.string().optional(),
4437
+ targetNodeId: z.string().optional(),
4438
+ linkedBeliefNodeId: z.string().optional(),
4439
+ evidenceRelation: z.enum(["supports", "contradicts", "neutral"]).optional(),
4440
+ confidence: z.number().optional(),
4441
+ weight: z.number().optional(),
4442
+ reasoning: z.string().optional(),
4443
+ rationale: z.string(),
4444
+ metadata: jsonRecordSchema.optional(),
4445
+ trustedBypassAccessCheck: z.boolean().optional()
4446
+ }).passthrough();
4447
+ var createEvidenceInputSchema = createEvidenceInputSchemaBase.refine(
4448
+ (input) => Boolean(input.text ?? input.canonicalText),
4449
+ {
4450
+ message: "create_evidence requires text",
4451
+ path: ["text"]
4452
+ }
4453
+ );
4454
+ function compactRecord(input) {
4455
+ return Object.fromEntries(
4456
+ Object.entries(input).filter(([, value]) => value !== void 0)
4457
+ );
4458
+ }
4459
+ function recordValue(value) {
4460
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
4461
+ }
4462
+ var createEvidenceProjection = defineProjection({
4463
+ contractName: "create_evidence",
4464
+ inputSchema: createEvidenceInputSchema,
4465
+ project: (input) => {
4466
+ const text = input.text ?? input.canonicalText;
4467
+ const weight = typeof input.weight === "number" ? input.weight : void 0;
4468
+ return compactRecord({
4469
+ projectId: input.projectId,
4470
+ topicId: input.topicId,
4471
+ text,
4472
+ title: input.title ?? text,
4473
+ content: input.content ?? text,
4474
+ contentType: input.contentType,
4475
+ kind: input.kind,
4476
+ tags: input.tags,
4477
+ sourceType: input.sourceType,
4478
+ externalSourceType: input.externalSourceType,
4479
+ sourceUrl: input.sourceUrl ?? input.source,
4480
+ sourceQuestionId: input.sourceQuestionId,
4481
+ methodology: input.methodology,
4482
+ informationAsymmetry: input.informationAsymmetry,
4483
+ sourceDescription: input.sourceDescription,
4484
+ metadata: compactRecord({
4485
+ ...recordValue(input.metadata),
4486
+ source: input.source,
4487
+ targetId: input.targetId,
4488
+ targetNodeId: input.targetNodeId,
4489
+ weight,
4490
+ reasoning: input.reasoning,
4491
+ rationale: input.rationale
4492
+ }),
4493
+ linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
4494
+ evidenceRelation: input.evidenceRelation ?? (weight === void 0 ? void 0 : weight < 0 ? "contradicts" : "supports"),
4495
+ confidence: input.confidence ?? (weight === void 0 ? void 0 : Math.min(1, Math.max(0, Math.abs(weight)))),
4496
+ rationale: input.rationale,
4497
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
4498
+ });
4499
+ },
4500
+ convexArgsValidator: v.object({
4501
+ projectId: v.optional(v.string()),
4502
+ topicId: v.optional(v.string()),
4503
+ text: v.string(),
4504
+ title: v.optional(v.string()),
4505
+ content: v.optional(v.string()),
4506
+ contentType: v.optional(v.string()),
4507
+ kind: v.optional(v.string()),
4508
+ tags: v.optional(v.array(v.string())),
4509
+ sourceType: v.optional(v.string()),
4510
+ externalSourceType: v.optional(v.string()),
4511
+ sourceUrl: v.optional(v.string()),
4512
+ sourceQuestionId: v.optional(v.string()),
4513
+ methodology: v.optional(v.string()),
4514
+ informationAsymmetry: v.optional(v.string()),
4515
+ sourceDescription: v.optional(v.string()),
4516
+ metadata: v.optional(v.record(v.string(), v.any())),
4517
+ linkedBeliefNodeId: v.optional(v.string()),
4518
+ evidenceRelation: v.optional(
4519
+ v.union(
4520
+ v.literal("supports"),
4521
+ v.literal("contradicts"),
4522
+ v.literal("neutral")
4523
+ )
4524
+ ),
4525
+ confidence: v.optional(v.number()),
4526
+ rationale: v.string(),
4527
+ trustedBypassAccessCheck: v.optional(v.boolean())
4528
+ })
4529
+ });
4530
+ var beliefStatusSchema = z.enum(["active", "superseded", "archived", "unscored", "scored"]).optional().describe("Filter by belief lifecycle or scoring status");
4531
+ var listBeliefsInputSchema = z.object({
4532
+ topicId: z.string().describe("Topic scope"),
4533
+ worktreeId: z.string().optional().describe("Filter to worktree scope"),
4534
+ status: beliefStatusSchema,
4535
+ minConfidence: z.number().optional().describe("Minimum confidence threshold"),
4536
+ limit: z.number().optional().describe("Maximum results"),
4537
+ includeEdgeAssociated: z.boolean().optional().describe("Include beliefs associated to the topic through edges")
4538
+ });
4539
+ function kernelStatus(status) {
4540
+ return status === "active" || status === "superseded" || status === "archived" ? status : void 0;
4541
+ }
4542
+ function compactRecord2(input) {
4543
+ return Object.fromEntries(
4544
+ Object.entries(input).filter(([, value]) => value !== void 0)
4545
+ );
4546
+ }
4547
+ var listBeliefsProjection = defineProjection({
4548
+ contractName: "list_beliefs",
4549
+ inputSchema: listBeliefsInputSchema,
4550
+ project: (input) => compactRecord2({
4551
+ topicId: input.topicId,
4552
+ status: kernelStatus(input.status),
4553
+ limit: input.limit,
4554
+ includeEdgeAssociated: input.includeEdgeAssociated
4555
+ }),
4556
+ convexArgsValidator: v.object({
4557
+ topicId: v.string(),
4558
+ status: v.optional(
4559
+ v.union(
4560
+ v.literal("active"),
4561
+ v.literal("superseded"),
4562
+ v.literal("archived")
4563
+ )
4564
+ ),
4565
+ limit: v.optional(v.number()),
4566
+ includeEdgeAssociated: v.optional(v.boolean())
4567
+ })
4568
+ });
4569
+ var taskStatusSchema = z.enum(["todo", "in_progress", "blocked", "done"]).optional().describe("Filter by task status");
4570
+ var listTasksInputSchema = z.object({
4571
+ topicId: z.string().describe("Topic scope"),
4572
+ worktreeId: z.string().optional().describe("Alias for linkedWorktreeId"),
4573
+ linkedWorktreeId: z.string().optional().describe("Filter to tasks linked to this worktree"),
4574
+ status: taskStatusSchema,
4575
+ limit: z.number().optional().describe("Maximum results")
4576
+ });
4577
+ function compactRecord3(input) {
4578
+ return Object.fromEntries(
4579
+ Object.entries(input).filter(([, value]) => value !== void 0)
4580
+ );
4581
+ }
4582
+ var listTasksProjection = defineProjection({
4583
+ contractName: "list_tasks",
4584
+ inputSchema: listTasksInputSchema,
4585
+ project: (input) => compactRecord3({
4586
+ topicId: input.topicId,
4587
+ status: input.status,
4588
+ userId: void 0,
4589
+ limit: input.limit,
4590
+ linkedWorktreeId: input.linkedWorktreeId ?? input.worktreeId
4591
+ }),
4592
+ convexArgsValidator: v.object({
4593
+ topicId: v.string(),
4594
+ status: v.optional(
4595
+ v.union(
4596
+ v.literal("todo"),
4597
+ v.literal("in_progress"),
4598
+ v.literal("blocked"),
4599
+ v.literal("done")
4600
+ )
4601
+ ),
4602
+ limit: v.optional(v.number()),
4603
+ linkedWorktreeId: v.optional(v.string())
4604
+ })
4605
+ });
4606
+ var confidenceTriggerSchema = z.enum([
4607
+ "evidence_added",
4608
+ "evidence_removed",
4609
+ "contradiction_resolved",
4610
+ "agent_assessment",
4611
+ "worktree_outcome",
4612
+ "worktree_completed",
4613
+ "contradiction_detected",
4614
+ "answer_recorded",
4615
+ "fusion",
4616
+ "discount",
4617
+ "deduction",
4618
+ "backfill_synthetic"
4619
+ ]);
4620
+ var provenanceSchema = z.object({
4621
+ evidence: z.string().optional(),
4622
+ question: z.string().optional(),
4623
+ answer: z.string().optional(),
4624
+ contradiction: z.string().optional(),
4625
+ worktree: z.string().optional()
4626
+ });
4627
+ var slOpinionProjectionSchema = z.object({
4628
+ belief: z.number(),
4629
+ disbelief: z.number(),
4630
+ uncertainty: z.number(),
4631
+ baseRate: z.number()
4632
+ });
4633
+ var modulateConfidenceInputObjectSchema = z.object({
4634
+ nodeId: z.string().optional(),
4635
+ beliefNodeId: z.string().optional(),
4636
+ worktreeId: z.string().optional(),
4637
+ opinion: slOpinionProjectionSchema.optional(),
4638
+ belief: z.number().optional(),
4639
+ disbelief: z.number().optional(),
4640
+ uncertainty: z.number().optional(),
4641
+ baseRate: z.number().optional(),
4642
+ trigger: confidenceTriggerSchema,
4643
+ provenance: provenanceSchema.optional(),
4644
+ triggeringEvidenceId: z.string().optional(),
4645
+ triggeringQuestionId: z.string().optional(),
4646
+ triggeringAnswerId: z.string().optional(),
4647
+ triggeringContradictionId: z.string().optional(),
4648
+ triggeringWorktreeId: z.string().optional(),
4649
+ rationale: z.string(),
4650
+ trustedBypassAccessCheck: z.boolean().optional()
4651
+ });
4652
+ var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
4653
+ if (hasProvenance(input)) {
4654
+ return;
4655
+ }
4656
+ ctx.addIssue({
4657
+ code: z.ZodIssueCode.custom,
4658
+ message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
4659
+ path: ["provenance"]
4660
+ });
4661
+ });
4662
+ var modulateConfidenceProjection = defineProjection({
4663
+ contractName: "modulate_confidence",
4664
+ inputSchema: modulateConfidenceInputSchema,
4665
+ project: (input) => {
4666
+ const nodeId = input.beliefNodeId ?? input.nodeId;
4667
+ if (!nodeId) {
4668
+ throw new Error("modulate_confidence requires beliefNodeId or nodeId");
4669
+ }
4670
+ const opinion = input.opinion ?? {
4671
+ belief: requireNumber(input.belief, "belief"),
4672
+ disbelief: requireNumber(input.disbelief, "disbelief"),
4673
+ uncertainty: requireNumber(input.uncertainty, "uncertainty"),
4674
+ baseRate: requireNumber(input.baseRate, "baseRate")
4675
+ };
4676
+ assertProvenance(input);
4677
+ return {
4678
+ nodeId,
4679
+ worktreeId: input.worktreeId,
4680
+ belief: opinion.belief,
4681
+ disbelief: opinion.disbelief,
4682
+ uncertainty: opinion.uncertainty,
4683
+ baseRate: opinion.baseRate,
4684
+ trigger: input.trigger === "answer_recorded" ? "agent_assessment" : input.trigger,
4685
+ triggeringEvidenceId: input.provenance?.evidence ?? input.triggeringEvidenceId,
4686
+ triggeringQuestionId: input.provenance?.question ?? input.triggeringQuestionId,
4687
+ triggeringAnswerId: input.provenance?.answer ?? input.triggeringAnswerId,
4688
+ triggeringContradictionId: input.provenance?.contradiction ?? input.triggeringContradictionId,
4689
+ triggeringWorktreeId: input.provenance?.worktree ?? input.triggeringWorktreeId,
4690
+ rationale: input.rationale,
4691
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
4692
+ };
4693
+ },
4694
+ convexArgsValidator: v.object({
4695
+ nodeId: v.string(),
4696
+ worktreeId: v.optional(v.string()),
4697
+ belief: v.number(),
4698
+ disbelief: v.number(),
4699
+ uncertainty: v.number(),
4700
+ baseRate: v.number(),
4701
+ trigger: v.union(
4702
+ v.literal("evidence_added"),
4703
+ v.literal("evidence_removed"),
4704
+ v.literal("worktree_completed"),
4705
+ v.literal("contradiction_detected"),
4706
+ v.literal("contradiction_resolved"),
4707
+ v.literal("agent_assessment"),
4708
+ v.literal("worktree_outcome"),
4709
+ v.literal("fusion"),
4710
+ v.literal("discount"),
4711
+ v.literal("deduction"),
4712
+ v.literal("backfill_synthetic")
4713
+ ),
4714
+ triggeringEvidenceId: v.optional(v.string()),
4715
+ triggeringQuestionId: v.optional(v.string()),
4716
+ triggeringAnswerId: v.optional(v.string()),
4717
+ triggeringContradictionId: v.optional(v.string()),
4718
+ triggeringWorktreeId: v.optional(v.string()),
4719
+ rationale: v.string(),
4720
+ trustedBypassAccessCheck: v.optional(v.boolean())
4721
+ })
4722
+ });
4723
+ function requireNumber(value, field) {
4724
+ if (value === void 0) {
4725
+ throw new Error(`modulate_confidence requires ${field}`);
4726
+ }
4727
+ return value;
4728
+ }
4729
+ function assertProvenance(input) {
4730
+ if (!hasProvenance(input)) {
4731
+ throw new Error(
4732
+ "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
4733
+ );
4734
+ }
4735
+ }
4736
+ function hasProvenance(input) {
4737
+ 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);
4738
+ }
4255
4739
 
4256
4740
  // ../contracts/src/lens-workflow.contract.ts
4257
4741
  var LENS_PERSPECTIVE_TYPES = [
@@ -4265,7 +4749,7 @@ var LENS_PERSPECTIVE_TYPES = [
4265
4749
  // ../contracts/src/tool-contracts.ts
4266
4750
  var CREATE_BELIEF = {
4267
4751
  name: "create_belief",
4268
- 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.",
4752
+ 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.",
4269
4753
  parameters: {
4270
4754
  canonicalText: {
4271
4755
  type: "string",
@@ -4277,7 +4761,7 @@ var CREATE_BELIEF = {
4277
4761
  },
4278
4762
  baseRate: {
4279
4763
  type: "number",
4280
- description: "Required prior probability used to seed the vacuous opinion `(0, 0, 1, a)` at creation time."
4764
+ description: "Prior probability used to seed the vacuous opinion `(0, 0, 1, a)` at creation time. Defaults to 0.5 when omitted."
4281
4765
  },
4282
4766
  beliefType: {
4283
4767
  type: "string",
@@ -4288,7 +4772,7 @@ var CREATE_BELIEF = {
4288
4772
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'] } for coding intelligence)"
4289
4773
  }
4290
4774
  },
4291
- required: ["canonicalText", "baseRate"],
4775
+ required: ["canonicalText"],
4292
4776
  response: {
4293
4777
  description: "The created canonical belief record",
4294
4778
  fields: {
@@ -4351,7 +4835,7 @@ var REFINE_BELIEF = {
4351
4835
  };
4352
4836
  var MODULATE_CONFIDENCE = {
4353
4837
  name: "modulate_confidence",
4354
- 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.",
4838
+ 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.",
4355
4839
  parameters: {
4356
4840
  nodeId: { type: "string", description: "The belief to score" },
4357
4841
  belief: {
@@ -4370,9 +4854,9 @@ var MODULATE_CONFIDENCE = {
4370
4854
  type: "number",
4371
4855
  description: "Subjective-logic base rate `a` in [0, 1]. Required for tuple payloads."
4372
4856
  },
4373
- confidence: {
4374
- type: "number",
4375
- description: "Deprecated scalar confidence value in [0, 1]. Scalar-only payloads are rejected as AMBIGUOUS_SCALAR."
4857
+ worktreeId: {
4858
+ type: "string",
4859
+ description: "Completed worktree that tested this belief when confidence policy requires merge-backed scoring."
4376
4860
  },
4377
4861
  trigger: {
4378
4862
  type: "string",
@@ -4387,17 +4871,43 @@ var MODULATE_CONFIDENCE = {
4387
4871
  "worktree_completed",
4388
4872
  "fusion",
4389
4873
  "discount",
4390
- "deduction",
4391
- "manual",
4392
- "decay"
4874
+ "deduction"
4393
4875
  ]
4394
4876
  },
4877
+ triggeringEvidenceId: {
4878
+ type: "string",
4879
+ description: "Evidence node that caused an evidence-triggered modulation"
4880
+ },
4881
+ triggeringQuestionId: {
4882
+ type: "string",
4883
+ description: "Answered question whose resolution supports this modulation"
4884
+ },
4885
+ triggeringAnswerId: {
4886
+ type: "string",
4887
+ description: "Answer node whose content supports this modulation"
4888
+ },
4889
+ triggeringContradictionId: {
4890
+ type: "string",
4891
+ description: "Contradiction record that caused a contradiction-triggered modulation"
4892
+ },
4893
+ triggeringWorktreeId: {
4894
+ type: "string",
4895
+ description: "Completed worktree whose outcome caused a worktree-triggered modulation"
4896
+ },
4395
4897
  rationale: {
4396
4898
  type: "string",
4397
4899
  description: "Human-readable explanation of why confidence changed"
4398
4900
  }
4399
4901
  },
4400
- required: ["nodeId", "trigger", "rationale"],
4902
+ required: [
4903
+ "nodeId",
4904
+ "belief",
4905
+ "disbelief",
4906
+ "uncertainty",
4907
+ "baseRate",
4908
+ "trigger",
4909
+ "rationale"
4910
+ ],
4401
4911
  response: {
4402
4912
  description: "Confidence modulation result",
4403
4913
  fields: {
@@ -4591,7 +5101,7 @@ var ADD_EVIDENCE = {
4591
5101
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'], failedApproach: true } for coding intelligence)"
4592
5102
  }
4593
5103
  },
4594
- required: ["canonicalText", "targetNodeId"],
5104
+ required: ["canonicalText", "targetNodeId", "reasoning"],
4595
5105
  response: {
4596
5106
  description: "The created evidence node and its edge",
4597
5107
  fields: {
@@ -4672,9 +5182,21 @@ var ADD_WORKTREE = {
4672
5182
  type: "string",
4673
5183
  description: "Optional domain pack whose shaping hooks should influence generated questions and tasks"
4674
5184
  },
4675
- executionOrder: {
5185
+ campaign: {
5186
+ type: "number",
5187
+ description: "Top-level pipeline campaign number. Campaigns define the outer execution slice."
5188
+ },
5189
+ lane: {
5190
+ type: "string",
5191
+ description: "GitButler-aligned workstream lane name inside the campaign."
5192
+ },
5193
+ laneOrderInCampaign: {
5194
+ type: "number",
5195
+ description: "Ordering for this lane within its campaign."
5196
+ },
5197
+ orderInLane: {
4676
5198
  type: "number",
4677
- description: "Global execution order for this worktree"
5199
+ description: "Position of this worktree inside its lane."
4678
5200
  },
4679
5201
  dependsOn: {
4680
5202
  type: "array",
@@ -5332,6 +5854,10 @@ var CREATE_EVIDENCE = {
5332
5854
  type: "object",
5333
5855
  description: "Optional metadata merged into the canonical evidence node"
5334
5856
  },
5857
+ rationale: {
5858
+ type: "string",
5859
+ description: "Why this evidence should enter the reasoning graph"
5860
+ },
5335
5861
  title: { type: "string", description: "Optional short title" },
5336
5862
  content: { type: "string", description: "Optional long-form content" },
5337
5863
  contentType: {
@@ -5340,7 +5866,7 @@ var CREATE_EVIDENCE = {
5340
5866
  },
5341
5867
  kind: { type: "string", description: "Optional evidence kind" }
5342
5868
  },
5343
- required: ["text"],
5869
+ required: ["text", "rationale"],
5344
5870
  response: {
5345
5871
  description: "The created canonical evidence record",
5346
5872
  fields: {
@@ -5388,7 +5914,7 @@ var LIST_EVIDENCE = {
5388
5914
  limit: { type: "number", description: "Max results" },
5389
5915
  cursor: { type: "string", description: "Pagination cursor" }
5390
5916
  },
5391
- required: [],
5917
+ required: ["topicId"],
5392
5918
  response: {
5393
5919
  description: "Canonical evidence page",
5394
5920
  fields: {
@@ -5573,6 +6099,7 @@ var ANSWER_QUESTION = {
5573
6099
  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.",
5574
6100
  parameters: {
5575
6101
  id: { type: "string", description: "Canonical question ID" },
6102
+ topicId: { type: "string", description: "Topic scope for the answer" },
5576
6103
  text: { type: "string", description: "Answer text" },
5577
6104
  confidence: {
5578
6105
  type: "string",
@@ -5585,7 +6112,7 @@ var ANSWER_QUESTION = {
5585
6112
  },
5586
6113
  rationale: { type: "string", description: "Why this answer is credible" }
5587
6114
  },
5588
- required: ["id", "text"],
6115
+ required: ["id", "topicId", "text"],
5589
6116
  response: {
5590
6117
  description: "Answer result",
5591
6118
  fields: {
@@ -5804,6 +6331,10 @@ var LIST_BELIEFS = {
5804
6331
  minConfidence: {
5805
6332
  type: "number",
5806
6333
  description: "Minimum confidence threshold"
6334
+ },
6335
+ limit: {
6336
+ type: "number",
6337
+ description: "Maximum results"
5807
6338
  }
5808
6339
  },
5809
6340
  required: ["topicId"],
@@ -5820,20 +6351,37 @@ var LIST_BELIEFS = {
5820
6351
  };
5821
6352
  var LIST_WORKTREES = {
5822
6353
  name: "list_worktrees",
5823
- 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.",
6354
+ 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.",
5824
6355
  parameters: {
5825
6356
  topicId: { type: "string", description: "Topic scope" },
5826
6357
  status: {
5827
6358
  type: "string",
5828
6359
  description: "Filter: active, merged, abandoned",
5829
6360
  enum: ["active", "merged", "abandoned"]
6361
+ },
6362
+ groupBy: {
6363
+ type: "string",
6364
+ description: "Optional grouping mode for the response.",
6365
+ enum: ["campaign", "lane", "flat"]
6366
+ },
6367
+ lane: {
6368
+ type: "string",
6369
+ description: "Filter by GitButler-aligned lane name."
6370
+ },
6371
+ campaign: {
6372
+ type: "number",
6373
+ description: "Filter by top-level pipeline campaign number."
6374
+ },
6375
+ limit: {
6376
+ type: "number",
6377
+ description: "Maximum results to return."
5830
6378
  }
5831
6379
  },
5832
6380
  required: ["topicId"],
5833
6381
  response: {
5834
- description: "Worktrees with phase, status, belief count, and creation time",
6382
+ description: "Worktrees with lifecycle phase, campaign, lane, status, belief count, and creation time",
5835
6383
  fields: {
5836
- worktrees: "array \u2014 { worktreeId, title, phase, status, beliefCount, createdAt }"
6384
+ worktrees: "array \u2014 { worktreeId, title, phase, campaign, lane, laneOrderInCampaign, orderInLane, status, beliefCount, createdAt }"
5837
6385
  }
5838
6386
  },
5839
6387
  ownerModule: "workflow-engine",
@@ -5842,7 +6390,7 @@ var LIST_WORKTREES = {
5842
6390
  };
5843
6391
  var LIST_ALL_WORKTREES = {
5844
6392
  name: "list_all_worktrees",
5845
- 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.",
6393
+ 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.",
5846
6394
  parameters: {
5847
6395
  status: {
5848
6396
  type: "string",
@@ -5860,13 +6408,18 @@ var LIST_ALL_WORKTREES = {
5860
6408
  "dismissed"
5861
6409
  ]
5862
6410
  },
5863
- track: {
6411
+ lane: {
5864
6412
  type: "string",
5865
- description: "Filter by track name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity')"
6413
+ description: "Filter by lane name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity')"
5866
6414
  },
5867
- executionBand: {
6415
+ campaign: {
5868
6416
  type: "number",
5869
- description: "Filter by execution band number (e.g., 1, 2, 3). Returns only worktrees in that parallel execution group."
6417
+ description: "Filter by campaign number (e.g., 1, 2, 3). Returns only worktrees in that campaign."
6418
+ },
6419
+ groupBy: {
6420
+ type: "string",
6421
+ description: "Optional grouping mode for the response.",
6422
+ enum: ["campaign", "lane", "flat"]
5870
6423
  },
5871
6424
  limit: {
5872
6425
  type: "number",
@@ -5877,10 +6430,39 @@ var LIST_ALL_WORKTREES = {
5877
6430
  response: {
5878
6431
  description: "All worktrees across all topics with full pipeline metadata",
5879
6432
  fields: {
5880
- worktrees: "array \u2014 { worktreeId, title, topicId, topicName, phase, status, hypothesis, track, trackPosition, executionBand, executionOrder, dependsOn, blocks, gate, createdAt }",
6433
+ worktrees: "array \u2014 { worktreeId, title, topicId, topicName, phase, status, hypothesis, campaign, lane, laneOrderInCampaign, orderInLane, dependsOn, blocks, gate, createdAt }",
5881
6434
  total: "number \u2014 total count after filtering",
5882
- tracks: "object \u2014 { trackName: count } summary of worktrees per track",
5883
- bands: "object \u2014 { bandNumber: count } summary of worktrees per execution band"
6435
+ lanes: "object \u2014 { laneName: count } summary of worktrees per lane",
6436
+ campaigns: "object \u2014 { campaignNumber: count } summary of worktrees per campaign"
6437
+ }
6438
+ },
6439
+ ownerModule: "workflow-engine",
6440
+ ontologyPrimitive: "worktree",
6441
+ tier: "showcase"
6442
+ };
6443
+ var LIST_CAMPAIGNS = {
6444
+ name: "list_campaigns",
6445
+ 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.",
6446
+ parameters: {
6447
+ topicId: {
6448
+ type: "string",
6449
+ description: "Optional topic scope."
6450
+ },
6451
+ status: {
6452
+ type: "string",
6453
+ description: "Optional worktree status filter before grouping campaigns and lanes."
6454
+ },
6455
+ limit: {
6456
+ type: "number",
6457
+ description: "Maximum worktrees to scan before grouping."
6458
+ }
6459
+ },
6460
+ required: [],
6461
+ response: {
6462
+ description: "Pipeline campaigns with nested lane summaries.",
6463
+ fields: {
6464
+ campaigns: "array \u2014 { campaign, lanes: [{ lane, laneOrderInCampaign, worktreeCount, activeCount, readyCount, blockedCount, completedCount, nextWorktree }] }",
6465
+ totalWorktrees: "number \u2014 total worktrees scanned after filtering"
5884
6466
  }
5885
6467
  },
5886
6468
  ownerModule: "workflow-engine",
@@ -5943,16 +6525,28 @@ var UPDATE_WORKTREE_TARGETS = {
5943
6525
  };
5944
6526
  var UPDATE_WORKTREE_METADATA = {
5945
6527
  name: "update_worktree_metadata",
5946
- 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.",
6528
+ 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.",
5947
6529
  parameters: {
5948
6530
  worktreeId: { type: "string", description: "The worktree to update" },
5949
6531
  hypothesis: {
5950
6532
  type: "string",
5951
6533
  description: "Testable claim this worktree investigates"
5952
6534
  },
5953
- executionOrder: {
6535
+ campaign: {
6536
+ type: "number",
6537
+ description: "Top-level pipeline campaign number."
6538
+ },
6539
+ lane: {
6540
+ type: "string",
6541
+ description: "GitButler-aligned workstream lane name inside the campaign."
6542
+ },
6543
+ laneOrderInCampaign: {
6544
+ type: "number",
6545
+ description: "Ordering for this lane within the campaign."
6546
+ },
6547
+ orderInLane: {
5954
6548
  type: "number",
5955
- description: "Global execution order (1 = first, higher = later)"
6549
+ description: "Position of this worktree inside its lane."
5956
6550
  },
5957
6551
  dependsOn: {
5958
6552
  type: "array",
@@ -5990,18 +6584,6 @@ var UPDATE_WORKTREE_METADATA = {
5990
6584
  type: "object",
5991
6585
  description: "Calibrated auto-fix policy controlling dry-run vs safe execution, per-run action caps, and permitted mutation tiers."
5992
6586
  },
5993
- track: {
5994
- type: "string",
5995
- 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."
5996
- },
5997
- trackPosition: {
5998
- type: "number",
5999
- description: "Position within the track (1-indexed). E.g., TC-A=1, TC-B=2, TC-C=3 within the 'tc-scope' track."
6000
- },
6001
- executionBand: {
6002
- type: "number",
6003
- 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."
6004
- },
6005
6587
  status: {
6006
6588
  type: "string",
6007
6589
  description: "Override the worktree status. Use for lifecycle transitions like marking a worktree superseded, long-term, or as a raw idea.",
@@ -6371,6 +6953,10 @@ var LIST_TASKS = {
6371
6953
  type: "string",
6372
6954
  description: "Filter to tasks linked to this worktree"
6373
6955
  },
6956
+ worktreeId: {
6957
+ type: "string",
6958
+ description: "Alias for linkedWorktreeId"
6959
+ },
6374
6960
  status: {
6375
6961
  type: "string",
6376
6962
  description: "Filter by status: todo, in_progress, blocked, done",
@@ -6458,7 +7044,7 @@ var GET_TOPIC = {
6458
7044
  description: "Legacy alias for topicId"
6459
7045
  }
6460
7046
  },
6461
- required: [],
7047
+ required: ["topicId"],
6462
7048
  response: {
6463
7049
  description: "Single topic record",
6464
7050
  fields: {
@@ -6813,7 +7399,7 @@ var GET_ONTOLOGY = {
6813
7399
  description: "Tenant scope for key lookup. Omit for platform-level."
6814
7400
  }
6815
7401
  },
6816
- required: [],
7402
+ required: ["id"],
6817
7403
  response: {
6818
7404
  description: "Ontology definition with latest published version",
6819
7405
  fields: {
@@ -6880,7 +7466,7 @@ var MATCH_ENTITY_TYPE = {
6880
7466
  description: "Optional maximum number of ranked matches to return"
6881
7467
  }
6882
7468
  },
6883
- required: ["text"],
7469
+ required: ["text", "ontologyId"],
6884
7470
  response: {
6885
7471
  description: "Ranked ontology entity type matches",
6886
7472
  fields: {
@@ -7134,7 +7720,7 @@ var RECORD_SCOPE_LEARNING = {
7134
7720
  };
7135
7721
  var PIPELINE_SNAPSHOT = {
7136
7722
  name: "pipeline_snapshot",
7137
- 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.",
7723
+ 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.",
7138
7724
  parameters: {
7139
7725
  topicId: { type: "string", description: "Topic scope ID" }
7140
7726
  },
@@ -7144,14 +7730,14 @@ var PIPELINE_SNAPSHOT = {
7144
7730
  fields: {
7145
7731
  topicId: "string",
7146
7732
  topicName: "string",
7147
- currentBand: "number | null",
7148
- nextBand: "number | null",
7733
+ currentCampaign: "number | null",
7734
+ nextCampaign: "number | null",
7149
7735
  activeWorktrees: "array \u2014 current hinge worktree(s)",
7150
- nextWave: "array \u2014 worktrees in the next planned band",
7736
+ nextWave: "array \u2014 worktrees in the next planned campaign",
7151
7737
  readyNow: "array \u2014 planning worktrees with dependencies completed",
7152
7738
  blockedBy: "array \u2014 grouped blockers",
7153
7739
  criticalPath: "array \u2014 ordered incomplete worktree chain",
7154
- bands: "array \u2014 incomplete worktrees grouped by executionBand",
7740
+ campaigns: "array \u2014 incomplete worktrees grouped by campaign",
7155
7741
  superseded: "array \u2014 worktrees marked superseded or not for activation",
7156
7742
  graphHygiene: "object \u2014 untargeted and taskless worktree debt",
7157
7743
  riskQuestions: "array \u2014 critical/high open questions",
@@ -7740,6 +8326,7 @@ var MCP_TOOL_CONTRACTS = {
7740
8326
  list_beliefs: LIST_BELIEFS,
7741
8327
  list_worktrees: LIST_WORKTREES,
7742
8328
  list_all_worktrees: LIST_ALL_WORKTREES,
8329
+ list_campaigns: LIST_CAMPAIGNS,
7743
8330
  activate_worktree: ACTIVATE_WORKTREE,
7744
8331
  update_worktree_targets: UPDATE_WORKTREE_TARGETS,
7745
8332
  update_worktree_metadata: UPDATE_WORKTREE_METADATA,
@@ -7922,6 +8509,7 @@ var MCP_WORKFLOW_PLATFORM_OPERATION_NAMES = [
7922
8509
  "activate_worktree",
7923
8510
  "list_worktrees",
7924
8511
  "list_all_worktrees",
8512
+ "list_campaigns",
7925
8513
  "update_worktree_targets",
7926
8514
  "update_worktree_metadata",
7927
8515
  "create_task",
@@ -8129,6 +8717,7 @@ var LUCERN_OPERATION_MANIFEST = {
8129
8717
 
8130
8718
  // ../contracts/src/function-registry/helpers.ts
8131
8719
  var jsonObjectSchema = z.record(z.unknown());
8720
+ var sdkSessionIdSchema = z.string().optional();
8132
8721
  function mcpContractShape(contract) {
8133
8722
  const required = new Set(contract.required);
8134
8723
  return Object.fromEntries(
@@ -8163,10 +8752,40 @@ function argsSchemaFromMcpContract(contract) {
8163
8752
  return z.object(mcpContractShape(contract));
8164
8753
  }
8165
8754
  function inputSchemaFromMcpContract(contract) {
8166
- return argsSchemaFromMcpContract(contract).passthrough();
8755
+ return withInternalSurfaceFields(argsSchemaFromMcpContract(contract));
8756
+ }
8757
+ function withInternalSurfaceFields(schema) {
8758
+ return schema.extend({ __sdkSessionId: sdkSessionIdSchema }).strict();
8759
+ }
8760
+ function normalizeInputSchema(schema) {
8761
+ if (schema instanceof z.ZodObject) {
8762
+ return withInternalSurfaceFields(schema);
8763
+ }
8764
+ return schema;
8765
+ }
8766
+ function unwrapObjectSchema(schema) {
8767
+ let current = schema;
8768
+ while (true) {
8769
+ switch (current._def.typeName) {
8770
+ case z.ZodFirstPartyTypeKind.ZodEffects:
8771
+ current = current._def.schema;
8772
+ continue;
8773
+ case z.ZodFirstPartyTypeKind.ZodBranded:
8774
+ current = current._def.type;
8775
+ continue;
8776
+ default:
8777
+ return current instanceof z.ZodObject ? current : void 0;
8778
+ }
8779
+ }
8167
8780
  }
8168
8781
  function getObjectShape(schema) {
8169
- const shape = typeof schema._def.shape === "function" ? schema._def.shape() : schema._def.shape;
8782
+ const objectSchema = unwrapObjectSchema(schema);
8783
+ if (!objectSchema) {
8784
+ throw new Error(
8785
+ `Expected a Zod object schema, received ${schema._def.typeName}.`
8786
+ );
8787
+ }
8788
+ const shape = typeof objectSchema._def.shape === "function" ? objectSchema._def.shape() : objectSchema._def.shape;
8170
8789
  return shape;
8171
8790
  }
8172
8791
  function unwrapMcpParameterSchema(schema) {
@@ -8187,6 +8806,9 @@ function unwrapMcpParameterSchema(schema) {
8187
8806
  case z.ZodFirstPartyTypeKind.ZodBranded:
8188
8807
  current = current._def.type;
8189
8808
  continue;
8809
+ case z.ZodFirstPartyTypeKind.ZodEffects:
8810
+ current = current._def.schema;
8811
+ continue;
8190
8812
  default:
8191
8813
  return { schema: current, required, description: description ?? current.description };
8192
8814
  }
@@ -8206,6 +8828,7 @@ function mcpParameterFromZod(fieldName, schema, contractName) {
8206
8828
  return { parameter: { type: "array", description }, required };
8207
8829
  case z.ZodFirstPartyTypeKind.ZodObject:
8208
8830
  case z.ZodFirstPartyTypeKind.ZodRecord:
8831
+ case z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
8209
8832
  return { parameter: { type: "object", description }, required };
8210
8833
  case z.ZodFirstPartyTypeKind.ZodEnum:
8211
8834
  return {
@@ -8267,6 +8890,14 @@ function withCreatedBy(input, context) {
8267
8890
  createdBy: typeof input.createdBy === "string" ? input.createdBy : authUserId(context)
8268
8891
  };
8269
8892
  }
8893
+ function compactRecord4(input) {
8894
+ return Object.fromEntries(
8895
+ Object.entries(input).filter(([, value]) => value !== void 0)
8896
+ );
8897
+ }
8898
+ function recordValue2(value) {
8899
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
8900
+ }
8270
8901
  function surfaceMcpContract(name) {
8271
8902
  const contract = MCP_TOOL_CONTRACTS[name];
8272
8903
  if (!contract) {
@@ -8311,7 +8942,9 @@ function surfaceContract(args) {
8311
8942
  const canonicalArgs = args.args ?? argsSchemaFromMcpContract(baseMcp);
8312
8943
  const mcp = args.args ? mcpContractFromArgsSchema(baseMcp, canonicalArgs, args.name) : baseMcp;
8313
8944
  const canonicalReturns = args.returns ?? jsonObjectSchema;
8314
- const input = args.input ?? inputSchemaFromMcpContract(mcp);
8945
+ const input = normalizeInputSchema(
8946
+ args.input ?? inputSchemaFromMcpContract(mcp)
8947
+ );
8315
8948
  const output = args.output ?? canonicalReturns;
8316
8949
  return defineFunctionContract({
8317
8950
  name: args.name,
@@ -8373,20 +9006,26 @@ function assertSurfaceCoverage(contracts) {
8373
9006
 
8374
9007
  // ../contracts/src/function-registry/context.ts
8375
9008
  var observationInput = (input, context) => withUserId(
8376
- {
8377
- ...input,
9009
+ compactRecord4({
9010
+ projectId: input.projectId,
9011
+ topicId: input.topicId,
8378
9012
  text: input.text ?? input.summary,
8379
9013
  title: input.title ?? input.summary,
8380
9014
  content: input.content ?? input.summary,
9015
+ contentType: input.contentType,
8381
9016
  kind: input.kind ?? input.observationType ?? "observation",
8382
- sourceType: input.sourceType ?? input.source ?? "agent",
8383
- metadata: {
8384
- ...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {},
9017
+ tags: input.tags,
9018
+ sourceType: input.sourceType,
9019
+ externalSourceType: input.externalSourceType,
9020
+ sourceUrl: input.sourceUrl,
9021
+ metadata: compactRecord4({
9022
+ ...recordValue2(input.metadata),
8385
9023
  observationType: input.observationType,
8386
9024
  source: input.source
8387
- },
9025
+ }),
9026
+ rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded observation",
8388
9027
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8389
- },
9028
+ }),
8390
9029
  context
8391
9030
  );
8392
9031
  var contextContracts = [
@@ -8438,7 +9077,13 @@ var contextContracts = [
8438
9077
  convex: {
8439
9078
  module: "evidence",
8440
9079
  functionName: "getByTopic",
8441
- kind: "query"
9080
+ kind: "query",
9081
+ inputProjection: (input) => compactRecord4({
9082
+ topicId: input.topicId,
9083
+ limit: input.limit,
9084
+ status: input.status,
9085
+ userId: input.userId
9086
+ })
8442
9087
  }
8443
9088
  })
8444
9089
  ];
@@ -8504,42 +9149,62 @@ var identityContracts = [
8504
9149
  ];
8505
9150
 
8506
9151
  // ../contracts/src/function-registry/beliefs.ts
8507
- var withBeliefId = (input) => ({
8508
- ...input,
9152
+ var beliefLookupInput = (input) => compactRecord4({
8509
9153
  nodeId: input.nodeId ?? input.id ?? input.beliefId,
8510
- beliefId: input.beliefId ?? input.id ?? input.nodeId
9154
+ beliefId: input.beliefId
8511
9155
  });
8512
- var createBeliefInput = (input, context) => withUserId(
8513
- {
8514
- ...input,
8515
- formulation: input.formulation ?? input.canonicalText,
8516
- baseRate: input.baseRate ?? 0.5,
8517
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8518
- },
8519
- context
8520
- );
9156
+ var beliefNodeInput = (input) => compactRecord4({
9157
+ nodeId: input.nodeId ?? input.id ?? input.beliefId
9158
+ });
9159
+ var beliefTopicInput = (input) => {
9160
+ const parsed = listBeliefsProjection.inputSchema.safeParse(input);
9161
+ if (!parsed.success) {
9162
+ throw new Error(
9163
+ `list_beliefs projection input rejected: ${parsed.error.message}`
9164
+ );
9165
+ }
9166
+ return compactRecord4(listBeliefsProjection.project(parsed.data));
9167
+ };
9168
+ var createBeliefInput = (input, context) => {
9169
+ return withUserId(
9170
+ compactRecord4({
9171
+ projectId: input.projectId,
9172
+ topicId: input.topicId,
9173
+ formulation: input.formulation ?? input.canonicalText,
9174
+ beliefType: input.beliefType,
9175
+ rationale: input.rationale,
9176
+ pillar: input.pillar,
9177
+ worktreeId: input.worktreeId,
9178
+ sourceBeliefIds: input.sourceBeliefIds,
9179
+ sourceType: input.sourceType,
9180
+ reversibility: input.reversibility,
9181
+ predictionMeta: input.predictionMeta,
9182
+ baseRate: input.baseRate ?? 0.5,
9183
+ metadata: input.metadata,
9184
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9185
+ }),
9186
+ context
9187
+ );
9188
+ };
8521
9189
  var forkBeliefInput = (input, context) => withUserId(
8522
- {
8523
- ...input,
9190
+ compactRecord4({
8524
9191
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
9192
+ newFormulation: input.newFormulation,
9193
+ forkReason: input.forkReason,
9194
+ rationale: input.rationale,
8525
9195
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8526
- },
9196
+ }),
8527
9197
  context
8528
9198
  );
8529
9199
  var confidenceInput = (input, context) => {
8530
- const confidence = typeof input.confidence === "number" ? input.confidence : void 0;
8531
- const belief = typeof input.belief === "number" ? input.belief : confidence ?? 0.5;
8532
- const disbelief = typeof input.disbelief === "number" ? input.disbelief : 0;
8533
- const uncertainty = typeof input.uncertainty === "number" ? input.uncertainty : Math.max(0, 1 - belief - disbelief);
9200
+ const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
9201
+ if (!parsed.success) {
9202
+ throw new Error(
9203
+ `modulate_confidence projection input rejected: ${parsed.error.message}`
9204
+ );
9205
+ }
8534
9206
  return withUserId(
8535
- {
8536
- ...input,
8537
- belief,
8538
- disbelief,
8539
- uncertainty,
8540
- baseRate: input.baseRate ?? 0.5,
8541
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8542
- },
9207
+ compactRecord4(modulateConfidenceProjection.project(parsed.data)),
8543
9208
  context
8544
9209
  );
8545
9210
  };
@@ -8574,7 +9239,7 @@ var beliefsContracts = [
8574
9239
  module: "beliefs",
8575
9240
  functionName: "getById",
8576
9241
  kind: "query",
8577
- inputProjection: withBeliefId
9242
+ inputProjection: beliefLookupInput
8578
9243
  }
8579
9244
  }),
8580
9245
  surfaceContract({
@@ -8590,8 +9255,10 @@ var beliefsContracts = [
8590
9255
  convex: {
8591
9256
  module: "beliefs",
8592
9257
  functionName: "getByTopic",
8593
- kind: "query"
8594
- }
9258
+ kind: "query",
9259
+ inputProjection: beliefTopicInput
9260
+ },
9261
+ args: listBeliefsInputSchema
8595
9262
  }),
8596
9263
  surfaceContract({
8597
9264
  name: "refine_belief",
@@ -8609,7 +9276,7 @@ var beliefsContracts = [
8609
9276
  kind: "mutation",
8610
9277
  inputProjection: (input, context) => withUserId(
8611
9278
  {
8612
- ...withBeliefId(input),
9279
+ ...beliefLookupInput(input),
8613
9280
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8614
9281
  },
8615
9282
  context
@@ -8630,7 +9297,8 @@ var beliefsContracts = [
8630
9297
  functionName: "modulateConfidence",
8631
9298
  kind: "mutation",
8632
9299
  inputProjection: confidenceInput
8633
- }
9300
+ },
9301
+ args: modulateConfidenceInputSchema
8634
9302
  }),
8635
9303
  surfaceContract({
8636
9304
  name: "fork_belief",
@@ -8663,10 +9331,10 @@ var beliefsContracts = [
8663
9331
  functionName: "archive",
8664
9332
  kind: "mutation",
8665
9333
  inputProjection: (input, context) => withUserId(
8666
- {
8667
- ...withBeliefId(input),
9334
+ compactRecord4({
9335
+ ...beliefNodeInput(input),
8668
9336
  reason: input.reason ?? input.rationale
8669
- },
9337
+ }),
8670
9338
  context
8671
9339
  )
8672
9340
  }
@@ -8684,10 +9352,12 @@ var beliefsContracts = [
8684
9352
  module: "nodes",
8685
9353
  functionName: "search",
8686
9354
  kind: "query",
8687
- inputProjection: (input) => ({
8688
- ...input,
9355
+ inputProjection: (input) => compactRecord4({
8689
9356
  searchQuery: input.searchQuery ?? input.query,
8690
- nodeType: "belief"
9357
+ projectId: input.projectId,
9358
+ topicId: input.topicId,
9359
+ nodeType: "belief",
9360
+ limit: input.limit
8691
9361
  })
8692
9362
  }
8693
9363
  }),
@@ -8704,7 +9374,7 @@ var beliefsContracts = [
8704
9374
  module: "beliefs",
8705
9375
  functionName: "getConfidenceHistory",
8706
9376
  kind: "query",
8707
- inputProjection: withBeliefId
9377
+ inputProjection: beliefNodeInput
8708
9378
  }
8709
9379
  }),
8710
9380
  surfaceContract({
@@ -8721,25 +9391,69 @@ var beliefsContracts = [
8721
9391
  module: "beliefs",
8722
9392
  functionName: "getConfidenceHistory",
8723
9393
  kind: "query",
8724
- inputProjection: withBeliefId
9394
+ inputProjection: beliefNodeInput
8725
9395
  }
8726
9396
  })
8727
9397
  ];
8728
9398
 
8729
9399
  // ../contracts/src/function-registry/evidence.ts
8730
- var evidenceIdInput = (input) => ({
8731
- ...input,
8732
- evidenceId: input.evidenceId ?? input.id ?? input.nodeId,
9400
+ var evidenceIdInput = (input) => compactRecord4({
9401
+ evidenceId: input.evidenceId,
9402
+ insightId: input.insightId,
8733
9403
  nodeId: input.nodeId ?? input.id ?? input.evidenceId
8734
9404
  });
8735
- var createEvidenceInput = (input, context) => withUserId(
8736
- {
8737
- ...input,
8738
- title: input.title ?? input.text,
8739
- content: input.content ?? input.text,
8740
- sourceType: input.sourceType ?? input.source ?? "agent",
9405
+ var evidenceTopicInput = (input) => compactRecord4({
9406
+ topicId: input.topicId,
9407
+ status: input.status,
9408
+ userId: input.userId,
9409
+ limit: input.limit
9410
+ });
9411
+ var createEvidenceInput = (input, context) => {
9412
+ const parsed = createEvidenceProjection.inputSchema.safeParse(input);
9413
+ if (!parsed.success) {
9414
+ throw new Error(
9415
+ `create_evidence projection input rejected: ${parsed.error.message}`
9416
+ );
9417
+ }
9418
+ return withUserId(
9419
+ compactRecord4(createEvidenceProjection.project(parsed.data)),
9420
+ context
9421
+ );
9422
+ };
9423
+ var linkEvidenceToBeliefEdgeInput = (input, context) => withCreatedBy(
9424
+ compactRecord4({
9425
+ fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
9426
+ toNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
9427
+ edgeType: "evidence_supports_belief",
9428
+ globalId: input.globalId ?? `edge:${String(
9429
+ input.insightId ?? input.evidenceNodeId ?? input.evidenceId
9430
+ )}:${String(
9431
+ input.beliefNodeId ?? input.beliefId ?? input.targetId
9432
+ )}:evidence_supports_belief`,
9433
+ weight: typeof input.weight === "number" ? input.weight : input.type === "contradicting" ? -1 : 1,
9434
+ context: input.rationale ?? input.context,
9435
+ skipLayerValidation: true,
9436
+ topicId: input.topicId,
8741
9437
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8742
- },
9438
+ }),
9439
+ context
9440
+ );
9441
+ var linkEvidenceToQuestionEdgeInput = (input, context) => withCreatedBy(
9442
+ compactRecord4({
9443
+ fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
9444
+ toNodeId: input.questionId ?? input.questionNodeId ?? input.targetId,
9445
+ edgeType: "evidence_supports_question",
9446
+ globalId: input.globalId ?? `edge:${String(
9447
+ input.insightId ?? input.evidenceNodeId ?? input.evidenceId
9448
+ )}:${String(
9449
+ input.questionId ?? input.questionNodeId ?? input.targetId
9450
+ )}:evidence_supports_question`,
9451
+ weight: input.impactScore ?? input.weight,
9452
+ context: input.rationale ?? input.context,
9453
+ skipLayerValidation: true,
9454
+ topicId: input.topicId,
9455
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9456
+ }),
8743
9457
  context
8744
9458
  );
8745
9459
  var evidenceContracts = [
@@ -8783,8 +9497,9 @@ var evidenceContracts = [
8783
9497
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
8784
9498
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
8785
9499
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
9500
+ rationale: input.reasoning,
8786
9501
  metadata: {
8787
- ...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {},
9502
+ ...recordValue2(input.metadata),
8788
9503
  reasoning: input.reasoning,
8789
9504
  sourceUrl: input.sourceUrl
8790
9505
  }
@@ -8824,7 +9539,8 @@ var evidenceContracts = [
8824
9539
  convex: {
8825
9540
  module: "evidence",
8826
9541
  functionName: "getByTopic",
8827
- kind: "query"
9542
+ kind: "query",
9543
+ inputProjection: evidenceTopicInput
8828
9544
  }
8829
9545
  }),
8830
9546
  surfaceContract({
@@ -8840,10 +9556,12 @@ var evidenceContracts = [
8840
9556
  module: "nodes",
8841
9557
  functionName: "search",
8842
9558
  kind: "query",
8843
- inputProjection: (input) => ({
8844
- ...input,
9559
+ inputProjection: (input) => compactRecord4({
8845
9560
  searchQuery: input.searchQuery ?? input.q ?? input.query,
8846
- nodeType: "evidence"
9561
+ projectId: input.projectId,
9562
+ topicId: input.topicId,
9563
+ nodeType: "evidence",
9564
+ limit: input.limit
8847
9565
  })
8848
9566
  }
8849
9567
  }),
@@ -8857,17 +9575,10 @@ var evidenceContracts = [
8857
9575
  sdkMethod: "linkEvidenceToBelief",
8858
9576
  summary: "Link evidence to a belief.",
8859
9577
  convex: {
8860
- module: "beliefs",
8861
- functionName: "linkEvidence",
9578
+ module: "edges",
9579
+ functionName: "create",
8862
9580
  kind: "mutation",
8863
- inputProjection: (input, context) => withUserId(
8864
- {
8865
- ...input,
8866
- beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
8867
- evidenceNodeId: input.evidenceNodeId ?? input.evidenceId
8868
- },
8869
- context
8870
- )
9581
+ inputProjection: linkEvidenceToBeliefEdgeInput
8871
9582
  }
8872
9583
  }),
8873
9584
  surfaceContract({
@@ -8880,18 +9591,10 @@ var evidenceContracts = [
8880
9591
  sdkMethod: "linkEvidenceToQuestion",
8881
9592
  summary: "Link evidence to a question.",
8882
9593
  convex: {
8883
- module: "questionLinks",
9594
+ module: "edges",
8884
9595
  functionName: "create",
8885
9596
  kind: "mutation",
8886
- inputProjection: (input, context) => withCreatedBy(
8887
- {
8888
- ...input,
8889
- questionId: input.questionId,
8890
- insightId: input.insightId ?? input.evidenceId,
8891
- helpsAnswer: input.helpsAnswer ?? true
8892
- },
8893
- context
8894
- )
9597
+ inputProjection: linkEvidenceToQuestionEdgeInput
8895
9598
  }
8896
9599
  }),
8897
9600
  surfaceContract({
@@ -8904,35 +9607,46 @@ var evidenceContracts = [
8904
9607
  sdkMethod: "linkEvidence",
8905
9608
  summary: "Link evidence to a target node.",
8906
9609
  convex: {
8907
- module: "beliefs",
8908
- functionName: "linkEvidence",
9610
+ module: "edges",
9611
+ functionName: "create",
8909
9612
  kind: "mutation",
8910
- inputProjection: (input, context) => withUserId(
8911
- {
8912
- ...input,
8913
- beliefNodeId: input.beliefNodeId ?? input.targetId,
8914
- evidenceNodeId: input.evidenceNodeId ?? input.evidenceId
8915
- },
8916
- context
8917
- )
9613
+ inputProjection: linkEvidenceToBeliefEdgeInput
8918
9614
  }
8919
9615
  })
8920
9616
  ];
8921
9617
 
8922
9618
  // ../contracts/src/function-registry/questions.ts
8923
- var questionIdInput = (input) => ({
8924
- ...input,
8925
- questionId: input.questionId ?? input.id ?? input.nodeId,
8926
- nodeId: input.nodeId ?? input.id ?? input.questionId
9619
+ var questionNodeInput = (input) => compactRecord4({
9620
+ nodeId: input.nodeId ?? input.id ?? input.questionId,
9621
+ questionId: input.questionId
8927
9622
  });
8928
- var createQuestionInput = (input, context) => withUserId(
8929
- {
8930
- ...input,
8931
- text: input.text ?? input.question,
8932
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8933
- },
8934
- context
8935
- );
9623
+ var questionTopicInput = (input) => compactRecord4({
9624
+ topicId: input.topicId,
9625
+ status: input.status,
9626
+ userId: input.userId,
9627
+ limit: input.limit
9628
+ });
9629
+ var createQuestionInput = (input, context) => {
9630
+ const priority = input.priority === "urgent" ? "high" : input.priority;
9631
+ return withUserId(
9632
+ compactRecord4({
9633
+ topicId: input.topicId,
9634
+ question: input.question ?? input.text,
9635
+ category: input.category,
9636
+ priority,
9637
+ source: input.source,
9638
+ linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.linkedBeliefId,
9639
+ testType: input.testType,
9640
+ importance: input.importance,
9641
+ epistemicUnlock: input.epistemicUnlock,
9642
+ sourceQuestionIds: input.sourceQuestionIds,
9643
+ linkedWorktreeId: input.linkedWorktreeId,
9644
+ questionType: input.questionType,
9645
+ questionPriority: input.questionPriority
9646
+ }),
9647
+ context
9648
+ );
9649
+ };
8936
9650
  var questionsContracts = [
8937
9651
  surfaceContract({
8938
9652
  name: "create_question",
@@ -8964,7 +9678,7 @@ var questionsContracts = [
8964
9678
  module: "questions",
8965
9679
  functionName: "getById",
8966
9680
  kind: "query",
8967
- inputProjection: questionIdInput
9681
+ inputProjection: questionNodeInput
8968
9682
  }
8969
9683
  }),
8970
9684
  surfaceContract({
@@ -8980,7 +9694,8 @@ var questionsContracts = [
8980
9694
  convex: {
8981
9695
  module: "questions",
8982
9696
  functionName: "getByTopic",
8983
- kind: "query"
9697
+ kind: "query",
9698
+ inputProjection: questionTopicInput
8984
9699
  }
8985
9700
  }),
8986
9701
  surfaceContract({
@@ -8997,7 +9712,12 @@ var questionsContracts = [
8997
9712
  module: "questions",
8998
9713
  functionName: "updateQuestion",
8999
9714
  kind: "mutation",
9000
- inputProjection: (input, context) => withUserId({ ...questionIdInput(input), text: input.text }, context)
9715
+ inputProjection: (input) => compactRecord4({
9716
+ questionId: input.questionId ?? input.id ?? input.nodeId,
9717
+ question: input.question ?? input.text,
9718
+ category: input.category,
9719
+ priority: input.priority
9720
+ })
9001
9721
  }
9002
9722
  }),
9003
9723
  surfaceContract({
@@ -9014,7 +9734,16 @@ var questionsContracts = [
9014
9734
  module: "questions",
9015
9735
  functionName: "updateStatus",
9016
9736
  kind: "mutation",
9017
- inputProjection: (input, context) => withUserId(questionIdInput(input), context)
9737
+ inputProjection: (input, context) => withUserId(
9738
+ compactRecord4({
9739
+ questionId: input.questionId ?? input.id,
9740
+ nodeId: input.nodeId,
9741
+ status: input.status,
9742
+ answer: input.answer,
9743
+ answerStatus: input.answerStatus
9744
+ }),
9745
+ context
9746
+ )
9018
9747
  }
9019
9748
  }),
9020
9749
  surfaceContract({
@@ -9031,7 +9760,12 @@ var questionsContracts = [
9031
9760
  module: "questions",
9032
9761
  functionName: "deleteQuestion",
9033
9762
  kind: "mutation",
9034
- inputProjection: questionIdInput
9763
+ inputProjection: (input, context) => withUserId(
9764
+ compactRecord4({
9765
+ questionId: input.questionId ?? input.id ?? input.nodeId
9766
+ }),
9767
+ context
9768
+ )
9035
9769
  }
9036
9770
  }),
9037
9771
  surfaceContract({
@@ -9048,10 +9782,16 @@ var questionsContracts = [
9048
9782
  functionName: "create",
9049
9783
  kind: "mutation",
9050
9784
  inputProjection: (input, context) => withUserId(
9051
- {
9052
- ...input,
9053
- questionNodeId: input.questionNodeId ?? input.questionId
9054
- },
9785
+ compactRecord4({
9786
+ topicId: input.topicId,
9787
+ questionNodeId: input.questionNodeId ?? input.questionId,
9788
+ answerText: input.answerText,
9789
+ confidence: input.confidence,
9790
+ evidenceNodeIds: input.evidenceNodeIds,
9791
+ answerSource: input.answerSource,
9792
+ worktreeId: input.worktreeId,
9793
+ sprintId: input.sprintId
9794
+ }),
9055
9795
  context
9056
9796
  )
9057
9797
  }
@@ -9071,13 +9811,16 @@ var questionsContracts = [
9071
9811
  functionName: "create",
9072
9812
  kind: "mutation",
9073
9813
  inputProjection: (input, context) => withUserId(
9074
- {
9075
- ...input,
9814
+ compactRecord4({
9815
+ topicId: input.topicId,
9076
9816
  questionNodeId: input.questionNodeId ?? input.questionId ?? input.id,
9077
9817
  answerText: input.answerText ?? input.text,
9078
9818
  evidenceNodeIds: input.evidenceNodeIds ?? input.evidenceIds,
9079
- answerSource: input.answerSource ?? "human"
9080
- },
9819
+ answerSource: input.answerSource ?? "human",
9820
+ confidence: input.confidence,
9821
+ worktreeId: input.worktreeId,
9822
+ sprintId: input.sprintId
9823
+ }),
9081
9824
  context
9082
9825
  )
9083
9826
  }
@@ -9110,7 +9853,8 @@ var questionsContracts = [
9110
9853
  convex: {
9111
9854
  module: "questions",
9112
9855
  functionName: "getByTopic",
9113
- kind: "query"
9856
+ kind: "query",
9857
+ inputProjection: questionTopicInput
9114
9858
  }
9115
9859
  }),
9116
9860
  surfaceContract({
@@ -9125,7 +9869,11 @@ var questionsContracts = [
9125
9869
  convex: {
9126
9870
  module: "questions",
9127
9871
  functionName: "getByTopic",
9128
- kind: "query"
9872
+ kind: "query",
9873
+ inputProjection: (input) => compactRecord4({
9874
+ ...questionTopicInput(input),
9875
+ status: input.includeAnswered === true ? void 0 : "open"
9876
+ })
9129
9877
  }
9130
9878
  }),
9131
9879
  surfaceContract({
@@ -9140,16 +9888,28 @@ var questionsContracts = [
9140
9888
  convex: {
9141
9889
  module: "questions",
9142
9890
  functionName: "getByTopic",
9143
- kind: "query"
9891
+ kind: "query",
9892
+ inputProjection: questionTopicInput
9144
9893
  }
9145
9894
  })
9146
9895
  ];
9147
9896
 
9148
9897
  // ../contracts/src/function-registry/topics.ts
9149
- var topicIdInput = (input) => ({
9150
- ...input,
9898
+ var topicIdInput = (input) => compactRecord4({
9151
9899
  id: input.id ?? input.topicId
9152
9900
  });
9901
+ var updateTopicInput = (input) => compactRecord4({
9902
+ id: input.id ?? input.topicId,
9903
+ name: input.name,
9904
+ description: input.description,
9905
+ type: input.type,
9906
+ status: input.status,
9907
+ visibility: input.visibility,
9908
+ ontologyId: input.ontologyId,
9909
+ clearOntologyId: input.clearOntologyId,
9910
+ graphScopeProjectId: input.graphScopeProjectId,
9911
+ metadata: input.metadata
9912
+ });
9153
9913
  var topicsContracts = [
9154
9914
  surfaceContract({
9155
9915
  name: "create_topic",
@@ -9214,7 +9974,7 @@ var topicsContracts = [
9214
9974
  module: "topics",
9215
9975
  functionName: "update",
9216
9976
  kind: "mutation",
9217
- inputProjection: topicIdInput
9977
+ inputProjection: updateTopicInput
9218
9978
  }
9219
9979
  }),
9220
9980
  surfaceContract({
@@ -9236,6 +9996,27 @@ var topicsContracts = [
9236
9996
  ];
9237
9997
 
9238
9998
  // ../contracts/src/function-registry/lenses.ts
9999
+ var createLensInput = (input, context) => compactRecord4({
10000
+ name: input.name,
10001
+ description: input.description,
10002
+ workspaceId: input.workspaceId,
10003
+ topicId: input.topicId,
10004
+ perspectiveType: input.perspectiveType,
10005
+ promptTemplates: input.promptTemplates,
10006
+ workflowTemplates: input.workflowTemplates,
10007
+ taskTemplates: input.taskTemplates,
10008
+ questionTemplates: input.questionTemplates,
10009
+ filterCriteria: input.filterCriteria,
10010
+ metadata: input.metadata,
10011
+ createdBy: authUserId(context)
10012
+ });
10013
+ var lensListInput = (input, context) => compactRecord4({
10014
+ actorId: input.actorId ?? authUserId(context),
10015
+ workspaceId: input.workspaceId,
10016
+ topicId: input.topicId,
10017
+ status: input.status,
10018
+ perspectiveType: input.perspectiveType
10019
+ });
9239
10020
  var lensesContracts = [
9240
10021
  surfaceContract({
9241
10022
  name: "create_lens",
@@ -9249,7 +10030,8 @@ var lensesContracts = [
9249
10030
  convex: {
9250
10031
  module: "lenses",
9251
10032
  functionName: "create",
9252
- kind: "mutation"
10033
+ kind: "mutation",
10034
+ inputProjection: createLensInput
9253
10035
  }
9254
10036
  }),
9255
10037
  surfaceContract({
@@ -9265,7 +10047,8 @@ var lensesContracts = [
9265
10047
  convex: {
9266
10048
  module: "lenses",
9267
10049
  functionName: "list",
9268
- kind: "query"
10050
+ kind: "query",
10051
+ inputProjection: lensListInput
9269
10052
  }
9270
10053
  }),
9271
10054
  surfaceContract({
@@ -9280,7 +10063,13 @@ var lensesContracts = [
9280
10063
  convex: {
9281
10064
  module: "lenses",
9282
10065
  functionName: "applyToTopic",
9283
- kind: "mutation"
10066
+ kind: "mutation",
10067
+ inputProjection: (input, context) => compactRecord4({
10068
+ lensId: input.lensId,
10069
+ topicId: input.topicId,
10070
+ metadata: input.metadata,
10071
+ appliedBy: authUserId(context)
10072
+ })
9284
10073
  }
9285
10074
  }),
9286
10075
  surfaceContract({
@@ -9296,12 +10085,28 @@ var lensesContracts = [
9296
10085
  convex: {
9297
10086
  module: "lenses",
9298
10087
  functionName: "removeFromTopic",
9299
- kind: "mutation"
10088
+ kind: "mutation",
10089
+ inputProjection: (input, context) => compactRecord4({
10090
+ lensId: input.lensId,
10091
+ topicId: input.topicId,
10092
+ removedBy: authUserId(context)
10093
+ })
9300
10094
  }
9301
10095
  })
9302
10096
  ];
9303
10097
 
9304
10098
  // ../contracts/src/function-registry/ontologies.ts
10099
+ var ontologyIdInput = (input) => compactRecord4({
10100
+ id: input.id ?? input.ontologyId
10101
+ });
10102
+ var ontologyVersionIdInput = (input) => compactRecord4({
10103
+ id: input.id ?? input.versionId,
10104
+ ontologyId: input.ontologyId,
10105
+ actorId: input.actorId
10106
+ });
10107
+ var effectiveOntologyInput = (input) => compactRecord4({
10108
+ ontologyId: input.ontologyId ?? input.id
10109
+ });
9305
10110
  var ontologiesContracts = [
9306
10111
  surfaceContract({
9307
10112
  name: "create_ontology",
@@ -9332,10 +10137,7 @@ var ontologiesContracts = [
9332
10137
  module: "ontologies",
9333
10138
  functionName: "getOntologyDefinition",
9334
10139
  kind: "query",
9335
- inputProjection: (input) => ({
9336
- ...input,
9337
- id: input.id ?? input.ontologyId
9338
- })
10140
+ inputProjection: ontologyIdInput
9339
10141
  }
9340
10142
  }),
9341
10143
  surfaceContract({
@@ -9368,9 +10170,13 @@ var ontologiesContracts = [
9368
10170
  module: "ontologies",
9369
10171
  functionName: "updateOntologyDefinition",
9370
10172
  kind: "mutation",
9371
- inputProjection: (input) => ({
9372
- ...input,
9373
- id: input.id ?? input.ontologyId
10173
+ inputProjection: (input) => compactRecord4({
10174
+ id: input.id ?? input.ontologyId,
10175
+ name: input.name,
10176
+ description: input.description,
10177
+ parentOntologyId: input.parentOntologyId,
10178
+ status: input.status,
10179
+ actorId: input.actorId
9374
10180
  })
9375
10181
  }
9376
10182
  }),
@@ -9388,10 +10194,7 @@ var ontologiesContracts = [
9388
10194
  module: "ontologies",
9389
10195
  functionName: "archiveOntologyDefinition",
9390
10196
  kind: "mutation",
9391
- inputProjection: (input) => ({
9392
- ...input,
9393
- id: input.id ?? input.ontologyId
9394
- })
10197
+ inputProjection: ontologyIdInput
9395
10198
  }
9396
10199
  }),
9397
10200
  surfaceContract({
@@ -9422,8 +10225,7 @@ var ontologiesContracts = [
9422
10225
  module: "topics",
9423
10226
  functionName: "update",
9424
10227
  kind: "mutation",
9425
- inputProjection: (input) => ({
9426
- ...input,
10228
+ inputProjection: (input) => compactRecord4({
9427
10229
  id: input.topicId ?? input.id,
9428
10230
  ontologyId: input.ontologyId ?? input.id
9429
10231
  })
@@ -9441,7 +10243,8 @@ var ontologiesContracts = [
9441
10243
  convex: {
9442
10244
  module: "ontologies",
9443
10245
  functionName: "resolveEffectiveOntology",
9444
- kind: "query"
10246
+ kind: "query",
10247
+ inputProjection: effectiveOntologyInput
9445
10248
  }
9446
10249
  }),
9447
10250
  surfaceContract({
@@ -9457,10 +10260,7 @@ var ontologiesContracts = [
9457
10260
  module: "ontologies",
9458
10261
  functionName: "publishOntologyVersion",
9459
10262
  kind: "mutation",
9460
- inputProjection: (input) => ({
9461
- ...input,
9462
- id: input.id ?? input.versionId
9463
- })
10263
+ inputProjection: ontologyVersionIdInput
9464
10264
  }
9465
10265
  }),
9466
10266
  surfaceContract({
@@ -9476,10 +10276,7 @@ var ontologiesContracts = [
9476
10276
  module: "ontologies",
9477
10277
  functionName: "deprecateOntologyVersion",
9478
10278
  kind: "mutation",
9479
- inputProjection: (input) => ({
9480
- ...input,
9481
- id: input.id ?? input.versionId
9482
- })
10279
+ inputProjection: ontologyVersionIdInput
9483
10280
  }
9484
10281
  }),
9485
10282
  surfaceContract({
@@ -9494,16 +10291,51 @@ var ontologiesContracts = [
9494
10291
  convex: {
9495
10292
  module: "ontologies",
9496
10293
  functionName: "resolveEffectiveOntology",
9497
- kind: "query"
10294
+ kind: "query",
10295
+ inputProjection: effectiveOntologyInput
9498
10296
  }
9499
10297
  })
9500
10298
  ];
9501
10299
 
9502
10300
  // ../contracts/src/function-registry/worktrees.ts
9503
- var worktreeInput = (input) => ({
9504
- ...input,
10301
+ var worktreeIdInput = (input) => compactRecord4({
9505
10302
  worktreeId: input.worktreeId ?? input.id
9506
10303
  });
10304
+ var activateWorktreeInput = (input, context) => withUserId(worktreeIdInput(input), context);
10305
+ var worktreeTargetsInput = (input) => compactRecord4({
10306
+ worktreeId: input.worktreeId ?? input.id,
10307
+ addBeliefIds: input.addBeliefIds,
10308
+ removeBeliefIds: input.removeBeliefIds,
10309
+ addQuestionIds: input.addQuestionIds,
10310
+ removeQuestionIds: input.removeQuestionIds
10311
+ });
10312
+ var worktreeMetadataInput = (input) => compactRecord4({
10313
+ worktreeId: input.worktreeId ?? input.id,
10314
+ topicId: input.topicId,
10315
+ additionalTopicIds: input.additionalTopicIds,
10316
+ status: input.status,
10317
+ campaign: input.campaign,
10318
+ lane: input.lane,
10319
+ laneOrderInCampaign: input.laneOrderInCampaign,
10320
+ orderInLane: input.orderInLane,
10321
+ gate: input.gate,
10322
+ hypothesis: input.hypothesis,
10323
+ objective: input.objective,
10324
+ rationale: input.rationale,
10325
+ proofArtifacts: input.proofArtifacts,
10326
+ staffingHint: input.staffingHint,
10327
+ blocks: input.blocks,
10328
+ dependsOn: input.dependsOn,
10329
+ lensId: input.lensId,
10330
+ autoFixPolicy: input.autoFixPolicy,
10331
+ lastReconciledAt: input.lastReconciledAt
10332
+ });
10333
+ var listAllWorktreesInput = (input) => compactRecord4({
10334
+ status: input.status,
10335
+ lane: input.lane,
10336
+ campaign: input.campaign,
10337
+ limit: input.limit
10338
+ });
9507
10339
  var worktreesContracts = [
9508
10340
  surfaceContract({
9509
10341
  name: "add_worktree",
@@ -9519,11 +10351,43 @@ var worktreesContracts = [
9519
10351
  functionName: "create",
9520
10352
  kind: "mutation",
9521
10353
  inputProjection: (input, context) => withCreatedBy(
9522
- {
9523
- ...input,
10354
+ compactRecord4({
9524
10355
  name: input.name ?? input.title,
9525
- targetBeliefIds: input.targetBeliefIds ?? input.beliefIds
9526
- },
10356
+ topicId: input.topicId,
10357
+ worktreeType: input.worktreeType,
10358
+ objective: input.objective,
10359
+ gate: input.gate,
10360
+ hypothesis: input.hypothesis,
10361
+ rationale: input.rationale,
10362
+ signal: input.signal,
10363
+ startDate: input.startDate,
10364
+ endDate: input.endDate,
10365
+ durationWeeks: input.durationWeeks,
10366
+ confidenceImpact: input.confidenceImpact,
10367
+ autoShape: input.autoShape,
10368
+ autoFixPolicy: input.autoFixPolicy,
10369
+ beliefFocus: input.beliefFocus,
10370
+ targetQuestionIds: input.targetQuestionIds,
10371
+ targetBeliefIds: input.targetBeliefIds ?? input.beliefIds,
10372
+ keyQuestions: input.keyQuestions,
10373
+ proofArtifacts: input.proofArtifacts,
10374
+ decisionGate: input.decisionGate ?? (input.goCriteria || input.noGoSignals ? compactRecord4({
10375
+ goCriteria: input.goCriteria,
10376
+ noGoSignals: input.noGoSignals
10377
+ }) : void 0),
10378
+ evidenceSignals: input.evidenceSignals,
10379
+ dependsOn: input.dependsOn,
10380
+ blocks: input.blocks,
10381
+ campaign: input.campaign,
10382
+ lane: input.lane,
10383
+ laneOrderInCampaign: input.laneOrderInCampaign,
10384
+ orderInLane: input.orderInLane,
10385
+ staffingHint: input.staffingHint,
10386
+ domainPackId: input.domainPackId,
10387
+ lensId: input.lensId,
10388
+ linkedQuestionId: input.linkedQuestionId,
10389
+ lastReconciledAt: input.lastReconciledAt
10390
+ }),
9527
10391
  context
9528
10392
  )
9529
10393
  }
@@ -9541,7 +10405,7 @@ var worktreesContracts = [
9541
10405
  module: "worktrees",
9542
10406
  functionName: "activate",
9543
10407
  kind: "mutation",
9544
- inputProjection: worktreeInput
10408
+ inputProjection: activateWorktreeInput
9545
10409
  }
9546
10410
  }),
9547
10411
  surfaceContract({
@@ -9557,7 +10421,36 @@ var worktreesContracts = [
9557
10421
  convex: {
9558
10422
  module: "worktrees",
9559
10423
  functionName: "list",
9560
- kind: "query"
10424
+ kind: "query",
10425
+ inputProjection: (input) => compactRecord4({
10426
+ topicId: input.topicId,
10427
+ status: input.status,
10428
+ groupBy: input.groupBy,
10429
+ lane: input.lane,
10430
+ campaign: input.campaign,
10431
+ limit: input.limit
10432
+ })
10433
+ }
10434
+ }),
10435
+ surfaceContract({
10436
+ name: "list_campaigns",
10437
+ kind: "query",
10438
+ domain: "worktrees",
10439
+ surfaceClass: "platform_public",
10440
+ method: "GET",
10441
+ path: "/worktrees/campaigns",
10442
+ sdkNamespace: "worktrees",
10443
+ sdkMethod: "listCampaigns",
10444
+ summary: "List compact pipeline campaigns with nested lanes.",
10445
+ convex: {
10446
+ module: "worktrees",
10447
+ functionName: "listCampaigns",
10448
+ kind: "query",
10449
+ inputProjection: (input) => compactRecord4({
10450
+ topicId: input.topicId,
10451
+ status: input.status,
10452
+ limit: input.limit
10453
+ })
9561
10454
  }
9562
10455
  }),
9563
10456
  surfaceContract({
@@ -9573,7 +10466,8 @@ var worktreesContracts = [
9573
10466
  convex: {
9574
10467
  module: "worktrees",
9575
10468
  functionName: "listAll",
9576
- kind: "query"
10469
+ kind: "query",
10470
+ inputProjection: listAllWorktreesInput
9577
10471
  }
9578
10472
  }),
9579
10473
  surfaceContract({
@@ -9590,7 +10484,7 @@ var worktreesContracts = [
9590
10484
  module: "worktrees",
9591
10485
  functionName: "updateTargets",
9592
10486
  kind: "mutation",
9593
- inputProjection: worktreeInput
10487
+ inputProjection: worktreeTargetsInput
9594
10488
  }
9595
10489
  }),
9596
10490
  surfaceContract({
@@ -9607,7 +10501,7 @@ var worktreesContracts = [
9607
10501
  module: "worktrees",
9608
10502
  functionName: "updateMetadata",
9609
10503
  kind: "mutation",
9610
- inputProjection: worktreeInput
10504
+ inputProjection: worktreeMetadataInput
9611
10505
  }
9612
10506
  }),
9613
10507
  surfaceContract({
@@ -9623,12 +10517,17 @@ var worktreesContracts = [
9623
10517
  module: "worktrees",
9624
10518
  functionName: "complete",
9625
10519
  kind: "mutation",
9626
- inputProjection: (input) => ({
9627
- ...worktreeInput(input),
9628
- keyFindings: input.keyFindings ?? [input.summary ?? "Merged worktree"],
9629
- decisionsReached: input.decisionsReached ?? [],
9630
- nextSteps: input.nextSteps ?? []
9631
- })
10520
+ inputProjection: (input, context) => withUserId(
10521
+ {
10522
+ ...worktreeIdInput(input),
10523
+ keyFindings: input.keyFindings ?? [
10524
+ input.summary ?? "Merged worktree"
10525
+ ],
10526
+ decisionsReached: input.decisionsReached ?? [],
10527
+ nextSteps: input.nextSteps ?? []
10528
+ },
10529
+ context
10530
+ )
9632
10531
  }
9633
10532
  }),
9634
10533
  surfaceContract({
@@ -9644,11 +10543,7 @@ var worktreesContracts = [
9644
10543
  module: "worktrees",
9645
10544
  functionName: "updateMetadata",
9646
10545
  kind: "mutation",
9647
- inputProjection: (input) => ({
9648
- ...worktreeInput(input),
9649
- lastPushTargetContext: input.targetContext,
9650
- lastPushBeliefIds: input.beliefIds
9651
- })
10546
+ inputProjection: worktreeMetadataInput
9652
10547
  }
9653
10548
  }),
9654
10549
  surfaceContract({
@@ -9664,20 +10559,30 @@ var worktreesContracts = [
9664
10559
  module: "worktrees",
9665
10560
  functionName: "updateMetadata",
9666
10561
  kind: "mutation",
9667
- inputProjection: (input) => ({
9668
- ...worktreeInput(input),
9669
- lastPullRequestSummary: input.summary,
9670
- lastPullRequestReviewers: input.reviewers
9671
- })
10562
+ inputProjection: worktreeMetadataInput
9672
10563
  }
9673
10564
  })
9674
10565
  ];
9675
10566
 
9676
10567
  // ../contracts/src/function-registry/tasks.ts
9677
- var taskInput = (input) => ({
10568
+ var taskInput = (input) => compactRecord4({
9678
10569
  ...input,
9679
10570
  taskId: input.taskId ?? input.id
9680
10571
  });
10572
+ var taskTopicInput = (input) => {
10573
+ const parsed = listTasksProjection.inputSchema.safeParse(input);
10574
+ if (!parsed.success) {
10575
+ throw new Error(
10576
+ `list_tasks projection input rejected: ${parsed.error.message}`
10577
+ );
10578
+ }
10579
+ return compactRecord4(listTasksProjection.project(parsed.data));
10580
+ };
10581
+ var completeTaskInput = (input) => compactRecord4({
10582
+ taskId: input.taskId ?? input.id,
10583
+ outputSummary: input.outputSummary ?? input.summary,
10584
+ userId: input.userId
10585
+ });
9681
10586
  var tasksContracts = [
9682
10587
  surfaceContract({
9683
10588
  name: "create_task",
@@ -9707,8 +10612,10 @@ var tasksContracts = [
9707
10612
  convex: {
9708
10613
  module: "tasks",
9709
10614
  functionName: "getByTopic",
9710
- kind: "query"
9711
- }
10615
+ kind: "query",
10616
+ inputProjection: taskTopicInput
10617
+ },
10618
+ args: listTasksInputSchema
9712
10619
  }),
9713
10620
  surfaceContract({
9714
10621
  name: "update_task",
@@ -9740,12 +10647,29 @@ var tasksContracts = [
9740
10647
  module: "tasks",
9741
10648
  functionName: "complete",
9742
10649
  kind: "mutation",
9743
- inputProjection: taskInput
10650
+ inputProjection: completeTaskInput
9744
10651
  }
9745
10652
  })
9746
10653
  ];
9747
-
9748
- // ../contracts/src/function-registry/edges.ts
10654
+ var createEdgeArgs = z.object({
10655
+ from: GraphRefSchema,
10656
+ to: GraphRefSchema,
10657
+ edgeType: z.string(),
10658
+ globalId: z.string().optional(),
10659
+ weight: z.number().optional(),
10660
+ confidence: z.number().optional(),
10661
+ context: z.string().optional(),
10662
+ reasoning: z.string().optional(),
10663
+ derivationType: z.string().optional(),
10664
+ topicId: z.string().optional(),
10665
+ trustedBypassAccessCheck: z.boolean().optional()
10666
+ });
10667
+ function graphRefNodeId(ref) {
10668
+ if (ref.kind === "epistemic_node") {
10669
+ return ref.nodeId;
10670
+ }
10671
+ return `external_belief:${ref.ref.tenantId}:${ref.ref.beliefId}`;
10672
+ }
9749
10673
  var edgesContracts = [
9750
10674
  surfaceContract({
9751
10675
  name: "create_edge",
@@ -9760,16 +10684,35 @@ var edgesContracts = [
9760
10684
  module: "edges",
9761
10685
  functionName: "create",
9762
10686
  kind: "mutation",
9763
- inputProjection: (input, context) => withCreatedBy(
9764
- {
9765
- ...input,
9766
- fromNodeId: input.fromNodeId ?? input.sourceId,
9767
- toNodeId: input.toNodeId ?? input.targetId,
9768
- context: input.context ?? input.reasoning
9769
- },
9770
- context
9771
- )
9772
- }
10687
+ inputProjection: (input, context) => {
10688
+ const parsed = createEdgeArgs.parse(input);
10689
+ assertEdgePolicyAllowed(
10690
+ edgePolicyManifest,
10691
+ parsed.edgeType,
10692
+ parsed.from,
10693
+ parsed.to
10694
+ );
10695
+ const fromNodeId = graphRefNodeId(parsed.from);
10696
+ const toNodeId = graphRefNodeId(parsed.to);
10697
+ return withCreatedBy(
10698
+ compactRecord4({
10699
+ fromNodeId,
10700
+ toNodeId,
10701
+ edgeType: parsed.edgeType,
10702
+ globalId: parsed.globalId ?? `edge:${fromNodeId}:${toNodeId}:${parsed.edgeType}`,
10703
+ weight: parsed.weight,
10704
+ confidence: parsed.confidence,
10705
+ context: parsed.context ?? parsed.reasoning,
10706
+ derivationType: parsed.derivationType,
10707
+ skipLayerValidation: true,
10708
+ topicId: parsed.topicId,
10709
+ trustedBypassAccessCheck: parsed.trustedBypassAccessCheck
10710
+ }),
10711
+ context
10712
+ );
10713
+ }
10714
+ },
10715
+ args: createEdgeArgs
9773
10716
  }),
9774
10717
  surfaceContract({
9775
10718
  name: "query_lineage",
@@ -9784,9 +10727,12 @@ var edgesContracts = [
9784
10727
  module: "edges",
9785
10728
  functionName: "getLineage",
9786
10729
  kind: "query",
9787
- inputProjection: (input) => ({
9788
- ...input,
9789
- maxDepth: input.maxDepth ?? input.depth
10730
+ inputProjection: (input) => compactRecord4({
10731
+ nodeId: input.nodeId ?? input.startNode,
10732
+ maxDepth: input.maxDepth ?? input.depth,
10733
+ mode: input.mode,
10734
+ minLayer: input.minLayer,
10735
+ maxLayer: input.maxLayer
9790
10736
  })
9791
10737
  }
9792
10738
  })
@@ -9806,8 +10752,7 @@ var contradictionSeverity = (value) => {
9806
10752
  return "significant";
9807
10753
  }
9808
10754
  };
9809
- var flagContradictionInput = (input, context) => ({
9810
- ...input,
10755
+ var flagContradictionInput = (input, context) => compactRecord4({
9811
10756
  beliefId: input.beliefId ?? input.beliefA,
9812
10757
  supportingInsightIds: Array.isArray(input.supportingInsightIds) ? input.supportingInsightIds : [],
9813
10758
  contradictingInsightIds: Array.isArray(input.contradictingInsightIds) ? input.contradictingInsightIds : [input.beliefB].filter((value) => typeof value === "string"),
@@ -9821,6 +10766,18 @@ var flagContradictionInput = (input, context) => ({
9821
10766
  },
9822
10767
  createdBy: authUserId(context)
9823
10768
  });
10769
+ var lineageInput = (input) => compactRecord4({
10770
+ nodeId: input.nodeId ?? input.startNode ?? input.entityId,
10771
+ maxDepth: input.maxDepth ?? input.depth,
10772
+ mode: input.mode,
10773
+ minLayer: input.minLayer,
10774
+ maxLayer: input.maxLayer
10775
+ });
10776
+ var topicEdgesInput = (input) => compactRecord4({
10777
+ topicId: input.topicId,
10778
+ userId: input.userId,
10779
+ limit: input.limit
10780
+ });
9824
10781
  var graphContracts = [
9825
10782
  surfaceContract({
9826
10783
  name: "traverse_graph",
@@ -9834,7 +10791,8 @@ var graphContracts = [
9834
10791
  convex: {
9835
10792
  module: "edges",
9836
10793
  functionName: "getLineage",
9837
- kind: "query"
10794
+ kind: "query",
10795
+ inputProjection: lineageInput
9838
10796
  }
9839
10797
  }),
9840
10798
  surfaceContract({
@@ -9849,7 +10807,8 @@ var graphContracts = [
9849
10807
  convex: {
9850
10808
  module: "edges",
9851
10809
  functionName: "getByTopic",
9852
- kind: "query"
10810
+ kind: "query",
10811
+ inputProjection: topicEdgesInput
9853
10812
  }
9854
10813
  }),
9855
10814
  surfaceContract({
@@ -9879,7 +10838,10 @@ var graphContracts = [
9879
10838
  convex: {
9880
10839
  module: "edges",
9881
10840
  functionName: "findContradictions",
9882
- kind: "query"
10841
+ kind: "query",
10842
+ inputProjection: (input) => compactRecord4({
10843
+ nodeId: input.nodeId ?? input.beliefId
10844
+ })
9883
10845
  }
9884
10846
  }),
9885
10847
  surfaceContract({
@@ -9984,8 +10946,9 @@ var graphContracts = [
9984
10946
  summary: "Discover graph connections for an entity.",
9985
10947
  convex: {
9986
10948
  module: "edges",
9987
- functionName: "getByTopic",
9988
- kind: "query"
10949
+ functionName: "getLineage",
10950
+ kind: "query",
10951
+ inputProjection: lineageInput
9989
10952
  }
9990
10953
  }),
9991
10954
  surfaceContract({
@@ -10016,10 +10979,7 @@ var graphContracts = [
10016
10979
  module: "edges",
10017
10980
  functionName: "getLineage",
10018
10981
  kind: "query",
10019
- inputProjection: (input) => ({
10020
- ...input,
10021
- nodeId: input.nodeId ?? input.entityId
10022
- })
10982
+ inputProjection: lineageInput
10023
10983
  }
10024
10984
  })
10025
10985
  ];
@@ -10089,19 +11049,21 @@ var judgmentsContracts = [
10089
11049
  functionName: "create",
10090
11050
  kind: "mutation",
10091
11051
  inputProjection: (input, context) => withUserId(
10092
- {
10093
- ...input,
11052
+ compactRecord4({
11053
+ projectId: input.projectId,
11054
+ topicId: input.topicId,
10094
11055
  text: input.rationale,
10095
11056
  title: input.title,
10096
11057
  content: input.rationale,
10097
11058
  kind: "judgment",
10098
- sourceType: "agent",
10099
- metadata: {
11059
+ sourceType: "ai_generated",
11060
+ metadata: compactRecord4({
10100
11061
  confidence: input.confidence,
10101
11062
  beliefIds: input.beliefIds
10102
- },
11063
+ }),
11064
+ rationale: input.rationale ?? input.reasoning ?? "Recorded judgment evidence",
10103
11065
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10104
- },
11066
+ }),
10105
11067
  context
10106
11068
  )
10107
11069
  }
@@ -10119,9 +11081,12 @@ var judgmentsContracts = [
10119
11081
  module: "edges",
10120
11082
  functionName: "getLineage",
10121
11083
  kind: "query",
10122
- inputProjection: (input) => ({
10123
- ...input,
10124
- nodeId: input.nodeId ?? input.id
11084
+ inputProjection: (input) => compactRecord4({
11085
+ nodeId: input.nodeId ?? input.id,
11086
+ maxDepth: input.maxDepth ?? input.depth,
11087
+ mode: input.mode,
11088
+ minLayer: input.minLayer,
11089
+ maxLayer: input.maxLayer
10125
11090
  })
10126
11091
  }
10127
11092
  })
@@ -10247,7 +11212,10 @@ var coordinationContracts = [
10247
11212
  module: "coordination",
10248
11213
  functionName: "getInbox",
10249
11214
  kind: "query",
10250
- injectSessionId: "sessionId"
11215
+ injectSessionId: "sessionId",
11216
+ inputProjection: (input) => compactRecord4({
11217
+ limit: input.limit
11218
+ })
10251
11219
  }
10252
11220
  }),
10253
11221
  surfaceContract({
@@ -10265,7 +11233,6 @@ var coordinationContracts = [
10265
11233
  kind: "mutation",
10266
11234
  injectSessionId: "sessionId",
10267
11235
  inputProjection: (input) => ({
10268
- ...input,
10269
11236
  touchedFiles: stringArray(input.touchedFiles) ?? stringArray(input.files) ?? stringArray(input.paths) ?? []
10270
11237
  })
10271
11238
  }
@@ -10282,7 +11249,10 @@ var coordinationContracts = [
10282
11249
  convex: {
10283
11250
  module: "worktrees",
10284
11251
  functionName: "get",
10285
- kind: "query"
11252
+ kind: "query",
11253
+ inputProjection: (input) => compactRecord4({
11254
+ worktreeId: input.worktreeId ?? input.id
11255
+ })
10286
11256
  }
10287
11257
  })
10288
11258
  ];
@@ -10301,7 +11271,13 @@ var pipelineContracts = [
10301
11271
  convex: {
10302
11272
  module: "worktrees",
10303
11273
  functionName: "listAll",
10304
- kind: "query"
11274
+ kind: "query",
11275
+ inputProjection: (input) => compactRecord4({
11276
+ status: input.status,
11277
+ lane: input.lane,
11278
+ campaign: input.campaign,
11279
+ limit: input.limit
11280
+ })
10305
11281
  }
10306
11282
  }),
10307
11283
  surfaceContract({
@@ -10351,43 +11327,63 @@ var recordScopeLearningArgs = z.object({
10351
11327
  linkedBeliefNodeId: z.string().optional().describe("Optional belief to attach evidence to"),
10352
11328
  evidenceRelation: z.enum(["supports", "contradicts"]).optional().describe("Relation to linked belief"),
10353
11329
  confidence: z.number().optional().describe("Optional confidence in [0,1]"),
11330
+ rationale: z.string().optional().describe("Why this learning should enter the reasoning graph"),
10354
11331
  createQuestionText: z.string().optional().describe("Optional follow-up question text"),
10355
11332
  createBeliefText: z.string().optional().describe("Optional new belief text"),
10356
11333
  beliefType: z.string().optional().describe("Optional belief type for createBeliefText")
10357
11334
  });
10358
- var learningInput = (input, context) => withUserId(
10359
- {
10360
- ...input,
10361
- text: input.summary ?? input.text,
10362
- title: input.title ?? input.summary ?? "Scope learning",
10363
- content: input.body ?? input.content ?? input.summary,
10364
- kind: input.kind ?? input.sourceKind ?? "learning",
10365
- tags: input.tags ?? [],
10366
- metadata: {
10367
- sourceRef: input.sourceRef,
10368
- sourceKind: input.sourceKind,
10369
- touchedPaths: input.touchedPaths
10370
- },
10371
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10372
- },
10373
- context
10374
- );
11335
+ var learningInput = (input, context) => {
11336
+ const sourceKind = input.sourceKind ?? input.externalSourceType;
11337
+ return withUserId(
11338
+ compactRecord4({
11339
+ projectId: input.projectId,
11340
+ topicId: input.topicId,
11341
+ text: input.summary ?? input.text,
11342
+ title: input.title ?? input.summary ?? "Scope learning",
11343
+ content: input.body ?? input.content ?? input.summary,
11344
+ contentType: input.contentType,
11345
+ kind: input.kind ?? "learning",
11346
+ tags: input.tags ?? [],
11347
+ sourceType: input.sourceType,
11348
+ externalSourceType: input.externalSourceType ?? input.sourceKind,
11349
+ sourceUrl: input.sourceUrl,
11350
+ metadata: compactRecord4({
11351
+ ...recordValue2(input.metadata),
11352
+ sourceRef: input.sourceRef,
11353
+ sourceKind,
11354
+ touchedPaths: input.touchedPaths,
11355
+ createQuestionText: input.createQuestionText,
11356
+ createBeliefText: input.createBeliefText,
11357
+ beliefType: input.beliefType
11358
+ }),
11359
+ linkedBeliefNodeId: input.linkedBeliefNodeId,
11360
+ evidenceRelation: input.evidenceRelation,
11361
+ confidence: input.confidence,
11362
+ rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded scope learning",
11363
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
11364
+ }),
11365
+ context
11366
+ );
11367
+ };
10375
11368
  var attemptInput = (input, context) => withUserId(
10376
- {
10377
- ...input,
11369
+ compactRecord4({
11370
+ projectId: input.projectId,
11371
+ topicId: input.topicId,
10378
11372
  text: input.description,
10379
11373
  title: input.title ?? input.description,
10380
11374
  content: input.errorMessage ?? input.description,
10381
11375
  kind: "code_attempt",
10382
11376
  tags: ["code_attempt"],
10383
- metadata: {
11377
+ metadata: compactRecord4({
11378
+ ...recordValue2(input.metadata),
10384
11379
  filePaths: input.filePaths,
10385
11380
  filePath: input.filePath,
10386
11381
  errorMessage: input.errorMessage,
10387
11382
  linkedBeliefId: input.linkedBeliefId
10388
- },
11383
+ }),
11384
+ rationale: input.rationale ?? input.reasoning ?? input.errorMessage ?? input.description ?? "Recorded implementation attempt",
10389
11385
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10390
- },
11386
+ }),
10391
11387
  context
10392
11388
  );
10393
11389
  var codingContracts = [
@@ -10444,7 +11440,13 @@ var codingContracts = [
10444
11440
  convex: {
10445
11441
  module: "evidence",
10446
11442
  functionName: "getByTopic",
10447
- kind: "query"
11443
+ kind: "query",
11444
+ inputProjection: (input) => compactRecord4({
11445
+ topicId: input.topicId,
11446
+ limit: input.limit,
11447
+ status: input.status,
11448
+ userId: input.userId
11449
+ })
10448
11450
  }
10449
11451
  }),
10450
11452
  surfaceContract({
@@ -10459,7 +11461,13 @@ var codingContracts = [
10459
11461
  convex: {
10460
11462
  module: "evidence",
10461
11463
  functionName: "getByTopic",
10462
- kind: "query"
11464
+ kind: "query",
11465
+ inputProjection: (input) => compactRecord4({
11466
+ topicId: input.topicId,
11467
+ limit: input.limit,
11468
+ status: input.status,
11469
+ userId: input.userId
11470
+ })
10463
11471
  }
10464
11472
  }),
10465
11473
  surfaceContract({
@@ -10491,9 +11499,11 @@ var codingContracts = [
10491
11499
  module: "evidence",
10492
11500
  functionName: "getByTopic",
10493
11501
  kind: "query",
10494
- inputProjection: (input) => ({
10495
- ...input,
10496
- topicId: input.topicId ?? input.query
11502
+ inputProjection: (input) => compactRecord4({
11503
+ topicId: input.topicId ?? input.query,
11504
+ limit: input.limit,
11505
+ status: input.status,
11506
+ userId: input.userId
10497
11507
  })
10498
11508
  }
10499
11509
  })