@synap-core/workspace-templates 0.46.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +4 -3
  2. package/automations/lead-converted-becomes-client.automation.json +89 -0
  3. package/automations/lead-converted-becomes-client.catalog.json +13 -0
  4. package/capabilities/apify.capability.json +8 -1
  5. package/capabilities/apollo.capability.json +8 -1
  6. package/capabilities/cal-com.capability.json +8 -1
  7. package/capabilities/exa.capability.json +8 -1
  8. package/capabilities/fal-ai.capability.json +8 -1
  9. package/capabilities/fal-media-lab.capability.json +8 -1
  10. package/capabilities/fireflies.capability.json +8 -1
  11. package/capabilities/mailgun.capability.json +8 -1
  12. package/capabilities/omniroute.capability.json +7 -1
  13. package/capabilities/posthog-analytics.capability.json +7 -1
  14. package/capabilities/postiz.capability.json +7 -1
  15. package/capabilities/replicate-rvm.capability.json +21 -5
  16. package/capabilities/stripe.capability.json +10 -1
  17. package/capabilities/unipile-linkedin.capability.json +39 -3
  18. package/capabilities/vercel.capability.json +8 -1
  19. package/dist/{define-BAPO0xZf.d.ts → define-Dto5_E47.d.ts} +15 -3
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.js +623 -96
  22. package/dist/index.js.map +1 -1
  23. package/dist/wire.d.ts +1 -1
  24. package/package.json +1 -1
  25. package/src/agency-os.yaml +1 -1
  26. package/src/brand-library.yaml +6 -6
  27. package/src/builder.yaml +17 -12
  28. package/src/content-os.template.test.ts +38 -22
  29. package/src/content-os.video-takes.template.test.ts +4 -2
  30. package/src/content-os.yaml +33 -23
  31. package/src/crm-absorbs-outreach.template.test.ts +5 -1
  32. package/src/crm.yaml +53 -30
  33. package/src/decisions-wave.template.test.ts +99 -5
  34. package/src/finance.yaml +11 -6
  35. package/src/foundation.yaml +22 -10
  36. package/src/grants.yaml +4 -0
  37. package/src/intent.test.ts +4 -2
  38. package/src/lead-automations.test.ts +93 -0
  39. package/src/lead-becomes-client.template.test.ts +137 -0
  40. package/src/lifecycle-declarations.test.ts +20 -1
  41. package/src/lifecycle-presets.test.ts +39 -7
  42. package/src/marketing.yaml +3 -3
  43. package/src/operations.yaml +155 -24
  44. package/src/postiz-contract.test.ts +3 -2
  45. package/src/process-contract.validate.test.ts +4 -1
  46. package/src/publish-official-lib.test.ts +8 -7
  47. package/src/research-base.yaml +2 -2
  48. package/src/research-decision.yaml +1 -1
  49. package/src/ship-a-change.template.test.ts +11 -2
  50. package/src/templates.ts +223 -74
  51. package/src/types.ts +15 -3
  52. package/src/unipile-lookups-read-only.test.ts +1 -0
  53. package/src/validate-flow.ts +15 -1
  54. package/src/validate.ts +40 -4
