@synap-core/workspace-templates 0.38.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/wire.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { g as PackageDefinitionOutput, X as WorkspaceDefinitionInput } from './define-YL-hIPcn.js';
1
+ import { g as PackageDefinitionOutput, X as WorkspaceDefinitionInput } from './define-C0Iizc2r.js';
2
2
  import '@synap-core/types/presentation';
3
3
  import '@synap-core/types/space-brief';
4
4
  import '@synap-core/types/capability-intents';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synap-core/workspace-templates",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "type": "module",
5
5
  "description": "Canonical workspace definitions — YAML source + typed exports for browser, backend, CLI, and marketplace",
6
6
  "repository": {
@@ -322,8 +322,9 @@ describe("Content OS Repurpose proposes once per original, never for a copy", ()
322
322
  });
323
323
 
324
324
  // "Write the caption" (founder, 5 Nov): Content Studio's "Write it for me" runs it on ONE post. It drafts, never
325
- // decides: it writes the script's "## Caption draft" section, never the "## Caption" on its own; the person's yes to ONE
326
- // owed confirm ask (or their Save in the app) makes it the caption. It binds no stage and moves no status.
325
+ // decides: it writes the script's "## Caption draft" section, never the "## Caption"; the person's "Use this draft" and
326
+ // Save in the app make it the caption. It raises no ask and closes nothing: a run has no session tools (founder, 9 Nov:
327
+ // the tools win; schema/run-tools.guard.test.ts holds every playbook to that). It binds no stage and moves no status.
327
328
  describe("Content OS Write the caption drafts one post's caption, never the person's", () => {
328
329
  const playbooks = (template.playbooks ?? []) as TemplatePlaybook[];
329
330
  const caption = playbooks.find((p) => p.name === "Write the caption");
@@ -337,11 +338,11 @@ describe("Content OS Write the caption drafts one post's caption, never the pers
337
338
 
338
339
  it("writes the draft section only, never the saved caption, and never moves the status", () => {
339
340
  expect(caption?.goalTemplate).toMatch(/"## Caption draft" section/);
340
- expect(caption?.goalTemplate).toMatch(/Never write or change the "## Caption" section on\s+your own/);
341
- // The person's approval is ONE owed confirm ask; only their yes makes the draft the caption.
342
- expect(caption?.goalTemplate).toMatch(/ONE confirm ask on this session/);
343
- expect(caption?.goalTemplate).toMatch(/On yes, put the draft in\s+the "## Caption" section/);
344
- expect(caption?.goalTemplate).toMatch(/Never move the post's status/);
341
+ expect(caption?.goalTemplate).toMatch(/Never write or change the "## Caption" section:\s+it\s+is the person's/);
342
+ // The person approves in Content Studio ("Use this draft" + Save); the run itself asks nothing and closes nothing.
343
+ expect(caption?.goalTemplate).toMatch(/"Use this draft" and their Save make it the caption/);
344
+ expect(caption?.goalTemplate).not.toMatch(/\bask\b|\bclose\b|\bOn yes\b/i);
345
+ expect(caption?.goalTemplate).toMatch(/Never\s+move the post's status/);
345
346
  expect(caption?.stages ?? []).toEqual([]);
346
347
  expect(caption?.activators ?? []).toEqual([]);
347
348
  expect(caption?.expectedOutputs).toEqual([expect.objectContaining({ kind: "document", label: "Caption draft", relationToSubject: "none" })]);
@@ -2409,8 +2409,11 @@ playbooks:
2409
2409
  # caption so I don't have to"). Content Studio's "Write it for me" on a post's
2410
2410
  # Caption box runs it for that post. It writes a DRAFT, the script document's
2411
2411
  # "## Caption draft" section, never the "## Caption" the person saved; the
2412
- # person approves it through ONE owed confirm ask (yes: the draft becomes the
2413
- # caption) or uses it in the app's Caption box and saves it there. It works
2412
+ # person approves it in the app's Caption box ("Use this draft", then Save).
2413
+ # It raises no ask and closes nothing: a run has no session tools (founder,
2414
+ # 9 Nov: when a playbook's text and its run's tools disagree, the tools win;
2415
+ # the pod, not the agent, raises a person's approval at a run's end;
2416
+ # schema/run-tools.guard.test.ts keeps every playbook to that). It works
2414
2417
  # one post but binds no stage and never moves the status.
2415
2418
  - name: Write the caption
2416
2419
  description: Draft the caption of one post from its brief and its script, as a draft in its script document that the person edits and saves.
@@ -2428,15 +2431,11 @@ playbooks:
2428
2431
  and no line that starts with "##". Put it in the script document as its
2429
2432
  "## Caption draft" section: replace that section if it is there, else add
2430
2433
  it at the end, and change no other line (synap_update_document with the
2431
- revision you read). Never write or change the "## Caption" section on
2432
- your own: it is the person's. Then ask the person to approve your draft:
2433
- ONE confirm ask on this session (owner the person), its prompt the
2434
- caption itself, "Use this caption" recommended. On yes, put the draft in
2435
- the "## Caption" section (replace its words, or add it) and remove the
2436
- "## Caption draft" section, nothing else. On no, leave the draft where it
2437
- is (they may edit it and save it on the post's page in Content Studio,
2438
- which also makes it the caption). Never move the post's status. Close
2439
- this session once the person answered.
2434
+ revision you read). Never write or change the "## Caption" section: it
2435
+ is the person's. They approve your draft on the post's page in Content
2436
+ Studio, where "Use this draft" and their Save make it the caption. Never
2437
+ move the post's status. Stop once the draft is in the document: your
2438
+ answer is the caption draft itself.
2440
2439
  subjectProfile:
2441
2440
  profileSlug: post
2442
2441
  # Typed output: the draft lives in the post's own script document (a
@@ -54,7 +54,7 @@ const stageOf = (name: string, key: string) => {
54
54
  };
55
55
 
56
56
  const CADENCE =
57
- 'CADENCE: when a message is sent (a person approved its proposed message, so it is an outbound message in the channel), set its lead\'s lastContactedAt to the sent day, count the messages sent to the lead (the outbound messages in its channels, read with synap_get_channel mode person: for a company lead, the channels of the person written to there), and set the lead\'s next action: after the first message, nextAction "Follow up with <name> if no reply" and nextActionAt the sent day + 3 days; after the first follow-up, nextAction "Follow up with <name> a last time if no reply" and nextActionAt the sent day + 7 days; after the second follow-up, nextAction "No reply after two follow-ups: nurture or drop <name>" and nextActionAt the sent day + 7 days, and when that date passes with no reply, "Follow up on leads in outreach" proposes nurturing. Never a third follow-up. Propose moving a lead at new or researching to outreach through the status door, with its expected status. A reply stops the cadence: a reply is an inbound message after our last outbound one in the channel, and "Follow up on leads in outreach" reads it and proposes the next step.';
57
+ 'CADENCE: when a message is sent (a person approved its proposed message, so it is an outbound message in the channel), set its lead\'s lastContactedAt to the sent day, count the messages sent to the lead (the outbound messages in its channels, read with synap_get_channel mode person: for a company lead, the channels of the person written to there), and set the lead\'s next action: after the first message, nextAction "Follow up with <name> if no reply" and nextActionAt the sent day + 3 days; after the first follow-up, nextAction "Follow up with <name> a last time if no reply" and nextActionAt the sent day + 7 days; after the second follow-up, nextAction "No reply after two follow-ups: nurture or drop <name>" and nextActionAt the sent day + 7 days, and when that date passes with no reply, "Follow up on leads in outreach" proposes nurturing. Never a third follow-up. Propose moving a lead at qualified to outreach through the status door, with its expected status. A reply stops the cadence: a reply is an inbound message after our last outbound one in the channel, and "Follow up on leads in outreach" reads it and proposes the next step.';
58
58
 
59
59
  /**
60
60
  * The LinkedIn order (CRM wave 2, S4b, build map 6f6c197f; changed by the CRM
@@ -108,6 +108,18 @@ describe("CRM messages and cadence — catalog contract", () => {
108
108
  expect(holders.sort()).toEqual([...SENDERS].sort());
109
109
  });
110
110
 
111
+ it("a lead enters outreach from QUALIFIED (we qualify before we contact), the order the sent automation moves it in", () => {
112
+ const texts = (crm.playbooks ?? []).flatMap((p) => [
113
+ flat(p.goalTemplate),
114
+ ...(p.stages ?? []).map((s) => flat((s as { goal?: string }).goal)),
115
+ ]);
116
+ const joined = texts.join(" | ");
117
+ expect(joined).not.toMatch(/new or researching (lead )?(to|at)|lead at new or researching|new or researching lead to outreach/);
118
+ // non-vacuity: the old wording was in three goals and one stage; the new one is in all of them
119
+ expect(texts.filter((x) => x.includes("Propose moving a lead at qualified to outreach")).length).toBe(3);
120
+ expect(texts.some((x) => x.includes("propose moving a qualified lead to outreach"))).toBe(true);
121
+ });
122
+
111
123
  it("no CRM process keeps the old weekly cadence or the 14-day silence default", () => {
112
124
  const texts = (crm.playbooks ?? []).flatMap((p) => [
113
125
  [p.name, flat(p.goalTemplate)],
package/src/crm.yaml CHANGED
@@ -53,10 +53,10 @@ meta:
53
53
  suggestFor: [small-business, founder]
54
54
  views: [deal-pipeline, deals-table, deals-list]
55
55
  example:
56
- - { title: "Acme renewal", values: { commercialStage: negotiating, value: 12000, nextStep: "Send revised quote Thu" } }
57
- - { title: "Nordlys brand audit", values: { commercialStage: proposed, value: 6000, nextStep: "Follow up on proposal Mon" } }
58
- - { title: "Atelier 9 workshop", values: { commercialStage: draft, value: 2800, nextStep: "Discovery call Wed" } }
59
- - { title: "Maison Dupont redesign", values: { commercialStage: won, value: 18000, nextStep: "Kick-off next week" } }
56
+ - { title: "Acme renewal", values: { commercialStage: negotiating, value: 12000, nextAction: "Send revised quote Thu" } }
57
+ - { title: "Nordlys brand audit", values: { commercialStage: proposed, value: 6000, nextAction: "Follow up on proposal Mon" } }
58
+ - { title: "Atelier 9 workshop", values: { commercialStage: draft, value: 2800, nextAction: "Discovery call Wed" } }
59
+ - { title: "Maison Dupont redesign", values: { commercialStage: won, value: 18000, nextAction: "Kick-off next week" } }
60
60
  - { title: "Lumen Studio retainer", values: { commercialStage: lost, value: 4500 } }
61
61
  firstSession:
62
62
  title: Your live deals
@@ -177,14 +177,6 @@ profiles:
177
177
  label: Last contact date
178
178
  valueType: date
179
179
  inputType: date
180
- - slug: nextFollowUpDate
181
- label: Next follow-up date
182
- valueType: date
183
- inputType: date
184
- - slug: nextStep
185
- label: Next step
186
- valueType: string
187
- inputType: textarea
188
180
  - slug: notes
189
181
  label: Notes
190
182
  valueType: string
@@ -263,14 +255,6 @@ profiles:
263
255
  label: Last contact date
264
256
  valueType: date
265
257
  inputType: date
266
- - slug: nextFollowUpDate
267
- label: Next follow-up date
268
- valueType: date
269
- inputType: date
270
- - slug: nextStep
271
- label: Next step
272
- valueType: string
273
- inputType: textarea
274
258
  - slug: notes
275
259
  label: Notes
276
260
  valueType: string
@@ -290,9 +274,9 @@ profiles:
290
274
  lifecycle:
291
275
  property: commercialStage
292
276
  options:
293
- - { key: draft, label: Meeting booked, category: open, stuckAfterDays: 14 }
294
- - { key: proposed, label: Proposal sent, category: active, stuckAfterDays: 14 }
295
- - { key: negotiating, category: active, stuckAfterDays: 14 }
277
+ - { key: draft, label: Meeting booked, category: open, stuckAfterDays: 14, requires: [{ kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }] }
278
+ - { key: proposed, label: Proposal sent, category: active, stuckAfterDays: 14, requires: [{ kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }] }
279
+ - { key: negotiating, category: active, stuckAfterDays: 14, requires: [{ kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }] }
296
280
  - { key: won, category: done }
297
281
  - { key: lost, category: lost, humanOnly: true }
298
282
  properties:
@@ -343,10 +327,17 @@ profiles:
343
327
  label: Meeting date
344
328
  valueType: date
345
329
  inputType: date
346
- - slug: nextStep
347
- label: Next step
330
+ # ONE next-step pair on the work (founder, 2026-11-09): the same
331
+ # `nextAction` + `nextActionAt` the lead carries. Person and company have
332
+ # none: their next step lives on the lead role they wear.
333
+ - slug: nextAction
334
+ label: Next action
348
335
  valueType: string
349
336
  inputType: textarea
337
+ - slug: nextActionAt
338
+ label: Next action at
339
+ valueType: date
340
+ inputType: date
350
341
  - slug: description
351
342
  label: Notes
352
343
  valueType: string
@@ -422,7 +413,8 @@ profiles:
422
413
  displayName: Contact
423
414
  profileKind: role
424
415
  # Qualification fields "Qualify a lead" fills. Extras only: foundation's own
425
- # `leadStage` (the lead's ONE lifecycle) and `notes` are not restated.
416
+ # `leadStage` (the lead's ONE lifecycle), `nextActionAt` (the date outreach's
417
+ # wait is bound to) and `notes` are not restated.
426
418
  # Moved verbatim from business-developer (2026-10-12).
427
419
  - slug: lead
428
420
  displayName: Lead
@@ -494,10 +486,6 @@ profiles:
494
486
  label: Last contacted at
495
487
  valueType: date
496
488
  inputType: date
497
- - slug: nextActionAt
498
- label: Next action at
499
- valueType: date
500
- inputType: date
501
489
  - slug: nextAction
502
490
  label: Next action
503
491
  valueType: string
@@ -902,7 +890,7 @@ views:
902
890
  scopeProfileSlug: deal
903
891
  description: Every deal with its stage, value, expected close date and next step.
904
892
  config:
905
- columns: [title, commercialStage, value, closeDate, nextStep]
893
+ columns: [title, commercialStage, value, closeDate, nextAction, nextActionAt]
906
894
  - name: Deals list
907
895
  slug: deals-list
908
896
  type: list
@@ -964,6 +952,12 @@ onboarding:
964
952
  Populate the workspace with live work, not a perfect historical archive:
965
953
  propose the three to five opportunities the user is actively trying to
966
954
  move, then add the companies and people needed to understand those deals.
955
+ - >
956
+ An import creates people and companies, never leads: the lead role is a
957
+ qualification decision a person makes, one record at a time. Prefer a
958
+ lead on the company, with the founder as the contact; add a person lead
959
+ only when no company is known. Each lead carries one next action with a
960
+ date (nextAction, nextActionAt), the same pair a deal carries.
967
961
  - >
968
962
  Every active deal needs one observable next step with a date. If the next
969
963
  step is "follow up" or "keep warm", help turn it into a specific action
@@ -991,17 +985,17 @@ onboarding:
991
985
  min: 1
992
986
  what: The real prospect organisations behind current conversations.
993
987
  cardinality: few
994
- keyFields: [website, industry, companySize, source, nextStep]
988
+ keyFields: [website, industry, companySize, source]
995
989
  - profileSlug: person
996
990
  min: 1
997
991
  what: The known stakeholders for those organisations and opportunities.
998
992
  cardinality: few
999
- keyFields: [email, jobTitle, company, source, nextFollowUpDate]
993
+ keyFields: [email, jobTitle, company, source]
1000
994
  - profileSlug: deal
1001
995
  min: 1
1002
996
  what: The live opportunities worth actively moving through the pipeline.
1003
997
  cardinality: few
1004
- keyFields: [commercialStage, value, closeDate, nextStep]
998
+ keyFields: [commercialStage, value, closeDate, nextAction, nextActionAt]
1005
999
  openingQuestions:
1006
1000
  - "Which three to five opportunities are you actively trying to move right now?"
1007
1001
  - "For the most important one, which company and real stakeholder are involved?"
@@ -1160,7 +1154,7 @@ playbooks:
1160
1154
  Pass 2 — Flag stalled deals. Find `deal` records with no activity for a
1161
1155
  while or stuck in the same `commercialStage` past the stage's stuck
1162
1156
  threshold (14 days in Meeting booked, Proposal sent or negotiating).
1163
- For each stalled deal, propose a concise `nextStep` to unblock it and note
1157
+ For each stalled deal, propose a concise `nextAction` (and its `nextActionAt`) to unblock it and note
1164
1158
  why it looks stalled. Do not advance a deal's stage on its behalf — surface
1165
1159
  the risk and a recommended action for the human to decide.
1166
1160
 
@@ -1556,7 +1550,7 @@ playbooks:
1556
1550
  nextAction "No reply after two follow-ups: nurture or drop <name>" and
1557
1551
  nextActionAt the sent day + 7 days, and when that date passes with no
1558
1552
  reply, "Follow up on leads in outreach" proposes nurturing. Never a
1559
- third follow-up. Propose moving a lead at new or researching to
1553
+ third follow-up. Propose moving a lead at qualified to
1560
1554
  outreach through the status door, with its expected status. A reply
1561
1555
  stops the cadence: a reply is an inbound message after our last
1562
1556
  outbound one in the channel, and "Follow up on leads in outreach"
@@ -1615,7 +1609,7 @@ playbooks:
1615
1609
  - key: send
1616
1610
  name: Person sends
1617
1611
  category: completed
1618
- goal: The person reviews the proposed message in the channel, edits it if needed and approves it, and the pod sends it; then set the lead's lastContactedAt to the sent day, nextAction "Follow up with <name> if no reply" and nextActionAt the sent day + 3 days, and propose moving a new or researching lead to outreach.
1612
+ goal: The person reviews the proposed message in the channel, edits it if needed and approves it, and the pod sends it; then set the lead's lastContactedAt to the sent day, nextAction "Follow up with <name> if no reply" and nextActionAt the sent day + 3 days, and propose moving a qualified lead to outreach.
1619
1613
  gate: { kind: human }
1620
1614
  onFail: { toStage: draft }
1621
1615
 
@@ -1900,7 +1894,7 @@ playbooks:
1900
1894
  nextAction "No reply after two follow-ups: nurture or drop <name>" and
1901
1895
  nextActionAt the sent day + 7 days, and when that date passes with no
1902
1896
  reply, "Follow up on leads in outreach" proposes nurturing. Never a
1903
- third follow-up. Propose moving a lead at new or researching to
1897
+ third follow-up. Propose moving a lead at qualified to
1904
1898
  outreach through the status door, with its expected status. A reply
1905
1899
  stops the cadence: a reply is an inbound message after our last
1906
1900
  outbound one in the channel, and "Follow up on leads in outreach"
@@ -2032,7 +2026,7 @@ playbooks:
2032
2026
  nextAction "No reply after two follow-ups: nurture or drop <name>" and
2033
2027
  nextActionAt the sent day + 7 days, and when that date passes with no
2034
2028
  reply, "Follow up on leads in outreach" proposes nurturing. Never a
2035
- third follow-up. Propose moving a lead at new or researching to
2029
+ third follow-up. Propose moving a lead at qualified to
2036
2030
  outreach through the status door, with its expected status. A reply
2037
2031
  stops the cadence: a reply is an inbound message after our last
2038
2032
  outbound one in the channel, and "Follow up on leads in outreach"
@@ -2367,7 +2361,7 @@ playbooks:
2367
2361
  comes from. A cell reads the pod ONLY through the cell bridge, at
2368
2362
  render time: window.synap.query(op, params), with an op of the bridge
2369
2363
  table (entities.list, entities.get, views.list, profiles.list,
2370
- lifecycle.board, lifecycle.throughput, attention.needsYou,
2364
+ lifecycle.board, flow.of, lifecycle.throughput, attention.needsYou,
2371
2365
  attention.count, sessions.list, lifecycle.home, lifecycle.moving,
2372
2366
  documents.get, lens.page) and only that op's params; the host stamps
2373
2367
  the space, so never put a workspaceId, a token, a pod URL or a fetch in
@@ -519,7 +519,12 @@ profiles:
519
519
  displayName: Lead
520
520
  icon: user-plus
521
521
  color: yellow
522
- description: An early-pipeline prospect — not yet a client, being qualified or nurtured.
522
+ description: >-
523
+ An early-pipeline prospect — not yet a client, being qualified or nurtured.
524
+ The lead role is a qualification decision a person makes, never a label an
525
+ import applies: importing a contacts file creates people and companies, not
526
+ leads. Prefer a lead on the company, with the founder as the contact; a
527
+ person lead is allowed when no company is known.
523
528
  scope: shared
524
529
  profileKind: role
525
530
  applicableKinds:
@@ -530,13 +535,47 @@ profiles:
530
535
  # person records a booked meeting, which opens the deal; no agent sets it.
531
536
  lifecycle:
532
537
  property: leadStage
538
+ # Stage ORDER is the pipeline's reading order (founder, 2026-11-09, board
539
+ # review 24df5916): we qualify BEFORE we contact. Categories are unchanged.
533
540
  options:
534
- - { key: new, category: open }
535
- - { key: researching, category: open }
536
- - { key: outreach, category: open }
537
- - { key: engaged, category: active }
538
- - { key: qualified, category: active }
539
- - { key: nurturing, category: active }
541
+ - key: new
542
+ category: open
543
+ requires:
544
+ - { kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }
545
+ - key: researching
546
+ category: open
547
+ requires:
548
+ - { kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }
549
+ # Company first, a person still allowed: a soft nudge, an agent's to find.
550
+ - { kind: link, blockerKey: no_company, label: "Their company", relation: works_at, direction: out, owner: agent, forKinds: [person] }
551
+ - key: qualified
552
+ category: active
553
+ requires:
554
+ - { kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }
555
+ # Outreach is a WAIT on their reply (status-first, 2026-11-09): the
556
+ # step is late once the lead's `nextActionAt` passes while it stands here.
557
+ - key: outreach
558
+ category: open
559
+ dateBinding: nextActionAt
560
+ waits: { on: person, waitKind: their_reply, dateBinding: nextActionAt }
561
+ # What a lead must HAVE before outreach can start: derived live as a
562
+ # blocker on the lead, never a stored flag (`LifecycleOption.requires`).
563
+ # `works_at` runs person -> company, so a company's contacts are `in`.
564
+ # `no_contact` names no `clearedBy`: its fix is the "Find the right
565
+ # contact" playbook, and a playbook id is pod-local (the catalog names
566
+ # none), so the card offers no action until the catalog can name it.
567
+ requires:
568
+ - { kind: link, blockerKey: no_contact, label: "A contact at the company", relation: works_at, direction: in, forKinds: [company] }
569
+ - { kind: property, blockerKey: no_linkedin, label: "Their LinkedIn profile", property: linkedinUrl, owner: agent, clearedBy: { capability: linkedin_find_profile }, forKinds: [person] }
570
+ - { kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }
571
+ - key: engaged
572
+ category: active
573
+ requires:
574
+ - { kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }
575
+ - key: nurturing
576
+ category: active
577
+ requires:
578
+ - { kind: property, blockerKey: no_next_step, label: "A next step with a date", property: nextActionAt, owner: you }
540
579
  - { key: converted, category: done, humanOnly: true }
541
580
  - { key: disqualified, category: lost, humanOnly: true }
542
581
  properties:
@@ -553,13 +592,19 @@ profiles:
553
592
  enumValues:
554
593
  - new
555
594
  - researching
595
+ - qualified
556
596
  - outreach
557
597
  - engaged
558
- - qualified
559
598
  - nurturing
560
599
  - converted
561
600
  - disqualified
562
601
  constraints: { defaultValue: new }
602
+ # The date outreach's wait is bound to (`dateBinding`): declared here, with
603
+ # the lifecycle that names it, so a foundation-only pod can declare it.
604
+ - slug: nextActionAt
605
+ label: Next action at
606
+ valueType: date
607
+ inputType: date
563
608
  - slug: notes
564
609
  label: Notes
565
610
  valueType: string
package/src/index.ts CHANGED
@@ -150,6 +150,7 @@ export {
150
150
  REQUIRED_META_FIELDS,
151
151
  REQUIRED_WORKSPACE_FIELDS,
152
152
  lifecycleOptionWaitsProblems,
153
+ lifecycleOptionRequiresProblem,
153
154
  LIFECYCLE_OPTION_FIELDS,
154
155
  LIFECYCLE_OPTION_WAITS_FIELDS,
155
156
  LIFECYCLE_WAITS_ON,
@@ -0,0 +1,104 @@
1
+ /**
2
+ * The catalog automations that move a lead: qualified -> outreach on a sent message, outreach -> engaged on an inbound
3
+ * reply (founder decision 2026-11-09; backend#965 gives `facet_update` the
4
+ * lifecycle move through the one door, `viaRelation` + `expectedStatus`).
5
+ *
6
+ * Pinned: the flow passes the shipped flow validator; the trigger filter is the
7
+ * YAML/JSON BOOLEAN `isReply: true` (a quoted "true" never matches `===`); the
8
+ * move names only options of the lead lifecycle, from outreach to engaged; the
9
+ * header exists (so the catalog publishes it); the lead lifecycle really holds
10
+ * both options. Not covered: that a pod runs it end to end (NEEDS-DOGFOOD).
11
+ */
12
+ import { readFileSync } from "node:fs";
13
+ import { dirname, join } from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ import { describe, expect, it } from "vitest";
16
+ import { validateFlowDefinition } from "./validate-flow.js";
17
+ import { getWorkspaceTemplate } from "./templates.js";
18
+
19
+ const dir = join(dirname(fileURLToPath(import.meta.url)), "../automations");
20
+ const read = (f: string) => JSON.parse(readFileSync(join(dir, f), "utf8"));
21
+ const automation = read("lead-reply-engaged.automation.json");
22
+ const header = read("lead-reply-engaged.catalog.json");
23
+ const nodes = automation.flowDefinition.nodes as Array<{ id: string; type: string; data: Record<string, any> }>;
24
+ const move = nodes.find((n) => n.data.outputType === "facet_update")!;
25
+
26
+ describe("lead-reply-engaged", () => {
27
+ it("passes the flow validator", () => {
28
+ const r = validateFlowDefinition(automation.flowDefinition);
29
+ expect(r.errors).toEqual([]);
30
+ });
31
+
32
+ it("fires on an inbound message that is a reply (isReply is a boolean, on trigger and node)", () => {
33
+ expect(automation.triggerConfig.eventPattern).toBe("external_message.received.completed");
34
+ expect(automation.triggerConfig.filters.isReply).toBe(true);
35
+ const t = nodes.find((n) => n.type === "trigger")!;
36
+ expect(t.data.config.filters.isReply).toBe(true);
37
+ });
38
+
39
+ it("moves the sender's lead outreach -> engaged through facet_update, guarded on a named entity", () => {
40
+ expect(move.data.config).toEqual({
41
+ entityId: "{{trigger.payload.data.entityId}}",
42
+ facetSlug: "lead",
43
+ viaRelation: "works_at",
44
+ expectedStatus: "outreach",
45
+ status: "engaged",
46
+ });
47
+ const guard = nodes.find((n) => n.type === "guard")!;
48
+ expect(guard.data.checks[0]).toMatchObject({ path: "trigger.payload.data.entityId", minLength: 36 });
49
+ });
50
+
51
+ it("names only options of the lead lifecycle", () => {
52
+ const lead = getWorkspaceTemplate("foundation")!.profiles.find((p) => p.slug === "lead")!;
53
+ const keys = lead.lifecycle!.options.map((o) => o.key);
54
+ expect(keys).toContain(move.data.config.expectedStatus);
55
+ expect(keys).toContain(move.data.config.status);
56
+ });
57
+
58
+ it("has a catalog header, so it is published", () => {
59
+ expect(header.kind).toBe("automation");
60
+ expect(header.meta.slug).toBe("lead-reply-engaged");
61
+ });
62
+ });
63
+
64
+ describe("lead-sent-outreach", () => {
65
+ const sent = read("lead-sent-outreach.automation.json");
66
+ const sentHeader = read("lead-sent-outreach.catalog.json");
67
+ const sentNodes = sent.flowDefinition.nodes as Array<{ id: string; type: string; data: Record<string, any> }>;
68
+ const reach = sentNodes.find((n) => n.data.outputType === "facet_update")!;
69
+
70
+ it("passes the flow validator", () => {
71
+ expect(validateFlowDefinition(sent.flowDefinition).errors).toEqual([]);
72
+ });
73
+
74
+ it("fires on a message SENT to a person (the physical event, on trigger and node)", () => {
75
+ expect(sent.triggerConfig.eventPattern).toBe("external_message.sent.completed");
76
+ expect(sentNodes.find((n) => n.type === "trigger")!.data.config.eventPattern).toBe("external_message.sent.completed");
77
+ });
78
+
79
+ it("moves the person's lead qualified -> outreach, the shape of the reply automation", () => {
80
+ expect(reach.data.config).toEqual({
81
+ entityId: "{{trigger.payload.data.entityId}}",
82
+ facetSlug: "lead",
83
+ viaRelation: "works_at",
84
+ expectedStatus: "qualified",
85
+ status: "outreach",
86
+ });
87
+ const guard = sentNodes.find((n) => n.type === "guard")!;
88
+ expect(guard.data.checks[0]).toMatchObject({ path: "trigger.payload.data.entityId", minLength: 36 });
89
+ });
90
+
91
+ it("is the outreach entry of the reply chain: sent ends where reply begins", () => {
92
+ // sent: qualified -> outreach; reply: outreach -> engaged. A chain with a gap or a loop would strand leads.
93
+ expect(reach.data.config.status).toBe(move.data.config.expectedStatus);
94
+ const lead = getWorkspaceTemplate("foundation")!.profiles.find((p) => p.slug === "lead")!;
95
+ const keys = lead.lifecycle!.options.map((o) => o.key);
96
+ expect(keys.indexOf(reach.data.config.expectedStatus)).toBeLessThan(keys.indexOf(reach.data.config.status));
97
+ expect(keys).toContain(reach.data.config.expectedStatus);
98
+ });
99
+
100
+ it("has a catalog header, so it is published", () => {
101
+ expect(sentHeader.kind).toBe("automation");
102
+ expect(sentHeader.meta.slug).toBe("lead-sent-outreach");
103
+ });
104
+ });
@@ -16,12 +16,22 @@
16
16
  * - the whole corpus validates with zero `lifecycle-*` errors, and each rule
17
17
  * fires on a broken clone (self-checks).
18
18
  */
19
+ import { readFileSync } from "node:fs";
20
+ import { dirname, join } from "node:path";
21
+ import { fileURLToPath } from "node:url";
19
22
  import { describe, expect, it } from "vitest";
20
23
  import { LIFECYCLE_CATEGORIES as TYPES_CATEGORIES } from "@synap-core/types/lifecycle";
21
24
  import { LIFECYCLE_CATEGORIES, SYSTEM_PROFILES, validateTemplate } from "./validate.js";
22
25
  import type { TemplateLifecycle, WorkspaceYaml } from "./types.js";
23
26
  import { readYamlTemplates } from "./generate.mjs";
24
27
 
28
+ const NO_NEXT_STEP = {
29
+ kind: "property",
30
+ blockerKey: "no_next_step",
31
+ label: "A next step with a date",
32
+ property: "nextActionAt",
33
+ owner: "you",
34
+ };
25
35
  const corpus = readYamlTemplates().map((t) => t.data as WorkspaceYaml);
26
36
  const tpl = (slug: string) => corpus.find((t) => t.meta.slug === slug)!;
27
37
  const lifecycleOf = (t: WorkspaceYaml, profile: string): TemplateLifecycle | undefined =>
@@ -62,6 +72,105 @@ describe("lifecycle declarations — the mandatory four", () => {
62
72
  });
63
73
  });
64
74
 
75
+ it("lead outreach declares its wait: on their reply, late after nextActionAt", () => {
76
+ const lc = lifecycleOf(tpl("foundation"), "lead");
77
+ const outreach = lc?.options.find((o) => o.key === "outreach");
78
+ expect(outreach?.waits).toEqual({ on: "person", waitKind: "their_reply", dateBinding: "nextActionAt" });
79
+ expect(outreach?.dateBinding).toBe("nextActionAt");
80
+ // the bound date is declared by foundation itself (a foundation-only pod can declare the wait)
81
+ const date = tpl("foundation").profiles.find((p) => p.slug === "lead")?.properties?.find((x) => x.slug === "nextActionAt");
82
+ expect(date?.valueType).toBe("date");
83
+ // one list: the select's values ARE the lifecycle's option keys, default = initial status
84
+ const prop = tpl("foundation").profiles.find((p) => p.slug === "lead")?.properties?.find((x) => x.slug === "leadStage");
85
+ expect(prop?.enumValues).toEqual(lc?.options.map((o) => o.key));
86
+ expect(prop?.constraints?.defaultValue).toBe(lc?.options[0].key);
87
+ });
88
+
89
+ it("lead stages read in order: we qualify BEFORE we contact (board review 24df5916)", () => {
90
+ const lc = lifecycleOf(tpl("foundation"), "lead");
91
+ const keys = (lc?.options ?? []).map((o) => o.key);
92
+ expect(keys).toEqual(["new", "researching", "qualified", "outreach", "engaged", "nurturing", "converted", "disqualified"]);
93
+ // one list: the select's values ARE the option keys, in the same order
94
+ const prop = tpl("foundation").profiles.find((p) => p.slug === "lead")?.properties?.find((x) => x.slug === "leadStage");
95
+ expect(prop?.enumValues).toEqual(keys);
96
+ });
97
+
98
+ it("lead outreach requires a contact (company) and a LinkedIn profile (person), as derived blockers", () => {
99
+ const outreach = lifecycleOf(tpl("foundation"), "lead")?.options.find((o) => o.key === "outreach");
100
+ expect(outreach?.requires).toEqual([
101
+ { kind: "link", blockerKey: "no_contact", label: "A contact at the company", relation: "works_at", direction: "in", forKinds: ["company"] },
102
+ {
103
+ kind: "property",
104
+ blockerKey: "no_linkedin",
105
+ label: "Their LinkedIn profile",
106
+ property: "linkedinUrl",
107
+ owner: "agent",
108
+ clearedBy: { capability: "linkedin_find_profile" },
109
+ forKinds: ["person"],
110
+ },
111
+ NO_NEXT_STEP,
112
+ ]);
113
+ // the capability it names is a verb the catalog really ships
114
+ const verbs = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../capabilities/unipile-linkedin.capability.json"), "utf8");
115
+ expect(verbs).toContain('"name": "linkedin_find_profile"');
116
+ });
117
+
118
+ it("every open or active lead stage requires a dated next step; researching nudges company first; finished stages require nothing", () => {
119
+ const lc = lifecycleOf(tpl("foundation"), "lead")!;
120
+ for (const o of lc.options) {
121
+ const finished = o.category === "done" || o.category === "lost";
122
+ const keys = (o.requires ?? []).map((r) => r.blockerKey);
123
+ expect(keys.includes("no_next_step"), o.key).toBe(!finished);
124
+ expect(keys.includes("no_company"), o.key).toBe(o.key === "researching");
125
+ if (finished) expect(o.requires, o.key).toBeUndefined();
126
+ }
127
+ const researching = lc.options.find((o) => o.key === "researching")!;
128
+ expect(researching.requires).toContainEqual({
129
+ kind: "link",
130
+ blockerKey: "no_company",
131
+ label: "Their company",
132
+ relation: "works_at",
133
+ direction: "out",
134
+ owner: "agent",
135
+ forKinds: ["person"],
136
+ });
137
+ // the date it asks for is declared by the role itself
138
+ const lead = tpl("foundation").profiles.find((p) => p.slug === "lead")!;
139
+ expect(lead.properties?.some((x) => x.slug === "nextActionAt")).toBe(true);
140
+ });
141
+
142
+ it("the guidance says: an import creates people, never leads; a lead is a qualification decision; company first", () => {
143
+ const flat = (t: string | undefined) => (t ?? "").replace(/\s+/g, " ");
144
+ const lead = tpl("foundation").profiles.find((p) => p.slug === "lead")!;
145
+ expect(flat(lead.description)).toMatch(/never a label an import applies/);
146
+ expect(flat(lead.description)).toMatch(/importing a contacts file creates people and companies, not leads/);
147
+ expect(flat(lead.description)).toMatch(/Prefer a lead on the company, with the founder as the contact/);
148
+ const starters = (tpl("crm").onboarding?.expertise?.starters ?? []).map(flat).join(" | ");
149
+ expect(starters).toMatch(/An import creates people and companies, never leads/);
150
+ });
151
+
152
+ it("deal open and active stages require a dated next step too; won and lost do not", () => {
153
+ const lc = lifecycleOf(tpl("crm"), "deal")!;
154
+ for (const o of lc.options) {
155
+ const finished = o.category === "done" || o.category === "lost";
156
+ expect(o.requires, o.key).toEqual(finished ? undefined : [NO_NEXT_STEP]);
157
+ }
158
+ });
159
+
160
+ it("ONE next-step pair on the work: lead and deal carry nextAction + nextActionAt; person and company carry neither old slug", () => {
161
+ const crm = tpl("crm");
162
+ const slugs = (kind: string) => (crm.profiles.find((p) => p.slug === kind)?.properties ?? []).map((x) => x.slug);
163
+ for (const kind of ["person", "company", "deal"]) {
164
+ expect(slugs(kind), kind).not.toContain("nextStep");
165
+ expect(slugs(kind), kind).not.toContain("nextFollowUpDate");
166
+ }
167
+ expect(slugs("deal")).toEqual(expect.arrayContaining(["nextAction", "nextActionAt"]));
168
+ expect(slugs("lead")).toContain("nextAction");
169
+ // nothing else in the template names an old slug (views, keyFields, seeds, prose)
170
+ const text = JSON.stringify(crm);
171
+ expect(text).not.toMatch(/nextStep|nextFollowUpDate/);
172
+ });
173
+
65
174
  it("client = clientStatus, churned is a lost status (never a role)", () => {
66
175
  for (const slug of ["foundation", "grants"]) {
67
176
  const lc = lifecycleOf(tpl(slug), "client");