advisers 0.3.1 → 0.4.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 (48) hide show
  1. package/README-zh.md +13 -15
  2. package/README.md +32 -22
  3. package/THIRD-PARTY-NOTICES.md +1 -1
  4. package/bin/advisers.js +2769 -183
  5. package/index.js +1 -1
  6. package/lib/brief-archive.js +267 -0
  7. package/lib/client-pack.js +1016 -0
  8. package/lib/consent.js +390 -0
  9. package/lib/credentials.js +195 -0
  10. package/lib/customer-read.js +524 -0
  11. package/lib/error-codes.js +516 -7
  12. package/lib/evidence.js +928 -120
  13. package/lib/kb-extract.js +626 -0
  14. package/lib/kb-facts.js +429 -0
  15. package/lib/kb-pages.js +1084 -0
  16. package/lib/kb.js +1036 -0
  17. package/lib/ledger-read.js +109 -1
  18. package/lib/mail-errors.js +46 -0
  19. package/lib/mail-extract.js +351 -0
  20. package/lib/mail-imap.js +446 -0
  21. package/lib/mail-import.js +176 -0
  22. package/lib/mail-parse.js +223 -0
  23. package/lib/mail-store.js +731 -0
  24. package/lib/mail.js +506 -0
  25. package/lib/mcp-server.js +397 -11
  26. package/lib/notify.js +265 -7
  27. package/lib/policy/decision.js +315 -0
  28. package/lib/policy/egress.js +268 -0
  29. package/lib/policy/errors.js +71 -0
  30. package/lib/policy/index.js +99 -0
  31. package/lib/policy/rules.js +468 -0
  32. package/lib/policy/surfaces.js +141 -0
  33. package/lib/receipt-verify.js +283 -26
  34. package/lib/receivables.js +1653 -0
  35. package/lib/scheduler.js +453 -9
  36. package/lib/shell.js +1406 -0
  37. package/lib/source.js +98 -3
  38. package/lib/sqlite.js +501 -49
  39. package/lib/tos/index.js +2 -2
  40. package/lib/tos/manifest.json +6 -6
  41. package/lib/tos/privacy.zh-CN.md +33 -20
  42. package/lib/tos/safety.zh-CN.md +7 -6
  43. package/lib/tos/summary.zh-CN.md +3 -2
  44. package/lib/tos/terms.zh-CN.md +31 -16
  45. package/lib/tui/labels.js +1 -1
  46. package/lib/tui/render.js +1 -1
  47. package/lib/urgency.js +467 -0
  48. package/package.json +4 -4
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Egress registry (0.4 subset) + checkEgress(kind, meta).
3
+ *
4
+ * Why a registry: every place where data can leave the process (model, network,
5
+ * files, paths exported to a counterparty) must be discoverable from one list,
6
+ * so a new data surface cannot silently grow its own private gate. Each row
7
+ * records surface/action/dataClass/sink/entry/default/gate/tosRef plus the
8
+ * documentation clause that promises it.
9
+ *
10
+ * 0.4 registers the paths that exist at integration time (chat/capture/research/
11
+ * bridge model calls, IMAP sync, notify webhook, export packs) and the new
12
+ * mail.extract / kb.ask model paths landing in 0.4 (default off until consent
13
+ * exists). A static wiring gate (scripts/, lead-owned) can scan the model/net
14
+ * call sites and require each one to appear here; this module only owns the
15
+ * data + runtime check.
16
+ *
17
+ * lib/egress.js (matter secrecy guard) is intentionally untouched: it keeps its
18
+ * legacy exports/behaviour; this is an additive registry next to it.
19
+ */
20
+ import { policyError } from './errors.js'
21
+ import { evaluate } from './rules.js'
22
+ import { getSurface, normalizeSurface } from './surfaces.js'
23
+
24
+ /** Egress sink kinds: where data is going. */
25
+ export const EGRESS_SINKS = Object.freeze(['model', 'net', 'send', 'fs', 'export', 'spawn', 'local'])
26
+
27
+ const SINK_ALIASES = Object.freeze({
28
+ model: 'model',
29
+ 'model-egress': 'model',
30
+ chat: 'model',
31
+ llm: 'model',
32
+ net: 'net',
33
+ 'net-egress': 'net',
34
+ network: 'net',
35
+ webhook: 'net',
36
+ send: 'send',
37
+ mail: 'send',
38
+ fs: 'fs',
39
+ file: 'fs',
40
+ disk: 'fs',
41
+ export: 'export',
42
+ pack: 'export',
43
+ spawn: 'spawn',
44
+ exec: 'spawn',
45
+ local: 'local',
46
+ })
47
+
48
+ const RUNTIME_FACT_KEYS = Object.freeze([
49
+ 'facts', 'tos', 'consent', 'record', 'safety', 'trust', 'audit', 'path', 'clearance',
50
+ 'interactive', 'confirmed', 'dataClass', 'provider', 'baseUrl', 'actor', 'now',
51
+ ])
52
+
53
+ /**
54
+ * One row per registered egress path.
55
+ *
56
+ * default 'on' usable after the normal gates (TOS/key/config),
57
+ * 'off' requires an explicit local enablement (e.g. consent entry).
58
+ * gate matches the surface registry gate for the same surface.
59
+ */
60
+ export const EGRESS_REGISTRY = Object.freeze([
61
+ Object.freeze({ id: 'chat.model', surface: 'chat', action: 'model-egress', dataClass: 'conversation', sink: 'model', entry: 'lib/model.js#chatCompletion', default: 'on', gate: 'legacy-gate', tosRef: 'docs/TOS.md#9.3' }),
62
+ Object.freeze({ id: 'capture.model', surface: 'capture', action: 'model-egress', dataClass: 'conversation', sink: 'model', entry: 'lib/capture.js#captureCandidates', default: 'on', gate: 'legacy-gate', tosRef: 'docs/TOS.md#9.3' }),
63
+ Object.freeze({ id: 'research.model', surface: 'research', action: 'model-egress', dataClass: 'conversation', sink: 'model', entry: 'lib/research.js#research', default: 'on', gate: 'legacy-gate', tosRef: 'docs/TOS.md#9.3' }),
64
+ Object.freeze({ id: 'agent.model', surface: 'agent', action: 'model-egress', dataClass: 'conversation', sink: 'model', entry: 'lib/agent.js#runAgent', default: 'on', gate: 'legacy-gate', tosRef: 'docs/TOS.md#9.3' }),
65
+ Object.freeze({ id: 'bridge.model', surface: 'bridge', action: 'net-egress', dataClass: 'conversation', sink: 'net', entry: 'packages/bridge-hermes', default: 'off', gate: 'legacy-gate', tosRef: 'docs/TOS.md#9.3' }),
66
+ Object.freeze({ id: 'notify.webhook', surface: 'notify.webhook', action: 'net-egress', dataClass: 'reminder', sink: 'net', entry: 'lib/notify.js#sendWebhookNotification', default: 'off', gate: 'legacy-gate', tosRef: 'docs/TOS.md#9.3' }),
67
+ Object.freeze({ id: 'mail.sync', surface: 'mail.sync', action: 'net-egress', dataClass: 'mail', sink: 'net', entry: 'lib/mail.js#mailSync', default: 'on', gate: 'legacy-gate', tosRef: 'docs/TOS.md#9.3' }),
68
+ Object.freeze({ id: 'mail.extract.model', surface: 'mail.extract', action: 'model-egress', dataClass: 'mail', sink: 'model', entry: 'lib/mail-extract.js#extractCandidatesWithModel', default: 'off', gate: 'enforced-policy', tosRef: 'docs/TOS.md#9.3' }),
69
+ Object.freeze({ id: 'kb.ask.model', surface: 'kb.ask', action: 'model-egress', dataClass: 'kb', sink: 'model', entry: 'lib/kb.js (model ask planned 0.4.x; local kbSearch ships in 0.4)', default: 'off', gate: 'enforced-policy', tosRef: 'docs/TOS.md#9.3' }),
70
+ Object.freeze({ id: 'export.evidence-pack', surface: 'export', action: 'export', dataClass: 'ledger', sink: 'fs', entry: 'lib/evidence.js#buildEvidencePack', default: 'on', gate: 'enforced-policy', tosRef: 'docs/TOS.md#9.3' }),
71
+ Object.freeze({ id: 'export.receipt-pack', surface: 'export', action: 'export', dataClass: 'ledger', sink: 'fs', entry: 'lib/evidence.js#buildReceiptPack', default: 'on', gate: 'enforced-policy', tosRef: 'docs/TOS.md#9.3' }),
72
+ Object.freeze({ id: 'export.pet-brief', surface: 'pet-brief', action: 'export', dataClass: 'ledger', sink: 'fs', entry: 'lib/pet-brief.js#buildPetBrief', default: 'on', gate: 'legacy-gate', tosRef: 'docs/TOS.md#9.3' }),
73
+ Object.freeze({ id: 'kb.ingest.local', surface: 'kb.ingest', action: 'write-ledger', dataClass: 'kb', sink: 'fs', entry: 'lib/kb.js#kbAdd', default: 'on', gate: 'self-attested', tosRef: 'docs/TOS.md#9.3' }),
74
+ Object.freeze({ id: 'agent.exec', surface: 'agent', action: 'exec', dataClass: 'tool', sink: 'spawn', entry: 'lib/agent.js#executeTool', default: 'on', gate: 'legacy-gate', tosRef: 'docs/TOS.md#5' }),
75
+ ])
76
+
77
+ const ENTRY_BY_ID = new Map(EGRESS_REGISTRY.map((entry) => [entry.id, entry]))
78
+
79
+ /** Canonical egress sink kind or null. */
80
+ export function normalizeEgressKind(value) {
81
+ if (typeof value !== 'string') return null
82
+ const key = value.trim().toLowerCase()
83
+ return SINK_ALIASES[key] ?? null
84
+ }
85
+
86
+ /** Deterministic JSON-ready registry copy (for docs/contract tests). */
87
+ export function listEgress() {
88
+ return EGRESS_REGISTRY.map((entry) => ({
89
+ id: entry.id,
90
+ surface: entry.surface,
91
+ action: entry.action,
92
+ dataClass: entry.dataClass,
93
+ sink: entry.sink,
94
+ entry: entry.entry,
95
+ default: entry.default,
96
+ gate: entry.gate,
97
+ tosRef: entry.tosRef,
98
+ }))
99
+ }
100
+
101
+ /** Registry row by id. */
102
+ export function getEgressEntry(id) {
103
+ return typeof id === 'string' ? ENTRY_BY_ID.get(id) ?? null : null
104
+ }
105
+
106
+ function matchEntries(kind, meta) {
107
+ const sink = normalizeEgressKind(kind)
108
+ if (!sink) return { sink: null, entries: [] }
109
+ if (typeof meta?.id === 'string' && meta.id) {
110
+ const entry = ENTRY_BY_ID.get(meta.id)
111
+ return { sink, entries: entry && entry.sink === sink ? [entry] : [] }
112
+ }
113
+ let entries = EGRESS_REGISTRY.filter((entry) => entry.sink === sink)
114
+ const surface = normalizeSurface(meta?.surface)
115
+ if (surface) entries = entries.filter((entry) => entry.surface === surface)
116
+ const action = typeof meta?.action === 'string' ? meta.action.trim() : ''
117
+ if (action) entries = entries.filter((entry) => entry.action === action)
118
+ const dataClass = typeof meta?.dataClass === 'string' ? meta.dataClass.trim() : ''
119
+ if (dataClass) entries = entries.filter((entry) => entry.dataClass === dataClass)
120
+ return { sink, entries }
121
+ }
122
+
123
+ /**
124
+ * Static registry lookup: the registered egress row for a sink + selector.
125
+ * Returns null for unknown/ambiguous paths (never guesses between rows).
126
+ *
127
+ * @param {string} kind sink ('model'|'net'|'send'|'fs'|'export'|'spawn'|'local')
128
+ * @param {{id?: string, surface?: string, action?: string, dataClass?: string}} [meta]
129
+ */
130
+ export function findEgressEntry(kind, meta = {}) {
131
+ const matched = matchEntries(kind, meta)
132
+ if (!matched.sink || matched.entries.length !== 1) return null
133
+ return matched.entries[0]
134
+ }
135
+
136
+ function registryOnlyResult(sink, entry) {
137
+ const surfaceRow = getSurface(entry.surface)
138
+ return {
139
+ v: 1,
140
+ kind: sink,
141
+ id: entry.id,
142
+ registered: true,
143
+ checked: false,
144
+ entry: listEgress().find((row) => row.id === entry.id),
145
+ gate: surfaceRow ? surfaceRow.gate : entry.gate,
146
+ default: entry.default,
147
+ decision: 'not_checked',
148
+ code: null,
149
+ policyCode: null,
150
+ ruleIds: [],
151
+ obligations: [],
152
+ reason: 'registry-only check: runtime facts (tos/audit/consent/record/safety) were not supplied; call evaluate() or pass them as meta to get a decision',
153
+ }
154
+ }
155
+
156
+ function hasRuntimeFacts(meta) {
157
+ if (!meta || typeof meta !== 'object') return false
158
+ return RUNTIME_FACT_KEYS.some((key) => Object.prototype.hasOwnProperty.call(meta, key))
159
+ }
160
+
161
+ function factsFromMeta(entry, meta) {
162
+ if (meta && typeof meta.facts === 'object' && meta.facts !== null) {
163
+ return {
164
+ ...meta.facts,
165
+ surface: meta.facts.surface ?? entry.surface,
166
+ action: meta.facts.action ?? entry.action,
167
+ dataClass: meta.facts.dataClass ?? entry.dataClass,
168
+ }
169
+ }
170
+ const facts = {}
171
+ for (const key of RUNTIME_FACT_KEYS) {
172
+ if (key === 'facts') continue
173
+ if (meta[key] !== undefined) facts[key] = meta[key]
174
+ }
175
+ facts.surface = typeof meta.surface === 'string' && meta.surface ? meta.surface : entry.surface
176
+ facts.action = typeof meta.action === 'string' && meta.action ? meta.action : entry.action
177
+ facts.dataClass = typeof meta.dataClass === 'string' && meta.dataClass ? meta.dataClass : entry.dataClass
178
+ if (meta.provider !== undefined) facts.provider = meta.provider
179
+ return facts
180
+ }
181
+
182
+ /**
183
+ * Check one egress path.
184
+ *
185
+ * 1. The sink must be known and the path registered (otherwise deny with
186
+ * E_POLICY_EGRESS_UNREGISTERED/E_POLICY_UNKNOWN_SURFACE).
187
+ * 2. When runtime facts are supplied (directly or as meta.facts), the call
188
+ * delegates to evaluate() and returns its decision with the registry row.
189
+ * 3. Without runtime facts it returns decision 'not_checked' (registry-only
190
+ * probe for docs gates/tests) instead of pretending to have checked.
191
+ *
192
+ * @param {string} kind egress sink
193
+ * @param {object} [meta] selector {id?, surface?, action?, dataClass?} + runtime facts
194
+ * @returns {object} JSON-ready {kind, registered, entry, decision, code,
195
+ * policyCode, ruleIds, obligations, reason, checked}
196
+ */
197
+ export function checkEgress(kind, meta = {}) {
198
+ if (meta !== undefined && meta !== null && (typeof meta !== 'object' || Array.isArray(meta))) {
199
+ throw new TypeError('checkEgress(kind, meta) requires a meta object')
200
+ }
201
+ const selector = meta || {}
202
+ const matched = matchEntries(kind, selector)
203
+ if (!matched.sink) {
204
+ const error = policyError('POLICY_EGRESS_UNREGISTERED', 'unknown egress sink kind')
205
+ return {
206
+ v: 1,
207
+ kind: null,
208
+ id: null,
209
+ registered: false,
210
+ checked: false,
211
+ entry: null,
212
+ decision: 'deny',
213
+ code: error.code,
214
+ policyCode: error.policyCode,
215
+ ruleIds: [],
216
+ obligations: [],
217
+ reason: 'unknown egress sink kind; register it before it can be used',
218
+ }
219
+ }
220
+ if (matched.entries.length === 0) {
221
+ const error = policyError('POLICY_EGRESS_UNREGISTERED', 'egress path is not registered')
222
+ return {
223
+ v: 1,
224
+ kind: matched.sink,
225
+ id: null,
226
+ registered: false,
227
+ checked: false,
228
+ entry: null,
229
+ decision: 'deny',
230
+ code: error.code,
231
+ policyCode: error.policyCode,
232
+ ruleIds: [],
233
+ obligations: [],
234
+ reason: 'egress path is not registered in the egress registry; new paths fail closed',
235
+ }
236
+ }
237
+ if (matched.entries.length > 1) {
238
+ return {
239
+ v: 1,
240
+ kind: matched.sink,
241
+ id: null,
242
+ registered: false,
243
+ checked: false,
244
+ entry: null,
245
+ candidates: matched.entries.map((entry) => entry.id).sort(),
246
+ decision: 'deny',
247
+ code: 'E_POLICY_EGRESS_UNREGISTERED',
248
+ policyCode: 'POLICY_EGRESS_UNREGISTERED',
249
+ ruleIds: [],
250
+ obligations: [],
251
+ reason: 'ambiguous egress path: pass meta.id (one of the candidates) to disambiguate',
252
+ }
253
+ }
254
+ const entry = matched.entries[0]
255
+ if (!hasRuntimeFacts(selector)) return registryOnlyResult(matched.sink, entry)
256
+ const facts = factsFromMeta(entry, selector)
257
+ const decision = evaluate(facts)
258
+ return {
259
+ ...decision,
260
+ kind: matched.sink,
261
+ id: entry.id,
262
+ registered: true,
263
+ checked: true,
264
+ entry: listEgress().find((row) => row.id === entry.id),
265
+ gate: getSurface(entry.surface) ? getSurface(entry.surface).gate : entry.gate,
266
+ default: entry.default,
267
+ }
268
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Policy error codes (0.4 subset): one place that maps an internal POLICY_*
3
+ * reason to the public E_* code carried by error envelopes and CLI stderr.
4
+ *
5
+ * 0.4 does not activate exit codes 4/5/6 (contracts/cli/errors-v1.schema.json is
6
+ * a closed schema); every code below keeps exit 1 except E_TOS_REQUIRED, which
7
+ * keeps its historical exit 3.
8
+ *
9
+ * Registration note for lead/integration: the new E_POLICY_* literals must be
10
+ * added to lib/error-codes.js (category 'policy', since '0.4.0') and regenerated
11
+ * with `node scripts/check-contracts.mjs --update`; this module only defines the
12
+ * runtime mapping so lib/ tests do not depend on bin/ wiring.
13
+ */
14
+
15
+ /** Public code + operational metadata for every internal policy reason. */
16
+ export const POLICY_CODES = Object.freeze({
17
+ POLICY_UNKNOWN_SURFACE: Object.freeze({ code: 'E_POLICY_UNKNOWN_SURFACE', exit: 1, category: 'policy', description: 'surface/action not registered; new paths fail closed' }),
18
+ POLICY_SURFACE_NOT_ENABLED: Object.freeze({ code: 'E_POLICY_SURFACE_NOT_ENABLED', exit: 1, category: 'policy', description: 'registered but not wired/enabled yet (matrix gate not-wired)' }),
19
+ POLICY_TOS_REQUIRED: Object.freeze({ code: 'E_TOS_REQUIRED', exit: 3, category: 'tos', description: 'current terms of service must be accepted' }),
20
+ POLICY_SECRECY_BLOCKED: Object.freeze({ code: 'E_SECRECY_BLOCKED', exit: 1, category: 'policy', description: 'record belongs to a protected matter; egress/export blocked for that item' }),
21
+ POLICY_CONSENT_REQUIRED: Object.freeze({ code: 'E_POLICY_CONSENT_REQUIRED', exit: 1, category: 'policy', description: 'model egress of mail/KB content requires an explicit consent record for surface+dataClass+provider' }),
22
+ POLICY_CONFIRMATION_UNAVAILABLE: Object.freeze({ code: 'E_POLICY_CONFIRMATION_UNAVAILABLE', exit: 1, category: 'policy', description: 'untrusted content would drive a side effect and no interactive confirmation channel is available' }),
23
+ POLICY_AUDIT_UNAVAILABLE: Object.freeze({ code: 'E_POLICY_AUDIT_UNAVAILABLE', exit: 1, category: 'policy', description: 'intent/result audit could not be written; the side effect is refused (fail closed)' }),
24
+ POLICY_PROTECTED_PATH: Object.freeze({ code: 'E_POLICY_PROTECTED_PATH', exit: 1, category: 'policy', description: 'target path is a protected or persistence location' }),
25
+ POLICY_WORKSPACE_ESCAPE: Object.freeze({ code: 'E_POLICY_WORKSPACE_ESCAPE', exit: 1, category: 'policy', description: 'target path escapes the workspace boundary' }),
26
+ POLICY_CONTENT_SAFETY_BLOCKED: Object.freeze({ code: 'E_CONTENT_SAFETY_BLOCKED', exit: 1, category: 'content', description: 'content safety classifier blocked the content' }),
27
+ POLICY_SAFETY_REQUIRED: Object.freeze({ code: 'E_POLICY_SAFETY_REQUIRED', exit: 1, category: 'policy', description: 'a content-safety verdict is required before this action but was not supplied' }),
28
+ POLICY_INVALID_FACTS: Object.freeze({ code: 'E_POLICY_INVALID_FACTS', exit: 1, category: 'policy', description: 'policy facts are malformed or incomplete; fail closed instead of guessing' }),
29
+ POLICY_EGRESS_UNREGISTERED: Object.freeze({ code: 'E_POLICY_EGRESS_UNREGISTERED', exit: 1, category: 'policy', description: 'egress sink/path is not registered in the egress registry' }),
30
+ POLICY_TOKEN_INVALID: Object.freeze({ code: 'E_POLICY_TOKEN_INVALID', exit: 1, category: 'policy', description: 'decision token is malformed or was tampered with' }),
31
+ POLICY_TOKEN_UNKNOWN: Object.freeze({ code: 'E_POLICY_TOKEN_UNKNOWN', exit: 1, category: 'policy', description: 'decision token was not issued by this process' }),
32
+ POLICY_TOKEN_EXPIRED: Object.freeze({ code: 'E_POLICY_TOKEN_EXPIRED', exit: 1, category: 'policy', description: 'decision token expired before the effect was executed' }),
33
+ POLICY_TOKEN_REPLAY: Object.freeze({ code: 'E_POLICY_TOKEN_REPLAY', exit: 1, category: 'policy', description: 'one-shot decision token was already consumed' }),
34
+ POLICY_TOKEN_EFFECT_MISMATCH: Object.freeze({ code: 'E_POLICY_TOKEN_EFFECT_MISMATCH', exit: 1, category: 'policy', description: 'effect does not match the effect digest the decision was issued for' }),
35
+ })
36
+
37
+ /** Internal reason -> public code lookup (unknown reasons fail closed). */
38
+ export function policyCodeFor(reason) {
39
+ const entry = POLICY_CODES[reason]
40
+ return entry ? entry.code : 'E_POLICY_INVALID_FACTS'
41
+ }
42
+
43
+ export function policyCodeExit(reason) {
44
+ const entry = POLICY_CODES[reason]
45
+ return entry ? entry.exit : 1
46
+ }
47
+
48
+ /** JSON-ready code registry (docs/contracts/check scripts and tests). */
49
+ export function policyCodeRegistry() {
50
+ return Object.keys(POLICY_CODES)
51
+ .sort()
52
+ .map((reason) => ({ reason, ...POLICY_CODES[reason] }))
53
+ }
54
+
55
+ /** A policy refusal with a stable public code; details are JSON-ready. */
56
+ export class PolicyError extends Error {
57
+ constructor(reason, message, details) {
58
+ const entry = POLICY_CODES[reason]
59
+ const code = entry ? entry.code : 'E_POLICY_INVALID_FACTS'
60
+ super(code + ': ' + (message || (entry ? entry.description : 'policy refused')))
61
+ this.name = 'PolicyError'
62
+ this.code = code
63
+ this.policyCode = reason
64
+ if (details && typeof details === 'object' && !Array.isArray(details)) this.details = { ...details }
65
+ }
66
+ }
67
+
68
+ /** Build a PolicyError for an internal policy reason. */
69
+ export function policyError(reason, message, details) {
70
+ return new PolicyError(reason, message, details)
71
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Policy 0.4 subset — public module API.
3
+ *
4
+ * bin/MCP wiring is lead-owned; this barrel is what the integration is expected
5
+ * to import:
6
+ *
7
+ * import { evaluate, authorize, runWithDecision, checkEgress,
8
+ * loadConsent, saveConsent, consentFacts } from '../lib/policy/index.js'
9
+ *
10
+ * - evaluate(facts) pure decision (allow|confirm|deny, E_* code, rules,
11
+ * obligations, effectDigest)
12
+ * - authorize(action,facts) decision + one-shot decision token + intent audit
13
+ * - runWithDecision(token, effect, fn) digest-checked execution + result audit
14
+ * - checkEgress(kind, meta) egress registry lookup + optional evaluate
15
+ * - loadConsent/saveConsent $ADVISERS_HOME/consent.json (0600, atomic)
16
+ *
17
+ * Exit-code contract: unchanged (0/1/3). Policy detail travels in
18
+ * error.details.{policyCode,decisionId,ruleIds,surface,action}; exit 4/5/6 and
19
+ * errors/exit v2 stay 0.5 work.
20
+ */
21
+
22
+ export {
23
+ POLICY_CODES,
24
+ PolicyError,
25
+ policyCodeExit,
26
+ policyCodeFor,
27
+ policyCodeRegistry,
28
+ policyError,
29
+ } from './errors.js'
30
+
31
+ export {
32
+ CLEARANCE_ACTIONS,
33
+ DATA_CLASSES,
34
+ EGRESS_ACTIONS,
35
+ PATH_ACTIONS,
36
+ POLICY_ACTIONS,
37
+ POLICY_VERSION,
38
+ RULESET_VERSION,
39
+ SAFETY_REQUIRED_ACTIONS,
40
+ SIDE_EFFECT_ACTIONS,
41
+ SURFACE_DEFAULTS,
42
+ SURFACE_GATES,
43
+ SURFACE_REGISTRY,
44
+ TOS_REQUIRED_ACTIONS,
45
+ getSurface,
46
+ normalizeSurface,
47
+ surfaceMatrix,
48
+ surfaceNotWired,
49
+ surfaceSupportsAction,
50
+ } from './surfaces.js'
51
+
52
+ export {
53
+ EFFECT_DIGEST_FIELDS,
54
+ POLICY_RULES,
55
+ canonicalFacts,
56
+ canonicalJson,
57
+ effectDigestOf,
58
+ evaluate,
59
+ } from './rules.js'
60
+
61
+ export {
62
+ DECISION_TOKEN_TTL_MS,
63
+ authorize,
64
+ clearDecisionTokens,
65
+ consumeDecision,
66
+ decisionTokenCount,
67
+ decisionView,
68
+ runWithDecision,
69
+ } from './decision.js'
70
+
71
+ export {
72
+ EGRESS_REGISTRY,
73
+ EGRESS_SINKS,
74
+ checkEgress,
75
+ findEgressEntry,
76
+ getEgressEntry,
77
+ listEgress,
78
+ normalizeEgressKind,
79
+ } from './egress.js'
80
+
81
+ export {
82
+ CONSENT_CHANNELS,
83
+ CONSENT_DIR_MODE,
84
+ CONSENT_FILE,
85
+ CONSENT_FILE_MODE,
86
+ CONSENT_VERSION,
87
+ consentFacts,
88
+ consentPath,
89
+ consentStatus,
90
+ defaultHome,
91
+ grantConsent,
92
+ listConsents,
93
+ loadConsent,
94
+ readConsent,
95
+ revokeConsent,
96
+ saveConsent,
97
+ validateConsentRecord,
98
+ writeConsent,
99
+ } from '../consent.js'