package/src/types.ts CHANGED
@@ -668,11 +668,23 @@ export interface TemplatePlaybookStage {
668
668
  */
669
669
  gate?: { kind: "human" | "check"; proposalType?: "playbook.stage_gate" };
670
670
  /**
671
- * The value of the subject kind's lifecycle property this stage
672
- * corresponds to. Advancing INTO the stage writes it to the subject
673
- * (governed); the subject ENTERING it advances an open run to the stage.
671
+ * The IN-PROGRESS value of the subject kind's lifecycle property while this
672
+ * stage is worked (In Draft, Review). Entering the stage writes it to the
673
+ * subject (governed; a gated stage at its gate's pass); the subject
674
+ * ENTERING it advances an open run to the stage.
674
675
  */
675
676
  subjectStatus?: string;
677
+ /**
678
+ * The RESULT value this stage's APPROVED work reaches (Scripted, sent, won;
679
+ * decision D2): written when the stage's `expectedOutputs` are all
680
+ * delivered, else when the next stage's gate passes. With neither (a last
681
+ * stage, an ungated next stage, no required output) the pod never writes
682
+ * it, never on a session's end: it stays declared for the follow and
683
+ * `flow.of`, and the stage's goal names the move for whoever finishes it
684
+ * (validate.ts `stage-on-approved-no-signal`). The subject ENTERING it
685
+ * advances an open run to the NEXT stage. Pod `PlaybookStage.onApproved`.
686
+ */
687
+ onApproved?: string;
676
688
  /** Where a rejected human gate / failed check sends the run back (a stage key or name). */
677
689
  onFail?: { toStage: string };
678
690
  [key: string]: unknown;
@@ -37,6 +37,7 @@ const LOOKUPS = [
37
37
  "linkedin_find_profile",
38
38
  "linkedin_list_relations",
39
39
  "linkedin_list_invitations",
40
+ "linkedin_list_posts",
40
41
  "linkedin_list_company_pages",
41
42
  ];
42
43
  const WRITES = [
@@ -36,6 +36,7 @@
36
36
  * `schema/automations.ts`.
37
37
  */
38
38
  import { PLAYBOOK_RUN_MODES } from "@synap-core/types/automations";
39
+ import { needRefProblem } from "@synap-core/types/needs";
39
40
 
40
41
  // ── Contract constants (mirror schema/automations.ts — keep in sync) ──────────
41
42
 
@@ -311,11 +312,24 @@ export function validateFlowDefinition(
311
312
 
312
313
  switch (type) {
313
314
  case "capability": {
315
+ // A node may name a NEED instead of a verb (0426): the verb is the
316
+ // space's bound provider's, resolved at run time.
317
+ if (!nonEmptyString(data.verbId) && nonEmptyString(data.need)) {
318
+ const problem = needRefProblem(data.need);
319
+ if (problem) {
320
+ errors.push({
321
+ nodeId,
322
+ code: "capability_unknown_need",
323
+ message: `Capability node "${nodeId}": ${problem}`,
324
+ });
325
+ }
326
+ break;
327
+ }
314
328
  if (!nonEmptyString(data.verbId)) {
315
329
  errors.push({
316
330
  nodeId,
317
331
  code: "capability_missing_verbId",
318
- message: `Capability node "${nodeId}" has no \`verbId\`. Pick a verb on the selected tool.`,
332
+ message: `Capability node "${nodeId}" has no \`verbId\` (or \`need\`). Pick a verb on the selected tool, or name a need.`,
319
333
  });
320
334
  } else if (
321
335
  resolvers?.verbExists &&
package/src/validate.ts CHANGED
@@ -603,8 +603,15 @@ export function knownRelationTypes(
603
603
  /**
604
604
  * The process contract a playbook declares on top of its stages:
605
605
  * - it names no `statusProperty`, `onEnd` or `humanOnlyStatuses` (retired);
606
- * - every `stages[].subjectStatus` and `activators[].status` is an option of
607
- * the subject kind's declared lifecycle;
606
+ * - every `stages[].subjectStatus`, `stages[].onApproved` and
607
+ * `activators[].status` is an option of the subject kind's declared
608
+ * lifecycle;
609
+ * - a stage whose `onApproved` has NO approval signal (it owes no required
610
+ * output and the next stage has no gate, or it is the last stage) names
611
+ * that move in its goal: the engine never writes such a status (never on
612
+ * a session's end, decision 5e377b06), so the agent finishing the stage
613
+ * moves the subject through the status door. It stays declared so the
614
+ * follow and `flow.of` know what the stage reaches (decision D2);
608
615
  * - `onFail.toStage` names a stage (key or name) of the same playbook;
609
616
  * - every `relationToSubject` (playbook- and stage-level outputs) is a
610
617
  * relation the corpus defines, or `none`.
@@ -630,6 +637,18 @@ export const MAX_SESSION_CRITERIA = 12;
630
637
  */
631
638
  export const TEMPLATE_ACTIVATOR_ON = ["created", "enters_status", "count", "schedule", "manual"] as const;
632
639
 
640
+ /**
641
+ * Does a stage's goal NAME the move into `value` — the status value or its
642
+ * lifecycle label, as a whole word, any case? The test for an `onApproved`
643
+ * nothing approves (`stage-on-approved-no-signal`): the goal is what the agent
644
+ * finishing the stage reads, so it is where that move must be written.
645
+ */
646
+ function goalNamesStatus(goal: unknown, value: unknown, labels: Map<string, string> | null): boolean {
647
+ if (typeof goal !== "string" || typeof value !== "string") return false;
648
+ const names = [value, labels?.get(value)].filter((n): n is string => !!n && n.trim() !== "");
649
+ return names.some((n) => new RegExp(`(^|[^\\p{L}\\p{N}_])${n.trim().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}($|[^\\p{L}\\p{N}_])`, "iu").test(goal));
650
+ }
651
+
633
652
  function checkProcessContract(
634
653
  tpl: WorkspaceYaml,
635
654
  resolveDep: (slug: string) => WorkspaceYaml | undefined,
@@ -666,6 +685,7 @@ function checkProcessContract(
666
685
  // The lifecycle vocabulary: the kind's DECLARED lifecycle (null = none in
667
686
  // reach to check against).
668
687
  let statuses: Set<string> | null = null;
688
+ let labels: Map<string, string> | null = null;
669
689
  let lifecycleProperty: string | undefined;
670
690
  // A kind no declaration in reach carries is not judged without a corpus
671
691
  // (an unknown kind is reported by playbook-ref-unknown).
@@ -677,6 +697,7 @@ function checkProcessContract(
677
697
  if (declared) {
678
698
  lifecycleProperty = declared.property;
679
699
  statuses = new Set(declared.options.map((o) => o.key));
700
+ labels = new Map(declared.options.map((o) => [o.key, o.label ?? o.key]));
680
701
  }
681
702
  }
682
703
  const checkStatus = (rule: string, path: string, value: unknown) => {
@@ -710,10 +731,25 @@ function checkProcessContract(
710
731
  `${at}.criteria`,
711
732
  `playbook "${pb.name}" declares ${criterionKeys.size} criteria (playbook-level plus every stage's) — a session keeps ${MAX_SESSION_CRITERIA} and drops the rest silently`
712
733
  );
713
- for (const stage of stages) {
734
+ stages.forEach((stage, i) => {
714
735
  const sp = `${at}.stages.${stage.key}`;
715
736
  if (stage.subjectStatus !== undefined)
716
737
  checkStatus("stage-subject-status-unknown", `${sp}.subjectStatus`, stage.subjectStatus);
738
+ if (stage.onApproved !== undefined) {
739
+ checkStatus("stage-on-approved-unknown", `${sp}.onApproved`, stage.onApproved);
740
+ // The pod's two approval signals (`stage-subject-status.ts`): a
741
+ // required output of this stage (an optional one never holds it back,
742
+ // so it never approves it either), or the NEXT stage's gate passing.
743
+ // A stage's own gate approves the stage BEFORE it, never itself.
744
+ const owesOutput = (stage.expectedOutputs ?? []).some((o) => o.optional !== true);
745
+ const nextGated = !!stages[i + 1]?.gate;
746
+ if (!owesOutput && !nextGated && !goalNamesStatus(stage.goal, stage.onApproved, labels))
747
+ add(
748
+ "stage-on-approved-no-signal",
749
+ `${sp}.onApproved`,
750
+ `stage "${stage.key}" of playbook "${pb.name}" owes no required output and ${stages[i + 1] ? `the next stage "${stages[i + 1]!.key}" has no gate` : "is the last stage"}: nothing approves it, so the pod never writes onApproved "${String(stage.onApproved)}" (never on the session's end). Keep it declared, and make the goal tell whoever finishes the stage to move the subject to "${String(stage.onApproved)}" through the status door`
751
+ );
752
+ }
717
753
  const toStage = stage.onFail?.toStage;
718
754
  if (stage.onFail !== undefined && (!toStage || !stageIds.has(toStage)))
719
755
  add(
@@ -721,7 +757,7 @@ function checkProcessContract(
721
757
  `${sp}.onFail.toStage`,
722
758
  `stage "${stage.key}" onFail.toStage "${String(toStage)}" names no stage of playbook "${pb.name}"`
723
759
  );
724
- }
760
+ });
725
761
 
726
762
  (pb.activators ?? []).forEach((a, i) => {
727
763
  const ap = `${at}.activators[${i}]`;