@oxygen-agent/cli 1.987.20 → 1.1003.12

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 (106) hide show
  1. package/README.md +1 -1
  2. package/dist/admin-primary-providers-render.d.ts +0 -2
  3. package/dist/admin-primary-providers-render.js +1 -1
  4. package/dist/browser-login.js +1 -4
  5. package/dist/command-manifest.d.ts +3 -2
  6. package/dist/command-manifest.js +10 -0
  7. package/dist/credentials.d.ts +1 -1
  8. package/dist/functions-commands.js +6 -2
  9. package/dist/help.d.ts +8 -0
  10. package/dist/help.js +46 -0
  11. package/dist/index.js +1569 -123
  12. package/dist/knowledge-mirror.d.ts +2 -2
  13. package/dist/runtime.d.ts +0 -15
  14. package/dist/runtime.js +1 -1
  15. package/dist/session.d.ts +4 -3
  16. package/dist/skills.d.ts +8 -7
  17. package/dist/skills.js +24 -10
  18. package/dist/transcript.d.ts +2 -1
  19. package/dist/util.d.ts +1 -1
  20. package/dist/util.js +1 -3
  21. package/node_modules/@oxygen/formula/dist/coerce.d.ts +10 -0
  22. package/node_modules/@oxygen/formula/dist/coerce.js +10 -0
  23. package/node_modules/@oxygen/formula/dist/formula-functions.js +65 -0
  24. package/node_modules/@oxygen/formula/dist/hash.d.ts +19 -0
  25. package/node_modules/@oxygen/formula/dist/hash.js +199 -0
  26. package/node_modules/@oxygen/formula/dist/value-cleaners.d.ts +6 -1
  27. package/node_modules/@oxygen/formula/dist/value-cleaners.js +10 -26
  28. package/node_modules/@oxygen/shared/dist/array-utils.d.ts +5 -0
  29. package/node_modules/@oxygen/shared/dist/array-utils.js +11 -0
  30. package/node_modules/@oxygen/shared/dist/billing.d.ts +78 -22
  31. package/node_modules/@oxygen/shared/dist/billing.js +150 -40
  32. package/node_modules/@oxygen/shared/dist/capability-discovery.d.ts +17 -0
  33. package/node_modules/@oxygen/shared/dist/capability-discovery.js +89 -16
  34. package/node_modules/@oxygen/shared/dist/column-autofill.d.ts +52 -0
  35. package/node_modules/@oxygen/shared/dist/column-autofill.js +80 -0
  36. package/node_modules/@oxygen/shared/dist/column-output-fields.js +2 -6
  37. package/node_modules/@oxygen/shared/dist/company-enrichment-fields.d.ts +108 -0
  38. package/node_modules/@oxygen/shared/dist/company-enrichment-fields.js +545 -0
  39. package/node_modules/@oxygen/shared/dist/copilot-skills.generated.d.ts +2 -2
  40. package/node_modules/@oxygen/shared/dist/copilot-skills.generated.js +2 -2
  41. package/node_modules/@oxygen/shared/dist/deploy-env.d.ts +74 -0
  42. package/node_modules/@oxygen/shared/dist/deploy-env.js +82 -0
  43. package/node_modules/@oxygen/shared/dist/dnc-rules.d.ts +130 -0
  44. package/node_modules/@oxygen/shared/dist/dnc-rules.js +221 -0
  45. package/node_modules/@oxygen/shared/dist/enrichment-intents.d.ts +103 -0
  46. package/node_modules/@oxygen/shared/dist/enrichment-intents.js +819 -0
  47. package/node_modules/@oxygen/shared/dist/error-message.d.ts +1 -0
  48. package/node_modules/@oxygen/shared/dist/error-message.js +3 -0
  49. package/node_modules/@oxygen/shared/dist/error-redaction.js +1 -3
  50. package/node_modules/@oxygen/shared/dist/external-write-policy.d.ts +33 -0
  51. package/node_modules/@oxygen/shared/dist/external-write-policy.js +68 -0
  52. package/node_modules/@oxygen/shared/dist/format-percent.d.ts +8 -0
  53. package/node_modules/@oxygen/shared/dist/format-percent.js +13 -0
  54. package/node_modules/@oxygen/shared/dist/freemail-domains.d.ts +81 -0
  55. package/node_modules/@oxygen/shared/dist/freemail-domains.js +157 -0
  56. package/node_modules/@oxygen/shared/dist/future-signup-lifecycle-projection.d.ts +1 -0
  57. package/node_modules/@oxygen/shared/dist/future-signup-lifecycle-projection.js +1 -1
  58. package/node_modules/@oxygen/shared/dist/index.d.ts +13 -0
  59. package/node_modules/@oxygen/shared/dist/index.js +13 -0
  60. package/node_modules/@oxygen/shared/dist/json-path.js +1 -3
  61. package/node_modules/@oxygen/shared/dist/knowledge-bases.js +1 -3
  62. package/node_modules/@oxygen/shared/dist/knowledge-bootstrap.d.ts +2 -2
  63. package/node_modules/@oxygen/shared/dist/knowledge-bootstrap.js +2 -2
  64. package/node_modules/@oxygen/shared/dist/langfuse.js +9 -0
  65. package/node_modules/@oxygen/shared/dist/linkedin-countries.d.ts +32 -0
  66. package/node_modules/@oxygen/shared/dist/linkedin-countries.js +359 -0
  67. package/node_modules/@oxygen/shared/dist/log-sink-selector.d.ts +39 -0
  68. package/node_modules/@oxygen/shared/dist/log-sink-selector.js +56 -0
  69. package/node_modules/@oxygen/shared/dist/log.d.ts +1 -0
  70. package/node_modules/@oxygen/shared/dist/log.js +6 -1
  71. package/node_modules/@oxygen/shared/dist/object-storage.d.ts +17 -0
  72. package/node_modules/@oxygen/shared/dist/object-storage.js +21 -0
  73. package/node_modules/@oxygen/shared/dist/otlp-log-sink.d.ts +54 -0
  74. package/node_modules/@oxygen/shared/dist/otlp-log-sink.js +213 -0
  75. package/node_modules/@oxygen/shared/dist/plan-capabilities.js +1 -0
  76. package/node_modules/@oxygen/shared/dist/plan-limits.d.ts +23 -22
  77. package/node_modules/@oxygen/shared/dist/plan-limits.js +45 -18
  78. package/node_modules/@oxygen/shared/dist/pricing-sheet.d.ts +48 -41
  79. package/node_modules/@oxygen/shared/dist/pricing-sheet.js +36 -25
  80. package/node_modules/@oxygen/shared/dist/pricing-snapshot.generated.d.ts +22 -22
  81. package/node_modules/@oxygen/shared/dist/pricing-snapshot.generated.js +40 -34
  82. package/node_modules/@oxygen/shared/dist/product-analytics-environment.js +9 -0
  83. package/node_modules/@oxygen/shared/dist/product-analytics-events.d.ts +15 -0
  84. package/node_modules/@oxygen/shared/dist/product-analytics-events.js +15 -0
  85. package/node_modules/@oxygen/shared/dist/rate-window.d.ts +5 -0
  86. package/node_modules/@oxygen/shared/dist/rate-window.js +8 -0
  87. package/node_modules/@oxygen/shared/dist/research-output-contract.js +1 -3
  88. package/node_modules/@oxygen/shared/dist/search-vocab.js +4 -5
  89. package/node_modules/@oxygen/shared/dist/select-options.js +6 -1
  90. package/node_modules/@oxygen/shared/dist/sequence-failures.js +1 -5
  91. package/node_modules/@oxygen/shared/dist/sequences.d.ts +23 -0
  92. package/node_modules/@oxygen/shared/dist/sequences.js +110 -4
  93. package/node_modules/@oxygen/shared/dist/spend-safety.d.ts +22 -10
  94. package/node_modules/@oxygen/shared/dist/spend-safety.js +15 -21
  95. package/node_modules/@oxygen/shared/dist/sql-rows.d.ts +1 -0
  96. package/node_modules/@oxygen/shared/dist/sql-rows.js +3 -0
  97. package/node_modules/@oxygen/shared/dist/telemetry.js +9 -1
  98. package/node_modules/@oxygen/shared/dist/type-guards.d.ts +22 -0
  99. package/node_modules/@oxygen/shared/dist/type-guards.js +35 -0
  100. package/node_modules/@oxygen/shared/dist/value-readers.d.ts +21 -0
  101. package/node_modules/@oxygen/shared/dist/value-readers.js +59 -0
  102. package/node_modules/@oxygen/shared/dist/version.js +1 -1
  103. package/node_modules/@oxygen/shared/package.json +50 -0
  104. package/node_modules/@oxygen/workflows/dist/graph/expression.js +2 -5
  105. package/node_modules/@oxygen/workflows/dist/graph/params.js +1 -1
  106. package/package.json +2 -2
@@ -0,0 +1,74 @@
1
+ /**
2
+ * One answer to "which deployment is this, and is it holding production data".
3
+ *
4
+ * Before this module the repo had at least four: `VERCEL_ENV === "production" ||
5
+ * NODE_ENV === "production"` (the recipe sandbox guard), `FLY_ENVIRONMENT ===
6
+ * "production" || NODE_ENV === "production"` (the worker health guard), the
7
+ * Fly-app-name chain in `apps/worker/src/worker-env.ts`, and the
8
+ * product-analytics / Langfuse environment pickers. Self-hosting adds
9
+ * environments that are neither the managed prod nor the managed dev app while
10
+ * carrying production-shaped data (`selfhost-shadow`), which is exactly the case
11
+ * every one of those expressions answers wrong.
12
+ *
13
+ * `OXYGEN_DEPLOY_ENV` is the discriminator. Unset means managed: every caller
14
+ * falls back to the legacy signals byte-identically, so a managed environment
15
+ * that sets nothing behaves precisely as production does today
16
+ * (`.agents/skills/oxygen-platform-portability/SKILL.md` rule 1).
17
+ *
18
+ * Deliberately dependency-free apart from `OxygenError`: the log shipper, the
19
+ * OTel registration and the worker boot guard all read it before any heavier
20
+ * module is loaded.
21
+ */
22
+ export type DeployPlatform = "managed" | "selfhost";
23
+ /**
24
+ * `shadow` is a self-hosted environment running against production-shaped data
25
+ * during the cutover rehearsal. It is NOT production traffic, but it is
26
+ * production data — hence `isProductionData()` covers it while the telemetry
27
+ * environment keeps it out of the production dataset.
28
+ */
29
+ export type DeployTier = "prod" | "shadow" | "dev" | "local";
30
+ export type DeployEnvSource = "OXYGEN_DEPLOY_ENV" | "VERCEL_ENV" | "FLY_APP_NAME" | "NODE_ENV" | "none";
31
+ export type DeployEnv = {
32
+ platform: DeployPlatform;
33
+ tier: DeployTier;
34
+ /** Stable human/telemetry label: the raw selector on self-hosted, `managed-<tier>` otherwise. */
35
+ label: string;
36
+ /** Which signal decided the tier — the field to print when an operator disputes the answer. */
37
+ source: DeployEnvSource;
38
+ };
39
+ /**
40
+ * Resolves the deployment identity of this process.
41
+ *
42
+ * Throws `invalid_deploy_env` on any non-empty `OXYGEN_DEPLOY_ENV` that is not
43
+ * one of the three self-hosted values. A typo must fail the process, never fall
44
+ * through to the managed chain: falling through would silently resolve a
45
+ * self-hosted box holding production data as `local`, which is the exact shape
46
+ * of the sandbox-guard landmine this module exists to close.
47
+ */
48
+ export declare function resolveDeployEnv(env?: NodeJS.ProcessEnv): DeployEnv;
49
+ /**
50
+ * True when this process may touch production data, i.e. when an unsandboxed
51
+ * executor, a duplicated sweep or an external write would hit real customers.
52
+ *
53
+ * With `OXYGEN_DEPLOY_ENV` set this is the tier (`prod` or `shadow`). With it
54
+ * unset this is EXACTLY the legacy expression the recipe sandbox guard has
55
+ * always used — not the resolved tier — because the tier chain reads
56
+ * `FLY_APP_NAME` before `NODE_ENV` and would therefore disengage the guard on a
57
+ * Fly dev app that a Doppler secret had put into `NODE_ENV=production`. Unset
58
+ * means managed, and managed means byte-identical.
59
+ */
60
+ export declare function isProductionData(env?: NodeJS.ProcessEnv): boolean;
61
+ /** True when this process runs on self-hosted infrastructure. */
62
+ export declare function isSelfhost(env?: NodeJS.ProcessEnv): boolean;
63
+ /**
64
+ * The `deployment.environment` / tracing-environment value implied by
65
+ * `OXYGEN_DEPLOY_ENV`, or `null` when it is unset so the caller keeps its own
66
+ * managed chain untouched.
67
+ *
68
+ * `selfhost-shadow` maps to `development`: it carries production-shaped data but
69
+ * must never land in the production telemetry dataset, where it would be read as
70
+ * real customer traffic.
71
+ */
72
+ export declare function deployEnvTelemetryEnvironment(env?: NodeJS.ProcessEnv): "production" | "development" | null;
73
+ /** The `oxygen.platform` telemetry attribute: `managed` or `selfhost`. */
74
+ export declare function deployPlatformAttribute(env?: NodeJS.ProcessEnv): DeployPlatform;
@@ -0,0 +1,82 @@
1
+ import { OxygenError } from "./cli-result.js";
2
+ const SELFHOST_TIERS = new Map([
3
+ ["selfhost-prod", "prod"],
4
+ ["selfhost-shadow", "shadow"],
5
+ ["selfhost-dev", "dev"],
6
+ ]);
7
+ function managed(tier, source) {
8
+ return { platform: "managed", tier, label: `managed-${tier}`, source };
9
+ }
10
+ /**
11
+ * Resolves the deployment identity of this process.
12
+ *
13
+ * Throws `invalid_deploy_env` on any non-empty `OXYGEN_DEPLOY_ENV` that is not
14
+ * one of the three self-hosted values. A typo must fail the process, never fall
15
+ * through to the managed chain: falling through would silently resolve a
16
+ * self-hosted box holding production data as `local`, which is the exact shape
17
+ * of the sandbox-guard landmine this module exists to close.
18
+ */
19
+ export function resolveDeployEnv(env = process.env) {
20
+ const configured = env.OXYGEN_DEPLOY_ENV?.trim();
21
+ if (configured) {
22
+ const tier = SELFHOST_TIERS.get(configured.toLowerCase());
23
+ if (!tier) {
24
+ throw new OxygenError("invalid_deploy_env", `OXYGEN_DEPLOY_ENV must be one of selfhost-prod, selfhost-shadow, selfhost-dev (received '${configured}').`, { details: { oxygen_deploy_env: configured }, exitCode: 1 });
25
+ }
26
+ return { platform: "selfhost", tier, label: `selfhost-${tier}`, source: "OXYGEN_DEPLOY_ENV" };
27
+ }
28
+ const vercelEnv = env.VERCEL_ENV?.trim();
29
+ if (vercelEnv === "production")
30
+ return managed("prod", "VERCEL_ENV");
31
+ if (vercelEnv === "preview" || vercelEnv === "development")
32
+ return managed("dev", "VERCEL_ENV");
33
+ const flyApp = env.FLY_APP_NAME?.trim();
34
+ if (flyApp)
35
+ return managed(flyApp.includes("-dev") ? "dev" : "prod", "FLY_APP_NAME");
36
+ const nodeEnv = env.NODE_ENV?.trim();
37
+ if (nodeEnv === "production")
38
+ return managed("prod", "NODE_ENV");
39
+ if (nodeEnv)
40
+ return managed("local", "NODE_ENV");
41
+ return managed("local", "none");
42
+ }
43
+ /**
44
+ * True when this process may touch production data, i.e. when an unsandboxed
45
+ * executor, a duplicated sweep or an external write would hit real customers.
46
+ *
47
+ * With `OXYGEN_DEPLOY_ENV` set this is the tier (`prod` or `shadow`). With it
48
+ * unset this is EXACTLY the legacy expression the recipe sandbox guard has
49
+ * always used — not the resolved tier — because the tier chain reads
50
+ * `FLY_APP_NAME` before `NODE_ENV` and would therefore disengage the guard on a
51
+ * Fly dev app that a Doppler secret had put into `NODE_ENV=production`. Unset
52
+ * means managed, and managed means byte-identical.
53
+ */
54
+ export function isProductionData(env = process.env) {
55
+ if (env.OXYGEN_DEPLOY_ENV?.trim()) {
56
+ const { tier } = resolveDeployEnv(env);
57
+ return tier === "prod" || tier === "shadow";
58
+ }
59
+ return env.VERCEL_ENV === "production" || env.NODE_ENV === "production";
60
+ }
61
+ /** True when this process runs on self-hosted infrastructure. */
62
+ export function isSelfhost(env = process.env) {
63
+ return resolveDeployEnv(env).platform === "selfhost";
64
+ }
65
+ /**
66
+ * The `deployment.environment` / tracing-environment value implied by
67
+ * `OXYGEN_DEPLOY_ENV`, or `null` when it is unset so the caller keeps its own
68
+ * managed chain untouched.
69
+ *
70
+ * `selfhost-shadow` maps to `development`: it carries production-shaped data but
71
+ * must never land in the production telemetry dataset, where it would be read as
72
+ * real customer traffic.
73
+ */
74
+ export function deployEnvTelemetryEnvironment(env = process.env) {
75
+ if (!env.OXYGEN_DEPLOY_ENV?.trim())
76
+ return null;
77
+ return resolveDeployEnv(env).tier === "prod" ? "production" : "development";
78
+ }
79
+ /** The `oxygen.platform` telemetry attribute: `managed` or `selfhost`. */
80
+ export function deployPlatformAttribute(env = process.env) {
81
+ return resolveDeployEnv(env).platform;
82
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The workspace do-not-contact RULE CATALOG: which events may put somebody on the
3
+ * DNC list, and what the workspace has decided each one should do.
4
+ *
5
+ * WHY THIS EXISTS. Suppression ENFORCEMENT has always been absolute and layered —
6
+ * enrollment, plan and a dispatch-time re-check per channel — and none of that is
7
+ * configurable, on purpose: once an identity is on a ledger it always blocks. What
8
+ * was equally hardcoded, and should not have been, is ENTRY. Six writers decided
9
+ * unilaterally who lands on the list, and one of them was blunt enough to be a
10
+ * product complaint in its own right: ANY inbound LinkedIn message suppressed that
11
+ * person org-wide, forever, so a lead who replied "sure, send me pricing" could
12
+ * never be enrolled in another campaign again.
13
+ *
14
+ * The split this module draws is therefore: the workspace owns WHO GETS ON the
15
+ * list; the platform still owns WHAT A LIST ENTRY DOES. A rule resolves to one of
16
+ * three effects:
17
+ *
18
+ * off — the event is observed and recorded as it always was, but writes no
19
+ * suppression. Nothing else about the event changes.
20
+ * stop_only — end THIS enrollment, do not write the permanent ledger row. The
21
+ * missing middle: "a reply stops the cadence" without "blacklist this
22
+ * human from every future campaign".
23
+ * suppress — stop and write the ledger row. The default for every rule that
24
+ * shipped before this catalog existed, which is what makes the
25
+ * defaults a byte-for-byte reproduction of previous behaviour.
26
+ *
27
+ * DEFAULTS ARE THE OLD BEHAVIOUR. Every pre-existing rule defaults to `suppress`
28
+ * with the exact reason its writer used to hardcode, and every rule introduced with
29
+ * this catalog defaults to `off`. A workspace that never opens the Rules page keeps
30
+ * precisely the product it had, and a policy read that fails resolves to these
31
+ * defaults rather than dropping a suppression on the floor.
32
+ *
33
+ * COMPLIANCE RULES ARE CONFIGURABLE, AND FLAGGED. `email_unsubscribe_click` and
34
+ * `email_hard_bounce` carry `compliance: true`. That flag does not lock them — the
35
+ * product owner's decision (2026-09-19) is that a workspace may set any rule to any
36
+ * allowed effect — it marks the two whose surfaces must say plainly what turning
37
+ * them down means: an explicit unsubscribe request that is not honoured, and a
38
+ * hard-bounced address that keeps being mailed from the shared pool (which is also
39
+ * the numerator of the mailbox auto-pause). The warning is the product's job; the
40
+ * decision is the customer's.
41
+ */
42
+ /** What a rule does when its event fires. */
43
+ export declare const DNC_RULE_EFFECTS: readonly ["off", "stop_only", "suppress"];
44
+ export type DncRuleEffect = (typeof DNC_RULE_EFFECTS)[number];
45
+ export declare const DNC_RULE_EFFECT_LABELS: Record<DncRuleEffect, string>;
46
+ /**
47
+ * Which ledger a rule writes when it resolves to `suppress`. This decides which
48
+ * reason enum the configured reason is validated against, so a rule can never be
49
+ * saved with a reason its target table's CHECK constraint would reject at write
50
+ * time — the failure has to land on the person changing the setting, not on the
51
+ * inbound webhook hours later.
52
+ */
53
+ export declare const DNC_RULE_LEDGERS: readonly ["email", "contact", "phone"];
54
+ export type DncRuleLedger = (typeof DNC_RULE_LEDGERS)[number];
55
+ export type DncRuleDefinition = {
56
+ key: string;
57
+ /** Short label for a list row. */
58
+ label: string;
59
+ /** One sentence naming the exact event, in customer words. */
60
+ description: string;
61
+ /** Which DNC ledger a `suppress` writes. */
62
+ ledger: DncRuleLedger;
63
+ /** Effect when the workspace has not overridden the rule. */
64
+ defaultEffect: DncRuleEffect;
65
+ /** Reason stamped on the ledger row when the rule suppresses. */
66
+ defaultReason: string;
67
+ /**
68
+ * The effects this rule can actually express. A call disposition has no cadence
69
+ * step to stop, so `stop_only` is omitted rather than offered and silently
70
+ * behaving like `off`.
71
+ */
72
+ allowedEffects: readonly DncRuleEffect[];
73
+ /** Surfaces must warn before this rule is set below `suppress`. See the header. */
74
+ compliance?: boolean;
75
+ /** Grouping for the surfaces. */
76
+ group: "automatic" | "reply_classification";
77
+ };
78
+ /**
79
+ * The writers that existed before this catalog, each pinned to the reason and
80
+ * ledger it used to hardcode. Changing a `defaultEffect` or `defaultReason` here
81
+ * silently changes every workspace that has not overridden that rule, which is why
82
+ * `dnc-rules.test.ts` pins every one of them.
83
+ *
84
+ * `whatsapp_reply` is the LinkedIn rule's twin and was found the same way: an
85
+ * inbound WhatsApp message suppressed the lead org-wide with no way to say
86
+ * otherwise. Its DNC identity is the normalized chat JID rather than a lead
87
+ * provider id, because `whatsapp_message` is excluded from lead resolution — see
88
+ * the note in whatsapp-inbox-service.ts about why it is deliberately NOT the
89
+ * phone ledger.
90
+ */
91
+ export declare const DNC_BUILTIN_RULES: readonly DncRuleDefinition[];
92
+ /**
93
+ * Reply-classification rules are addressed by label key, so an org's own inbox
94
+ * labels get rules on exactly the same footing as the shipped ones. The prefix
95
+ * keeps that namespace from ever colliding with a builtin key.
96
+ */
97
+ export declare const DNC_REPLY_STATUS_RULE_PREFIX = "reply_status:";
98
+ export declare function replyStatusRuleKey(labelKey: string): string;
99
+ export declare function replyStatusLabelKey(ruleKey: string): string | null;
100
+ /**
101
+ * Build the rule definition for one inbox label. `ledger: "email"` is not a claim
102
+ * that the rule is email-only — it names which reason enum the reason is validated
103
+ * against. The applier picks the ledger per identity at write time, because the
104
+ * same classified conversation can carry an email address, a LinkedIn person, or
105
+ * both, and a classified LinkedIn DM must be able to suppress the LinkedIn person.
106
+ */
107
+ export declare function replyStatusRule(label: {
108
+ key: string;
109
+ name?: string | null;
110
+ }): DncRuleDefinition;
111
+ /** The builtin definition for a key, or null when the key is not a builtin. */
112
+ export declare function builtinDncRule(key: string): DncRuleDefinition | null;
113
+ export declare function isDncRuleEffect(value: unknown): value is DncRuleEffect;
114
+ /**
115
+ * Resolve a stored rule key to its definition. A `reply_status:*` key resolves even
116
+ * when the org has since renamed or archived the label, so an override never
117
+ * becomes unreadable (and therefore unresettable) because a label moved.
118
+ */
119
+ export declare function resolveDncRuleDefinition(key: string, labels?: ReadonlyArray<{
120
+ key: string;
121
+ name?: string | null;
122
+ }>): DncRuleDefinition | null;
123
+ /**
124
+ * The full catalog a surface renders: the six builtins, then one rule per inbox
125
+ * label the workspace can classify a reply as.
126
+ */
127
+ export declare function dncRuleCatalog(labels?: ReadonlyArray<{
128
+ key: string;
129
+ name?: string | null;
130
+ }>): DncRuleDefinition[];
@@ -0,0 +1,221 @@
1
+ /**
2
+ * The workspace do-not-contact RULE CATALOG: which events may put somebody on the
3
+ * DNC list, and what the workspace has decided each one should do.
4
+ *
5
+ * WHY THIS EXISTS. Suppression ENFORCEMENT has always been absolute and layered —
6
+ * enrollment, plan and a dispatch-time re-check per channel — and none of that is
7
+ * configurable, on purpose: once an identity is on a ledger it always blocks. What
8
+ * was equally hardcoded, and should not have been, is ENTRY. Six writers decided
9
+ * unilaterally who lands on the list, and one of them was blunt enough to be a
10
+ * product complaint in its own right: ANY inbound LinkedIn message suppressed that
11
+ * person org-wide, forever, so a lead who replied "sure, send me pricing" could
12
+ * never be enrolled in another campaign again.
13
+ *
14
+ * The split this module draws is therefore: the workspace owns WHO GETS ON the
15
+ * list; the platform still owns WHAT A LIST ENTRY DOES. A rule resolves to one of
16
+ * three effects:
17
+ *
18
+ * off — the event is observed and recorded as it always was, but writes no
19
+ * suppression. Nothing else about the event changes.
20
+ * stop_only — end THIS enrollment, do not write the permanent ledger row. The
21
+ * missing middle: "a reply stops the cadence" without "blacklist this
22
+ * human from every future campaign".
23
+ * suppress — stop and write the ledger row. The default for every rule that
24
+ * shipped before this catalog existed, which is what makes the
25
+ * defaults a byte-for-byte reproduction of previous behaviour.
26
+ *
27
+ * DEFAULTS ARE THE OLD BEHAVIOUR. Every pre-existing rule defaults to `suppress`
28
+ * with the exact reason its writer used to hardcode, and every rule introduced with
29
+ * this catalog defaults to `off`. A workspace that never opens the Rules page keeps
30
+ * precisely the product it had, and a policy read that fails resolves to these
31
+ * defaults rather than dropping a suppression on the floor.
32
+ *
33
+ * COMPLIANCE RULES ARE CONFIGURABLE, AND FLAGGED. `email_unsubscribe_click` and
34
+ * `email_hard_bounce` carry `compliance: true`. That flag does not lock them — the
35
+ * product owner's decision (2026-09-19) is that a workspace may set any rule to any
36
+ * allowed effect — it marks the two whose surfaces must say plainly what turning
37
+ * them down means: an explicit unsubscribe request that is not honoured, and a
38
+ * hard-bounced address that keeps being mailed from the shared pool (which is also
39
+ * the numerator of the mailbox auto-pause). The warning is the product's job; the
40
+ * decision is the customer's.
41
+ */
42
+ /** What a rule does when its event fires. */
43
+ export const DNC_RULE_EFFECTS = ["off", "stop_only", "suppress"];
44
+ export const DNC_RULE_EFFECT_LABELS = {
45
+ off: "Do nothing",
46
+ stop_only: "Stop this enrollment only",
47
+ suppress: "Stop and add to do-not-contact",
48
+ };
49
+ /**
50
+ * Which ledger a rule writes when it resolves to `suppress`. This decides which
51
+ * reason enum the configured reason is validated against, so a rule can never be
52
+ * saved with a reason its target table's CHECK constraint would reject at write
53
+ * time — the failure has to land on the person changing the setting, not on the
54
+ * inbound webhook hours later.
55
+ */
56
+ export const DNC_RULE_LEDGERS = ["email", "contact", "phone"];
57
+ const ALL_EFFECTS = DNC_RULE_EFFECTS;
58
+ const OFF_OR_SUPPRESS = ["off", "suppress"];
59
+ /**
60
+ * The writers that existed before this catalog, each pinned to the reason and
61
+ * ledger it used to hardcode. Changing a `defaultEffect` or `defaultReason` here
62
+ * silently changes every workspace that has not overridden that rule, which is why
63
+ * `dnc-rules.test.ts` pins every one of them.
64
+ *
65
+ * `whatsapp_reply` is the LinkedIn rule's twin and was found the same way: an
66
+ * inbound WhatsApp message suppressed the lead org-wide with no way to say
67
+ * otherwise. Its DNC identity is the normalized chat JID rather than a lead
68
+ * provider id, because `whatsapp_message` is excluded from lead resolution — see
69
+ * the note in whatsapp-inbox-service.ts about why it is deliberately NOT the
70
+ * phone ledger.
71
+ */
72
+ export const DNC_BUILTIN_RULES = [
73
+ {
74
+ key: "email_hard_bounce",
75
+ label: "Email hard bounce",
76
+ description: "A message to this address bounced permanently.",
77
+ ledger: "email",
78
+ defaultEffect: "suppress",
79
+ defaultReason: "hard_bounce",
80
+ allowedEffects: ALL_EFFECTS,
81
+ compliance: true,
82
+ group: "automatic",
83
+ },
84
+ {
85
+ key: "email_unsubscribe_click",
86
+ label: "One-click unsubscribe",
87
+ description: "The recipient used the unsubscribe link in one of your emails.",
88
+ ledger: "email",
89
+ defaultEffect: "suppress",
90
+ defaultReason: "unsubscribe",
91
+ allowedEffects: ALL_EFFECTS,
92
+ compliance: true,
93
+ group: "automatic",
94
+ },
95
+ {
96
+ key: "email_optout_phrase",
97
+ label: "Opt-out wording in an email reply",
98
+ description: 'The reply contains an explicit opt-out phrase such as "unsubscribe" or "take me off".',
99
+ ledger: "email",
100
+ defaultEffect: "suppress",
101
+ defaultReason: "unsubscribe",
102
+ allowedEffects: ALL_EFFECTS,
103
+ group: "automatic",
104
+ },
105
+ {
106
+ key: "linkedin_reply",
107
+ label: "LinkedIn reply received",
108
+ description: "Any inbound LinkedIn message from a lead, whatever it says.",
109
+ ledger: "contact",
110
+ defaultEffect: "suppress",
111
+ defaultReason: "replied",
112
+ allowedEffects: ALL_EFFECTS,
113
+ group: "automatic",
114
+ },
115
+ {
116
+ key: "whatsapp_reply",
117
+ label: "WhatsApp reply received",
118
+ description: "Any inbound WhatsApp message from a lead, whatever it says.",
119
+ ledger: "contact",
120
+ defaultEffect: "suppress",
121
+ defaultReason: "replied",
122
+ allowedEffects: ALL_EFFECTS,
123
+ group: "automatic",
124
+ },
125
+ {
126
+ key: "call_do_not_call",
127
+ label: 'Call marked "do not call"',
128
+ description: "A rep set the do-not-call disposition on a call task.",
129
+ ledger: "phone",
130
+ defaultEffect: "suppress",
131
+ defaultReason: "do_not_call",
132
+ allowedEffects: OFF_OR_SUPPRESS,
133
+ group: "automatic",
134
+ },
135
+ {
136
+ key: "call_wrong_number",
137
+ label: 'Call marked "wrong number"',
138
+ description: "A rep set the wrong-number disposition on a call task.",
139
+ ledger: "phone",
140
+ defaultEffect: "suppress",
141
+ defaultReason: "wrong_number",
142
+ allowedEffects: OFF_OR_SUPPRESS,
143
+ group: "automatic",
144
+ },
145
+ ];
146
+ /**
147
+ * Reply-classification rules are addressed by label key, so an org's own inbox
148
+ * labels get rules on exactly the same footing as the shipped ones. The prefix
149
+ * keeps that namespace from ever colliding with a builtin key.
150
+ */
151
+ export const DNC_REPLY_STATUS_RULE_PREFIX = "reply_status:";
152
+ export function replyStatusRuleKey(labelKey) {
153
+ return `${DNC_REPLY_STATUS_RULE_PREFIX}${labelKey}`;
154
+ }
155
+ export function replyStatusLabelKey(ruleKey) {
156
+ if (!ruleKey.startsWith(DNC_REPLY_STATUS_RULE_PREFIX))
157
+ return null;
158
+ const labelKey = ruleKey.slice(DNC_REPLY_STATUS_RULE_PREFIX.length).trim();
159
+ return labelKey.length > 0 ? labelKey : null;
160
+ }
161
+ /**
162
+ * Build the rule definition for one inbox label. `ledger: "email"` is not a claim
163
+ * that the rule is email-only — it names which reason enum the reason is validated
164
+ * against. The applier picks the ledger per identity at write time, because the
165
+ * same classified conversation can carry an email address, a LinkedIn person, or
166
+ * both, and a classified LinkedIn DM must be able to suppress the LinkedIn person.
167
+ */
168
+ export function replyStatusRule(label) {
169
+ const name = label.name?.trim() || label.key;
170
+ return {
171
+ key: replyStatusRuleKey(label.key),
172
+ label: `Reply classified "${name}"`,
173
+ description: `A reply in the inbox was classified as ${name}.`,
174
+ ledger: "email",
175
+ // New behaviour ships off. Classification is a model judgement, so turning one
176
+ // of these on is a deliberate act, never something a workspace wakes up to.
177
+ defaultEffect: "off",
178
+ defaultReason: "unsubscribe",
179
+ allowedEffects: ALL_EFFECTS,
180
+ group: "reply_classification",
181
+ };
182
+ }
183
+ const BUILTIN_BY_KEY = new Map(DNC_BUILTIN_RULES.map((rule) => [rule.key, rule]));
184
+ /** The builtin definition for a key, or null when the key is not a builtin. */
185
+ export function builtinDncRule(key) {
186
+ return BUILTIN_BY_KEY.get(key) ?? null;
187
+ }
188
+ export function isDncRuleEffect(value) {
189
+ return typeof value === "string" && DNC_RULE_EFFECTS.includes(value);
190
+ }
191
+ /**
192
+ * Resolve a stored rule key to its definition. A `reply_status:*` key resolves even
193
+ * when the org has since renamed or archived the label, so an override never
194
+ * becomes unreadable (and therefore unresettable) because a label moved.
195
+ */
196
+ export function resolveDncRuleDefinition(key, labels) {
197
+ const builtin = builtinDncRule(key);
198
+ if (builtin)
199
+ return builtin;
200
+ const labelKey = replyStatusLabelKey(key);
201
+ if (!labelKey)
202
+ return null;
203
+ const label = labels?.find((candidate) => candidate.key === labelKey);
204
+ return replyStatusRule(label ?? { key: labelKey });
205
+ }
206
+ /**
207
+ * The full catalog a surface renders: the six builtins, then one rule per inbox
208
+ * label the workspace can classify a reply as.
209
+ */
210
+ export function dncRuleCatalog(labels = []) {
211
+ const seen = new Set();
212
+ const replyRules = [];
213
+ for (const label of labels) {
214
+ const key = label.key?.trim();
215
+ if (!key || seen.has(key))
216
+ continue;
217
+ seen.add(key);
218
+ replyRules.push(replyStatusRule(label));
219
+ }
220
+ return [...DNC_BUILTIN_RULES, ...replyRules];
221
+ }
@@ -0,0 +1,103 @@
1
+ export declare const ENRICHMENT_INTENT_GROUPS: readonly ["person", "contact", "company", "decision_maker", "signal"];
2
+ export type EnrichmentIntentGroup = (typeof ENRICHMENT_INTENT_GROUPS)[number];
3
+ export declare const ENRICHMENT_INTENT_GROUP_LABELS: Record<EnrichmentIntentGroup, string>;
4
+ export type EnrichmentIntentKind = "profile" | "enrichment" | "verification" | "search" | "signal" | "formula" | "template";
5
+ /**
6
+ * default — a managed provider chain runs it today; the add path is exact.
7
+ * selectable — wired and reachable, but not offered as a one-click default.
8
+ * no_default — declared, but no managed default chain yet (an honest refusal
9
+ * with the reason and, where known, the candidate providers).
10
+ * coming_soon — founder-named for a later slice; projected with no add path.
11
+ * rejected — deliberately not offered; carries the decision id.
12
+ */
13
+ export type EnrichmentIntentStatus = "default" | "selectable" | "no_default" | "coming_soon" | "rejected";
14
+ export type EnrichmentIntentOutputField = {
15
+ key: string;
16
+ label: string;
17
+ /** `company.*` / `person.*` semantic type (packages/tenant-db/src/model.ts) or null. */
18
+ semanticType: string | null;
19
+ dataType: "text" | "numeric" | "boolean" | "jsonb" | "timestamptz";
20
+ /** Read from another field's payload at 0 credits; never fetched on its own. */
21
+ derived?: true;
22
+ };
23
+ export type EnrichmentIntentSurfaces = {
24
+ /** `columns add --capability <id>` / MCP column capability. */
25
+ capability?: string;
26
+ /** `columns add --preset <id>` / MCP preset. */
27
+ preset?: string;
28
+ /** `--preset-fields` subset of the company bundle this row materialises. */
29
+ presetFields?: readonly string[];
30
+ /** One-shot CLI verb, e.g. "find email". */
31
+ find?: string;
32
+ /** Managed Functions library id (apps/web/src/lib/managed-functions/catalog.ts). */
33
+ managedFunction?: string;
34
+ /** `columns catalog` template key. */
35
+ template?: string;
36
+ /** tenant-db ENRICHMENT_COLUMN_CATALOG entry id this row projects into. */
37
+ catalogEntry?: string;
38
+ registryFunction?: "enrichment" | "people_search" | "company_search" | "signals";
39
+ /** Registry intent id whose chains materialise this row. */
40
+ registryIntent?: string;
41
+ /** For per-field company rows: the exact `field:<key>` chains of `enrich_company`. */
42
+ registryInputShapes?: readonly string[];
43
+ };
44
+ export type EnrichmentIntentTaxonomyEntry = {
45
+ /** Stable id: registry intent id, `enrich_company:<group>`, `people_search:<intent>`, `signals:<intent>`, or a slug. */
46
+ id: string;
47
+ /** Customer label: the DATA, never a vendor. */
48
+ label: string;
49
+ /** ONE founder-voice line. No vendor names, no cost-structure words. */
50
+ description: string;
51
+ entity: "person" | "company";
52
+ group: EnrichmentIntentGroup;
53
+ kind: EnrichmentIntentKind;
54
+ /** ORDER IS THE PRODUCT DECISION: unique, ascending; pickers sort by it. */
55
+ rank: number;
56
+ /** Customer phrasings that mean this row; lower-case; feeds discovery. */
57
+ aliases: readonly string[];
58
+ /** Identity inputs the customer must hold, in customer words. */
59
+ inputShapes: readonly string[];
60
+ outputFields: readonly EnrichmentIntentOutputField[];
61
+ surfaces: EnrichmentIntentSurfaces;
62
+ status: EnrichmentIntentStatus;
63
+ /** Required for no_default | coming_soon | rejected; customer-readable. */
64
+ statusReason?: string;
65
+ /** Ledger id (docs/gtm-program/decisions.md); required for rejected rows. */
66
+ decision?: string;
67
+ /** Provider ids (metadata only) that document the data, for no_default / coming_soon rows. */
68
+ candidateProviders?: readonly string[];
69
+ };
70
+ export declare const ENRICHMENT_INTENT_TAXONOMY: readonly EnrichmentIntentTaxonomyEntry[];
71
+ /** True when a customer-facing string leaks vendor cost structure (OXYGEN_PRODUCT.md 2026-08-10). */
72
+ export declare function leaksCostStructure(text: string): boolean;
73
+ export declare function listEnrichmentIntents(filter?: {
74
+ group?: EnrichmentIntentGroup;
75
+ status?: EnrichmentIntentStatus | readonly EnrichmentIntentStatus[];
76
+ entity?: "person" | "company";
77
+ }): EnrichmentIntentTaxonomyEntry[];
78
+ export declare function getEnrichmentIntent(id: string): EnrichmentIntentTaxonomyEntry | null;
79
+ /**
80
+ * Best taxonomy row for a customer phrasing: the longest alias contained in the
81
+ * query wins, so "personal email" beats "email" and "decision makers at each
82
+ * account" beats "account". Rejected rows never match. Null when nothing does.
83
+ */
84
+ /**
85
+ * The pointer an older pricing surface carries back to the catalogue, so a
86
+ * customer who asks "what can I add and what does it cost" on `tools search
87
+ * --for-table` or `find company --list-fields` is handed the exact catalogue
88
+ * command instead of a ceiling. The 2026-09-19 blind acceptance run priced a
89
+ * whole pilot from those two surfaces and never reached `enrichment catalog`,
90
+ * although the skill it read named it: a new place to look is invisible until
91
+ * the place the question is asked points at it.
92
+ */
93
+ export type EnrichmentCatalogPointer = {
94
+ /** The single data type when the entry maps to exactly one row; null when it fans out to a group. */
95
+ intent: string | null;
96
+ group: EnrichmentIntentGroup;
97
+ exact_command: string;
98
+ };
99
+ /** Catalogue pointer for a column-catalogue entry id such as `preset:company_enrich` or `capability:work_email`. */
100
+ export declare function catalogPointerForEntry(entryId: string): EnrichmentCatalogPointer | null;
101
+ /** Catalogue pointer for one company enrichment field key such as `technologies` or `latest_funding_round`. */
102
+ export declare function catalogPointerForCompanyField(field: string): EnrichmentCatalogPointer | null;
103
+ export declare function findEnrichmentIntentByAlias(query: string): EnrichmentIntentTaxonomyEntry | null;