@coffre/ui 0.15.0 → 0.16.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 (139) hide show
  1. package/dist/audit-sentences.d.ts +56 -0
  2. package/dist/audit-sentences.js +886 -0
  3. package/dist/audit-sentences.js.map +1 -0
  4. package/dist/chunks/audit-sentence-C8NnAdjF.js +48 -0
  5. package/dist/chunks/audit-sentence-C8NnAdjF.js.map +1 -0
  6. package/dist/chunks/{connected-apps-CGUQlFMx.js → connected-apps-6sMSgQ9U.js} +5 -5
  7. package/dist/chunks/{connected-apps-CGUQlFMx.js.map → connected-apps-6sMSgQ9U.js.map} +1 -1
  8. package/dist/chunks/{delete-place-CswZ-meh.js → delete-place-T469tSN9.js} +5 -5
  9. package/dist/chunks/{delete-place-CswZ-meh.js.map → delete-place-T469tSN9.js.map} +1 -1
  10. package/dist/chunks/{directory-DrswWQLT.js → directory-B_gVf7UL.js} +18 -17
  11. package/dist/chunks/directory-B_gVf7UL.js.map +1 -0
  12. package/dist/chunks/{folders-A6sbR_PG.js → folders-CVYauIDz.js} +3 -3
  13. package/dist/chunks/{folders-A6sbR_PG.js.map → folders-CVYauIDz.js.map} +1 -1
  14. package/dist/chunks/{grants-C0cb2oii.js → grants-Dn_EW2XW.js} +8 -8
  15. package/dist/chunks/grants-Dn_EW2XW.js.map +1 -0
  16. package/dist/chunks/{multi-combobox-B3SEv1gq.js → multi-combobox-fbBRzi9z.js} +3 -3
  17. package/dist/chunks/{multi-combobox-B3SEv1gq.js.map → multi-combobox-fbBRzi9z.js.map} +1 -1
  18. package/dist/chunks/{offboarding-C1jbG_dk.js → offboarding-CXM464J_.js} +81 -80
  19. package/dist/chunks/offboarding-CXM464J_.js.map +1 -0
  20. package/dist/chunks/{page-CfhC9Hp1.js → page-Cb0ZjGda.js} +7 -12
  21. package/dist/chunks/page-Cb0ZjGda.js.map +1 -0
  22. package/dist/chunks/{personal-tokens-xC9wulhg.js → personal-tokens-CSHMlRHy.js} +7 -7
  23. package/dist/chunks/personal-tokens-CSHMlRHy.js.map +1 -0
  24. package/dist/chunks/{principal-CI17XK13.js → principal-BKJxbAtE.js} +2 -2
  25. package/dist/chunks/{principal-CI17XK13.js.map → principal-BKJxbAtE.js.map} +1 -1
  26. package/dist/chunks/{principal-page-CdSeftGD.js → principal-page-COPmTDVW.js} +132 -19
  27. package/dist/chunks/principal-page-COPmTDVW.js.map +1 -0
  28. package/dist/chunks/{project-page-CHxjBE97.js → project-page-g5_n46Nz.js} +3 -3
  29. package/dist/chunks/{project-page-CHxjBE97.js.map → project-page-g5_n46Nz.js.map} +1 -1
  30. package/dist/chunks/protected-DEWeOrmI.js +77 -0
  31. package/dist/chunks/protected-DEWeOrmI.js.map +1 -0
  32. package/dist/chunks/{queries-D1JuimTu.js → queries-D4_o-bz3.js} +22 -155
  33. package/dist/chunks/queries-D4_o-bz3.js.map +1 -0
  34. package/dist/chunks/{references-D5llUGQL.js → references-wTh_DT0M.js} +27 -23
  35. package/dist/chunks/references-wTh_DT0M.js.map +1 -0
  36. package/dist/chunks/{role-field-CoCv8wse.js → role-field-BiP09qfN.js} +5 -5
  37. package/dist/chunks/role-field-BiP09qfN.js.map +1 -0
  38. package/dist/chunks/{row-state-CYH7kZHl.js → row-state-CYhtmUkc.js} +3 -3
  39. package/dist/chunks/{row-state-CYH7kZHl.js.map → row-state-CYhtmUkc.js.map} +1 -1
  40. package/dist/chunks/{signin-errors-TlQmQe0t.js → signin-errors-BMnox7XD.js} +5 -19
  41. package/dist/chunks/signin-errors-BMnox7XD.js.map +1 -0
  42. package/dist/chunks/{theme-rF44Wbmm.js → theme-imSolE1q.js} +3 -3
  43. package/dist/chunks/{theme-rF44Wbmm.js.map → theme-imSolE1q.js.map} +1 -1
  44. package/dist/chunks/{ui-CGdORVzW.js → ui-Q_Eczt7m.js} +7 -3
  45. package/dist/chunks/{ui-CGdORVzW.js.map → ui-Q_Eczt7m.js.map} +1 -1
  46. package/dist/chunks/{use-action-BxrHTBZw.js → use-action-BfnN-De2.js} +3 -3
  47. package/dist/chunks/{use-action-BxrHTBZw.js.map → use-action-BfnN-De2.js.map} +1 -1
  48. package/dist/chunks/{use-change-BorW2R6C.js → use-change-Cc0X4sF3.js} +6 -4
  49. package/dist/chunks/use-change-Cc0X4sF3.js.map +1 -0
  50. package/dist/chunks/{use-roles-BZnJ9Cq0.js → use-roles-stcv2QFj.js} +13 -56
  51. package/dist/chunks/use-roles-stcv2QFj.js.map +1 -0
  52. package/dist/chunks/{use-shell-CPskgi1k.js → use-shell-DMhLa2sh.js} +3 -3
  53. package/dist/chunks/{use-shell-CPskgi1k.js.map → use-shell-DMhLa2sh.js.map} +1 -1
  54. package/dist/index.d.ts +23 -55
  55. package/dist/index.js +12 -31
  56. package/dist/index.js.map +1 -1
  57. package/dist/pages/account.js +12 -12
  58. package/dist/pages/account.js.map +1 -1
  59. package/dist/pages/approval.js +2 -2
  60. package/dist/pages/audit.js +173 -196
  61. package/dist/pages/audit.js.map +1 -1
  62. package/dist/pages/device-login.js +2 -2
  63. package/dist/pages/environment.js +445 -252
  64. package/dist/pages/environment.js.map +1 -1
  65. package/dist/pages/login.js +6 -15
  66. package/dist/pages/login.js.map +1 -1
  67. package/dist/pages/oauth-authorize.js +2 -2
  68. package/dist/pages/project-access.js +11 -11
  69. package/dist/pages/project-environments.js +359 -28
  70. package/dist/pages/project-environments.js.map +1 -1
  71. package/dist/pages/project-settings.js +8 -8
  72. package/dist/pages/project.js +3 -3
  73. package/dist/pages/projects.js +8 -8
  74. package/dist/pages/service-account.js +19 -16
  75. package/dist/pages/service-account.js.map +1 -1
  76. package/dist/pages/service-accounts.js +6 -7
  77. package/dist/pages/service-accounts.js.map +1 -1
  78. package/dist/pages/settings.d.ts +1 -6
  79. package/dist/pages/settings.js +155 -286
  80. package/dist/pages/settings.js.map +1 -1
  81. package/dist/pages/unregistered.js +2 -2
  82. package/dist/pages/user.js +7 -8
  83. package/dist/pages/user.js.map +1 -1
  84. package/dist/pages/users.js +6 -7
  85. package/dist/pages/users.js.map +1 -1
  86. package/package.json +8 -3
  87. package/src/components/actions-log.tsx +8 -61
  88. package/src/components/directory.tsx +10 -9
  89. package/src/components/grants.tsx +2 -2
  90. package/src/components/icons.tsx +0 -2
  91. package/src/components/offboarding.tsx +9 -16
  92. package/src/components/page.tsx +2 -3
  93. package/src/components/personal-tokens.tsx +5 -2
  94. package/src/components/principal-page.tsx +5 -4
  95. package/src/components/protected.tsx +39 -52
  96. package/src/components/references.tsx +18 -7
  97. package/src/components/role-editor.tsx +68 -99
  98. package/src/components/role-field.tsx +1 -1
  99. package/src/components/trusted-workloads.tsx +6 -5
  100. package/src/components/ui.tsx +5 -0
  101. package/src/lib/audit-proofs.ts +51 -0
  102. package/src/lib/audit-sentences.ts +490 -529
  103. package/src/lib/bindings.ts +6 -0
  104. package/src/lib/changes.ts +3 -1
  105. package/src/lib/coffre.ts +2 -2
  106. package/src/lib/queries.ts +19 -168
  107. package/src/lib/reveal.ts +32 -5
  108. package/src/lib/roles.ts +10 -36
  109. package/src/lib/row-reads.ts +2 -2
  110. package/src/lib/signin-errors.ts +5 -33
  111. package/src/options.ts +3 -19
  112. package/src/pages/account.tsx +1 -1
  113. package/src/pages/audit.tsx +151 -228
  114. package/src/pages/environment.tsx +373 -247
  115. package/src/pages/login.tsx +2 -4
  116. package/src/pages/project-environments.tsx +322 -20
  117. package/src/pages/service-accounts.tsx +1 -1
  118. package/src/pages/settings.tsx +49 -134
  119. package/src/pages/user.tsx +2 -2
  120. package/src/pages/users.tsx +1 -1
  121. package/src/parity.ts +11 -20
  122. package/src/styles/globals.css +107 -273
  123. package/dist/chunks/actions-log-DupYCEyV.js +0 -1134
  124. package/dist/chunks/actions-log-DupYCEyV.js.map +0 -1
  125. package/dist/chunks/directory-DrswWQLT.js.map +0 -1
  126. package/dist/chunks/environment-actions-8rL9Cw6X.js +0 -576
  127. package/dist/chunks/environment-actions-8rL9Cw6X.js.map +0 -1
  128. package/dist/chunks/grants-C0cb2oii.js.map +0 -1
  129. package/dist/chunks/offboarding-C1jbG_dk.js.map +0 -1
  130. package/dist/chunks/page-CfhC9Hp1.js.map +0 -1
  131. package/dist/chunks/personal-tokens-xC9wulhg.js.map +0 -1
  132. package/dist/chunks/principal-page-CdSeftGD.js.map +0 -1
  133. package/dist/chunks/queries-D1JuimTu.js.map +0 -1
  134. package/dist/chunks/references-D5llUGQL.js.map +0 -1
  135. package/dist/chunks/role-field-CoCv8wse.js.map +0 -1
  136. package/dist/chunks/signin-errors-TlQmQe0t.js.map +0 -1
  137. package/dist/chunks/use-change-BorW2R6C.js.map +0 -1
  138. package/dist/chunks/use-roles-BZnJ9Cq0.js.map +0 -1
  139. package/src/components/environment-actions.tsx +0 -508
@@ -7,11 +7,9 @@
7
7
  * A sentence is parts rather than a string, so the page can make the people
8
8
  * and places in it links. `plain` flattens it, for tests and titles.
9
9
  */
10
- import { runLabel, shownMember, type AuditEntryView } from '@coffre/client';
11
- import { INSTANCE_ROLES, isBuiltinRole, isInstanceRole, isScope, ROLES, scopeInWords, type Scope } from '@coffre/core/access';
12
-
13
- /** The run an entry was written for, said beside who did it: one rule for the pages and the CLI. */
14
- export { runLabel };
10
+ import { shownMember, type AuditEntryView } from '@coffre/client';
11
+ import { INSTANCE_ROLES, isBuiltinRole, isInstanceRole, isScope, normalDefinition, ROLES, scopeInWords, type Scope } from '@coffre/core/access';
12
+ import type { LogAction } from '@coffre/core/vault';
15
13
 
16
14
  /** What a sentence is made from: an entry of the log, as `GET /api/audit` gives it. */
17
15
  export type AuditEntry = Pick<
@@ -43,602 +41,494 @@ export type Part = string | { place: string } | { member: string };
43
41
 
44
42
  export type Sentence = { parts: Part[]; refused: boolean };
45
43
 
46
- /** What one template needs: the line's leading entry, its batch, and how it was decided. */
44
+ /** What one template needs: the line's leading entry, and its batch. */
47
45
  type Facts = {
48
46
  entry: AuditEntry;
49
47
  /** Every entry of the batch, the lead included, a read of several once per secret (`perSecret`). */
50
48
  batch: AuditEntry[];
51
49
  /** Secrets the batch was about. */
52
50
  count: number;
53
- refused: boolean;
54
51
  };
55
52
 
53
+ /** An allowed entry's sentence; a refused one has none (`refusal`). */
56
54
  type Template = {
57
55
  /** What they did: "revealed". */
58
56
  did: string | ((facts: Facts) => string);
59
- /** What they tried, after "tried to": "reveal". */
60
- tried: string | ((facts: Facts) => string);
61
57
  /** To what: "market/prod/API_KEY". */
62
58
  what: (facts: Facts) => Part[];
63
59
  /** Said only of what happened: ", now version 5". */
64
60
  then?: (facts: Facts) => Part[];
61
+ /** Asked, and nothing changed: said after it, ", unchanged", as `unchanged: true` in its detail is. */
62
+ unchanged?: (facts: Facts) => boolean;
65
63
  };
66
64
 
67
65
  // --- the pieces of a sentence ---------------------------------------------------
68
66
 
69
67
  const text = (value: unknown): string | null => (typeof value === 'string' && value !== '' ? value : null);
70
68
  const number = (value: unknown): number | null => (typeof value === 'number' ? value : null);
69
+ const list = (value: unknown): string[] => (Array.isArray(value) ? value.filter((item): item is string => text(item) !== null) : []);
71
70
 
72
- /** The entry's place, as deep as it goes. */
73
- function place({ project, environment, key }: AuditEntry): Part[] {
74
- const path = [project, environment, key].filter((part): part is string => part !== null);
75
- return path.length === 0 ? ['coffre'] : [{ place: path.join('/') }];
71
+ /** An object of the detail's, or an empty one for anything else. */
72
+ function record(value: unknown): Record<string, unknown> {
73
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
76
74
  }
77
75
 
78
- function environmentOf({ project, environment }: AuditEntry): Part[] {
79
- return place({ project, environment, key: null } as AuditEntry);
76
+ /** The entry's place, as deep as it goes. */
77
+ function place(entry: Pick<AuditEntry, 'project' | 'environment' | 'key'>): Part[] {
78
+ const path = [entry.project, entry.environment, entry.key].filter((part): part is string => part !== null);
79
+ return path.length === 0 ? ['coffre'] : [{ place: path.join('/') }];
80
80
  }
81
81
 
82
- /** The member an entry is about: its subject, or the principal a token entry names. */
83
- function subject(entry: AuditEntry): Part[] {
84
- if (entry.subject !== null) return [{ member: entry.subject }];
85
- const id = text(entry.metadata.principalId);
86
- if (id === null) return ['someone'];
87
- return [{ member: `${entry.metadata.principalType === 'service' ? 'token' : 'user'}:${id}` }];
82
+ function environmentOf(entry: AuditEntry): Part[] {
83
+ return place({ ...entry, key: null });
88
84
  }
89
85
 
90
- /** Whether a token entry is about a personal token, which acts as its person, rather than a service account's. */
91
- function personal(entry: AuditEntry): boolean {
92
- return entry.metadata.kind === 'personal';
86
+ /** A personal config's entry by the environment it is a config of, `market/dev`: its own slug is generated, and shown nowhere else. */
87
+ function asPersonal(entry: AuditEntry): [AuditEntry, Part[]] {
88
+ const of = text(entry.metadata.personal);
89
+ return of === null || entry.project === null ? [entry, []] : [{ ...entry, environment: of }, [', in their personal config']];
93
90
  }
94
91
 
95
- /** A personal token's label, as it was made: ` "cursor-agent"`. */
96
- function labelled(entry: AuditEntry): Part[] {
97
- const label = text(entry.metadata.label);
98
- return label === null ? [] : [` “${label}”`];
92
+ /** The member an entry is about: its subject, or the member or principal its detail names. */
93
+ function subject(entry: AuditEntry): Part[] {
94
+ const member = entry.subject ?? text(entry.metadata.member) ?? text(entry.metadata.principal);
95
+ return member === null ? ['someone'] : [{ member }];
99
96
  }
100
97
 
101
- /** Why the vault made someone an Owner itself, said after it. */
102
- function owned(entry: AuditEntry): Part[] {
103
- return entry.metadata.reason === 'owners' ? [': the deployment names them one'] : [];
98
+ /** An entry about its actor's own credential: the principal it names is who acted. */
99
+ function own(entry: AuditEntry): boolean {
100
+ const actor = who(entry);
101
+ return typeof actor !== 'string' && text(entry.metadata.principal) === actor.member;
104
102
  }
105
103
 
106
- /** An MCP client, by the name it connected under. */
104
+ /** An MCP client, by the host its metadata document is at; one registered by its own request names none in the entry. */
107
105
  function app(entry: AuditEntry): Part[] {
108
- return [text(entry.metadata.clientName) ?? 'an app'];
106
+ return [text(entry.metadata.host) ?? 'an MCP client'];
109
107
  }
110
108
 
111
109
  /** A tool's call: its name, and what it named. */
112
110
  function tool(entry: AuditEntry): Part[] {
113
- const names = Array.isArray(entry.metadata.names) ? entry.metadata.names.filter((name): name is string => typeof name === 'string') : [];
111
+ const names = list(entry.metadata.names);
114
112
  return [text(entry.metadata.tool) ?? 'a tool', ...(names.length === 0 ? [] : [` on ${names.join(', ')}`])];
115
113
  }
116
114
 
117
- /** The client a request came through, said after what it did: "via Claude". */
118
- function via(entry: AuditEntry): Part[] {
119
- const client = (entry.metadata.via as { clientName?: unknown } | undefined)?.clientName;
120
- return typeof client === 'string' ? [` via ${client}`] : [];
121
- }
122
-
123
- /** Why coffre itself ended a connection, said after it. */
115
+ /** Why the vault itself ended a connection, said after it. */
124
116
  const DISCONNECTED: Record<string, string> = {
125
117
  code_reused: ': its sign-in code was used twice',
126
118
  refresh_reused: ': a refresh token it had replaced was used again',
127
- revocation_endpoint: ', at its own request',
128
- superseded: ': a connection with more scopes replaced it',
129
119
  };
130
120
 
131
121
  function plural(count: number, one: string, many = `${one}s`): string {
132
122
  return `${count} ${count === 1 ? one : many}`;
133
123
  }
134
124
 
135
- /** A batch reads as its environment and a count; one entry as its secret. */
136
125
  /**
137
- * The secrets a read or write was about. A read through a reference is a
138
- * read of its source, "market/prod/DATABASE_URL through
139
- * billing/prod/DATABASE_URL"; a run that read some that way is a run of
140
- * the environment that holds them. A value a fork inherits is its parent's,
141
- * read in the fork: "market/prod/STRIPE_KEY in market/prod-eu".
126
+ * The secrets a read or write was about: one entry as its secret, a batch as
127
+ * its environment and a count. The vault logs a read where it was asked, so
128
+ * a read through a reference is the reference's, "billing/prod/DATABASE_URL
129
+ * through a reference"; its own part of the entry names the source by id
130
+ * alone (`through`), which the page cannot say as a path.
142
131
  */
143
132
  function secrets(facts: Facts): Part[] {
144
- const through = (entry: AuditEntry) => text((entry.metadata.via as { path?: unknown } | undefined)?.path);
145
- // The fork a value was inherited in, by path: in its parent's project, which holds the reference a read went through.
146
- const forkOf = (entry: AuditEntry) => {
147
- const slug = text((entry.metadata.through as { slug?: unknown } | undefined)?.slug);
148
- const project = through(entry)?.split('/')[0] ?? entry.project;
149
- return slug === null || project === null ? null : `${project}/${slug}`;
150
- };
151
- if (facts.batch.length === 1) {
152
- const [held, fork] = [through(facts.entry), forkOf(facts.entry)];
153
- return [...place(facts.entry), ...(held === null ? [] : [' through ', { place: held }]), ...(fork === null ? [] : [' in ', { place: fork }])];
154
- }
155
- const fork = facts.batch.map(forkOf).find((path) => path !== null);
156
- const own = facts.batch.find((entry) => through(entry) === null && forkOf(entry) === null);
157
- const held = facts.batch.map(through).filter((path): path is string => path !== null);
158
- const inherited = facts.batch.filter((entry) => forkOf(entry) !== null).length;
159
- const where = fork !== undefined && fork !== null
160
- ? [{ place: fork }]
161
- : own !== undefined ? environmentOf(own) : [{ place: held[0]!.split('/').slice(0, 2).join('/') }];
133
+ const [entry, mine] = asPersonal(facts.entry);
134
+ const referred = (entry: AuditEntry) => text(entry.metadata.through) !== null;
135
+ if (facts.batch.length === 1) return [...place(entry), ...(referred(entry) ? [' through a reference'] : []), ...mine];
136
+ const held = facts.batch.filter(referred).length;
162
137
  return [
163
- ...where,
164
- facts.refused ? ', ' : ': ',
138
+ ...environmentOf(entry),
139
+ ': ',
165
140
  plural(facts.count, 'secret'),
166
- ...(held.length === 0 ? [] : [`, ${held.length} through ${held.length === 1 ? 'a reference' : 'references'}`]),
167
- ...(inherited === 0 ? [] : [`, ${inherited} inherited`]),
141
+ ...(held === 0 ? [] : [`, ${held} through ${held === 1 ? 'a reference' : 'references'}`]),
142
+ ...mine,
168
143
  ];
169
144
  }
170
145
 
171
- /** "market/prod/OLD", or "OLD and STALE in market/prod" for an archive of several keys refused. */
172
- function archivedKeys(entry: AuditEntry): Part[] {
173
- const keys = Array.isArray(entry.metadata.keys) ? entry.metadata.keys.filter((key): key is string => text(key) !== null) : [];
174
- if (entry.key !== null || keys.length === 0) return place(entry);
175
- return [keys.length === 1 ? keys[0]! : `${keys.slice(0, -1).join(', ')} and ${keys.at(-1)!}`, ' in ', ...environmentOf(entry)];
146
+ /** "OLD in market/prod", "OLD and STALE in market/prod", or "5 keys in market/prod". */
147
+ function keysIn(entry: AuditEntry, keys: string[]): Part[] {
148
+ const [here, mine] = asPersonal(entry);
149
+ if (keys.length === 0) return [...environmentOf(here), ...mine];
150
+ const named = keys.length > 3 ? plural(keys.length, 'key') : keys.length === 1 ? keys[0]! : `${keys.slice(0, -1).join(', ')} and ${keys.at(-1)!}`;
151
+ return [named, ' in ', ...environmentOf(here), ...mine];
176
152
  }
177
153
 
178
- /** "SENTRY_DSN in market/dev", or "3 keys in market/dev" for a Dismiss all. */
179
- function missingKeys(facts: Facts): Part[] {
180
- const key = text(facts.entry.metadata.key);
181
- return [facts.batch.length === 1 && key !== null ? key : plural(facts.count, 'key'), ' in ', ...environmentOf(facts.entry)];
182
- }
154
+ /** A folder renamed onto its own name: nothing moved. */
155
+ const sameFolder = ({ entry }: Facts) => entry.metadata.folder === entry.metadata.to;
183
156
 
184
- /** "billing/prod/DATABASE_URL a reference to market/prod/DATABASE_URL", from either author's entry. */
185
- function referenceTo(entry: AuditEntry): Part[] {
186
- const holder = text(entry.metadata.subject);
187
- const key = text(entry.metadata.key);
188
- const source = text(entry.metadata.source) ?? text((entry.metadata.source as { path?: unknown } | undefined)?.path);
189
- return [
190
- ...(holder !== null ? [{ place: holder }] : key !== null ? place(entry) : environmentOf(entry)),
191
- ...(source === null ? [] : [' a reference to ', { place: source }]),
192
- ];
157
+ /** " to the folder stripe", or " out of its folder". */
158
+ function intoFolder(folder: unknown): Part[] {
159
+ return [text(folder) === null ? ' out of its folder' : ` to the folder ${text(folder)}`];
193
160
  }
194
161
 
195
- const READ_VERBS: Record<string, [did: string, tried: string]> = {
196
- reveal: ['revealed', 'reveal'],
197
- run: ['ran', 'run'],
198
- compare: ['compared', 'compare'],
199
- copy: ['copied', 'copy'],
162
+ const READ_VERBS: Record<string, string> = {
163
+ reveal: 'revealed',
164
+ run: 'ran',
165
+ compare: 'compared',
166
+ copy: 'copied',
200
167
  // The credential proxy's: a value injected into a request for its person, or one handed to their app.
201
- use: ['used', 'use'],
202
- expose: ['was given', 'be given'],
168
+ use: 'used',
169
+ expose: 'was given',
170
+ };
171
+
172
+ /**
173
+ * What a write did to one key, from its line of the entry (`keys`): made it
174
+ * a reference, restored a version, wrote a value (a new key's, or one over
175
+ * a reference's), set it aside for what a parent passes down or took it
176
+ * back, archived it or brought it back, or filed it in a folder.
177
+ */
178
+ type Written = 'reference' | 'restore' | 'add' | 'own' | 'mark' | 'change' | 'reset' | 'archive' | 'unarchive' | 'move';
179
+
180
+ function written({ metadata: line }: AuditEntry): Written {
181
+ if (text(line.refers) !== null) return 'reference';
182
+ if (number(line.restored) !== null) return 'restore';
183
+ // A nature marked in place: `was` the nature it had, `kept` the version whose value it is.
184
+ if (text(line.was) !== null && number(line.kept) !== null) return 'mark';
185
+ if (number(line.version) !== null) return line.made === true ? 'add' : text(line.source) !== null ? 'own' : 'change';
186
+ if (line.reset === true) return 'reset';
187
+ if (typeof line.archived === 'boolean') return line.archived ? 'archive' : 'unarchive';
188
+ return 'folder' in line ? 'move' : 'change';
189
+ }
190
+
191
+ const WRITTEN: Record<Written, string> = {
192
+ reference: 'made',
193
+ restore: 'restored',
194
+ add: 'added',
195
+ own: 'gave a value of its own to',
196
+ mark: 'marked',
197
+ change: 'changed',
198
+ reset: 'reset',
199
+ archive: 'archived',
200
+ unarchive: 'brought back',
201
+ move: 'moved',
203
202
  };
204
203
 
205
- function readVerb({ entry }: Facts): [string, string] {
206
- return READ_VERBS[text(entry.metadata.purpose) ?? 'reveal'] ?? READ_VERBS.reveal!;
204
+ /** Who sees a value written: said where it is not a secret's. */
205
+ function nature(entry: AuditEntry): Part[] {
206
+ return entry.metadata.nature === 'plain' ? [', as a plain value, no secret'] : entry.metadata.nature === 'sensitive' ? [', as a sensitive value, shown to nobody'] : [];
207
207
  }
208
208
 
209
- const placeTemplates = (kind: 'project' | 'environment'): Record<string, Template> => {
210
- // A personal config by what it is a config of, `market/dev`: its own slug is generated, and shown nowhere else.
211
- const of = (entry: AuditEntry): string | null => {
212
- const parent = text(entry.metadata.personal) ?? text(entry.metadata.with);
213
- return parent === null || entry.project === null ? null : `${entry.project}/${parent}`;
209
+ /** A project's or an environment's, as `place` names it: a personal config by what it is a config of. */
210
+ function placeWhat(kind: 'project' | 'environment') {
211
+ return ({ entry }: Facts): Part[] => {
212
+ if (kind === 'project') return ['project ', ...place({ ...entry, environment: null, key: null })];
213
+ const of = text(entry.metadata.personal);
214
+ if (of !== null && entry.project !== null) return ['a personal config of ', { place: `${entry.project}/${of}` }];
215
+ if (entry.metadata.personal === true) return [`a personal config, ${text(entry.metadata.path) ?? ''}`];
216
+ return ['environment ', ...environmentOf(entry)];
214
217
  };
215
- const what = (facts: Facts): Part[] => {
216
- const personal = kind === 'environment' ? of(facts.entry) : null;
217
- if (personal !== null) return ['a personal config of ', { place: personal }];
218
- if (kind === 'environment' && facts.entry.metadata.personal === true) return [`a personal config, ${text(facts.entry.metadata.path) ?? ''}`];
219
- return [`${kind} `, ...(kind === 'project' ? place({ ...facts.entry, environment: null, key: null }) : environmentOf(facts.entry))];
218
+ }
219
+
220
+ /** A re-slugging, said as one where the slug changed. */
221
+ function updated(kind: 'project' | 'environment'): Template {
222
+ const renamed = ({ metadata }: AuditEntry) => text(metadata.from) !== null && metadata.from !== metadata.slug;
223
+ return {
224
+ did: ({ entry }) => (renamed(entry) ? 'renamed' : 'changed'),
225
+ what: placeWhat(kind),
226
+ then: ({ entry }) => (renamed(entry) ? [`, was ${text(entry.metadata.from)}`] : []),
220
227
  };
228
+ }
229
+
230
+ /** Archived, restored or deleted: a deleted one is named by its tombstone from then on, `market~deleted-2026-10-05`, as every entry about it is. */
231
+ const plainly = (kind: 'project' | 'environment', did: string): Template => ({ did, what: placeWhat(kind) });
232
+
233
+ /** An environment made: a fork names the one it inherits from, a copy the one it copied. */
234
+ function created(kind: 'project' | 'environment'): Template {
221
235
  return {
222
- [`${kind}.create`]: {
223
- did: 'created',
224
- tried: 'create',
225
- what,
226
- // A fork names the environment it copied.
227
- then: ({ entry }) =>
228
- text(entry.metadata.inherits) !== null
229
- ? [`, inheriting from ${text(entry.metadata.inherits)}`]
230
- : text(entry.metadata.from) === null
231
- ? []
232
- : [`, a fork of ${text(entry.metadata.from)}`],
233
- },
234
- [`${kind}.update`]: { did: 'changed', tried: 'change', what },
235
- [`${kind}.archive`]: { did: 'archived', tried: 'archive', what },
236
- [`${kind}.restore`]: { did: 'restored', tried: 'restore', what },
237
- // Named by its tombstone from then on, `market~deleted-2026-10-05`, as every entry about it is.
238
- [`${kind}.delete`]: { did: 'deleted', tried: 'delete', what },
236
+ ...plainly(kind, 'created'),
237
+ then: ({ entry }) =>
238
+ text(entry.metadata.inherits) !== null
239
+ ? [`, inheriting from ${text(entry.metadata.inherits)}`]
240
+ : text(entry.metadata.from) === null ? [] : [`, a copy of ${text(entry.metadata.from)}`],
239
241
  };
242
+ }
243
+
244
+ /** A grant's lines (`changes`), the first said, the others counted. */
245
+ const changesOf = ({ metadata }: AuditEntry) => (Array.isArray(metadata.changes) ? metadata.changes.map(record) : []);
246
+
247
+ /**
248
+ * A grant's sentence, and a revocation's, from what changed: the action is the
249
+ * request's (a grant if it gives any role), and its lines only what changed, a
250
+ * role given (`role`) or taken (`role: null`), each at its own place, which the
251
+ * server names the entry for (`viewOf`).
252
+ */
253
+ const accessSentence: Template = {
254
+ did: ({ entry }) => {
255
+ const [first] = changesOf(entry);
256
+ return first === undefined ? 'set' : first.role === null ? 'took' : 'gave';
257
+ },
258
+ what: ({ entry }) => {
259
+ const [first] = changesOf(entry);
260
+ if (first === undefined) return ['the access of ', ...subject(entry), ' on ', ...environmentOf(entry)];
261
+ if (first.role !== null) return [...subject(entry), ` ${text(first.role) ?? 'a role'} on `, ...environmentOf(entry)];
262
+ const role = text(first.was);
263
+ return [...(role === null ? ['access to '] : [`${role} on `]), ...environmentOf(entry), ' from ', ...subject(entry)];
264
+ },
265
+ then: ({ entry }) => {
266
+ const [first] = changesOf(entry);
267
+ if (first === undefined) return [];
268
+ return [
269
+ ...(first.role === null ? [] : [
270
+ ...(text(first.was) === null ? [] : [`, was ${text(first.was)}`]),
271
+ ...(text(first.expiresAt) === null ? [] : [`, until ${text(first.expiresAt)!.slice(0, 10)}`]),
272
+ ]),
273
+ ...others(entry),
274
+ // Admitted with it, which 0.14.7 logged apart.
275
+ ...(entry.metadata.admitted === 'member.add' ? [', added to coffre with it'] : entry.metadata.admitted === 'member.restore' ? [', brought back with it'] : []),
276
+ ];
277
+ },
278
+ unchanged: ({ entry }) => changesOf(entry).length === 0,
279
+ };
280
+
281
+ /** The changes after a grant's first: "on 2 other places" where each gave or took what the first did; else "2 other changes". */
282
+ function others(entry: AuditEntry): Part[] {
283
+ const [first, ...rest] = changesOf(entry);
284
+ if (first === undefined || rest.length === 0) return [];
285
+ const same = rest.every((line) => (['role', 'was', 'expiresAt'] as const).every((field) => text(line[field]) === text(first[field])));
286
+ return [same ? `, and on ${plural(rest.length, 'other place')}` : `, and ${plural(rest.length, 'other change')}`];
287
+ }
288
+
289
+ /** Who a revoked credential was: a token, or a session or handle ended. */
290
+ const REVOKED: Record<string, string> = {
291
+ personal: 'revoked a personal token of',
292
+ service: 'revoked a bearer token of',
293
+ handle: 'ended a handle of',
294
+ cli: 'ended a CLI session of',
295
+ browser: 'ended a browser session of',
296
+ mcp: 'disconnected an MCP app of',
297
+ };
298
+
299
+ /** A CLI sign-in's label, as its CLI named it: `, “laptop”`. */
300
+ const labelled = ({ entry }: Facts): Part[] => (text(entry.metadata.label) === null ? [] : [`, “${text(entry.metadata.label)}”`]);
301
+
302
+ /** A trust binding's keys replaced, rather than a binding made. */
303
+ const rekeyed = ({ entry }: Facts) => entry.metadata.reason === 'keys_replaced';
304
+
305
+ /** The profiles whose tokens are CI runs'; every other binding trusts a workload. */
306
+ const CI_PROFILES = ['github', 'github-reusable', 'github-reusable-organization', 'gitlab'];
307
+
308
+ /** Whom a binding trusts, by its profile: CI runs, a platform's workloads, or a custom issuer's tokens. */
309
+ function trusted({ metadata }: AuditEntry): string {
310
+ const profile = text(metadata.profile) ?? 'custom';
311
+ if (CI_PROFILES.includes(profile)) return 'CI runs';
312
+ return profile === 'custom' ? `tokens from ${text(metadata.issuer) ?? 'an issuer'}` : `${profile} workloads`;
313
+ }
314
+
315
+ /** What a freeze is on: the whole instance, a service account's workloads, a binding's or a session. */
316
+ function frozen({ entry }: Facts): Part[] {
317
+ const target = text(entry.metadata.target);
318
+ if (target === null) return ['workloads'];
319
+ if (target === 'instance') return ['every workload'];
320
+ if (target.startsWith('token:')) return ['the workloads of ', { member: target }];
321
+ return [target.startsWith('binding:') ? 'the workloads of a trust binding of ' : 'a workload session of ', ...subject(entry)];
322
+ }
323
+
324
+ /** A write that wrote no key: asked of keys as they were already (a nature they had, archived already, filed where they are). The entry records none of what was asked. */
325
+ const empty = ({ metadata }: AuditEntry) => Array.isArray(metadata.keys) && metadata.keys.length === 0;
326
+
327
+ /** A write's sentence, and a loosening's: one key as what was done to it; a batch as what was done to every key, or as written. */
328
+ const writeSentence: Template = {
329
+ did: ({ entry, batch }) => {
330
+ if (empty(entry)) return 'wrote to';
331
+ const kinds = new Set(batch.map(written));
332
+ if (batch.length === 1 || (kinds.size === 1 && !kinds.has('reference') && !kinds.has('own'))) return WRITTEN[written(entry)];
333
+ return [...kinds].every((kind) => kind === 'add' || kind === 'change') ? 'wrote' : 'changed';
334
+ },
335
+ what: (facts) => (empty(facts.entry) ? keysIn(facts.entry, []) : [...secrets(facts), ...(facts.batch.length === 1 && written(facts.entry) === 'reference' ? [' a reference'] : [])]),
336
+ then: ({ entry, batch }) => {
337
+ if (empty(entry)) return [];
338
+ const kind = written(entry);
339
+ const folder = entry.metadata.folder;
340
+ // A folder said of the batch only where every key moved to it.
341
+ if (kind === 'move' && batch.every((other) => written(other) === 'move' && other.metadata.folder === folder)) return intoFolder(folder);
342
+ if (batch.length > 1) return [];
343
+ if (kind === 'restore') return [` to version ${number(entry.metadata.restored)}`, ...(entry.version === null ? [] : [`, now ${entry.version}`])];
344
+ if (kind === 'mark') return [` ${text(entry.metadata.nature) ?? ''}, from ${text(entry.metadata.was) ?? ''}, its value kept`];
345
+ return kind === 'add' || kind === 'change' || kind === 'own' ? [...((entry.version ?? 1) === 1 ? [] : [`, now version ${entry.version}`]), ...nature(entry)] : [];
346
+ },
347
+ unchanged: ({ entry }) => empty(entry),
240
348
  };
241
349
 
242
350
  // --- one template per action ----------------------------------------------------
243
351
 
244
- const TEMPLATES: Record<string, Template> = {
245
- 'secret.read': {
246
- did: (facts) => readVerb(facts)[0],
247
- tried: (facts) => readVerb(facts)[1],
248
- what: secrets,
249
- },
250
- 'secret.write': {
251
- // New secrets are added, others changed; a batch of both is written. One whose level changed is made that.
252
- did: ({ entry, batch }) => {
253
- if (batch.length === 1 && text(entry.metadata.was) !== null) return 'made';
254
- const firsts = batch.filter((entry) => entry.version === 1).length;
255
- return firsts === batch.length ? 'added' : firsts === 0 ? 'changed' : 'wrote';
256
- },
257
- tried: 'change',
258
- what: secrets,
259
- // Who sees the value, where it is not a secret's or it changed: a mark keeps the value, a write gives a new one.
260
- then: ({ entry, batch }) => {
261
- const version = batch.length > 1 || entry.version === null || entry.version === 1 ? [] : [`, now version ${entry.version}`];
262
- if (batch.length > 1) return version;
263
- const level = entry.metadata.sensitive === true ? 'sensitive' : entry.metadata.plain === true ? 'plain' : 'secret';
264
- if (text(entry.metadata.was) !== null) return [` ${level}`, ...(number(entry.metadata.kept) === null ? [' with a new value'] : []), ...version];
265
- return [...version, ...(level === 'plain' ? [', as a plain value, no secret'] : level === 'sensitive' ? [', as a sensitive value, shown to nobody'] : [])];
266
- },
267
- },
268
- // The credential proxy's record beside the vault's read, the vault's own since 0.14.5: which credential the keys went into, where, and by which road.
269
- // Like the read, it records the release: a `credential_ended` refusal of the same operation after it says the value was withheld,
270
- // as a 409 for a policy changed meanwhile withholds it too, logging nothing more.
271
- 'credential.use': {
272
- did: ({ entry }) => (entry.metadata.purpose === 'expose' ? 'was given the values of' : 'used the credential'),
273
- tried: ({ entry }) => (entry.metadata.purpose === 'expose' ? 'be given the values of' : 'use the credential'),
274
- what: ({ entry }) => [
275
- text(entry.metadata.credential) ?? '',
276
- ...(text(entry.metadata.host) === null ? [] : [` on ${text(entry.metadata.host)}`]),
277
- ...(entry.metadata.egress === true ? [", through the deployment's egress"] : []),
278
- ],
279
- },
280
- 'secret.restore': {
281
- did: 'restored',
282
- tried: 'restore',
283
- what: ({ entry }) => [...place(entry), ...(number(entry.metadata.from) === null ? [] : [` to version ${number(entry.metadata.from)}`])],
284
- then: ({ entry }) => (entry.version === null ? [] : [`, now ${entry.version}`]),
285
- },
286
- // A sensitive value made a secret in place, by an Owner of its project: its value kept, shown to its readers from then on.
287
- 'secret.loosen': {
288
- did: 'made',
289
- tried: 'make',
290
- what: ({ entry }) => place(entry),
291
- then: ({ entry }) => [
292
- ` ${text(entry.metadata.to) ?? 'secret'}, from ${text(entry.metadata.from) ?? 'sensitive'}, its value kept`,
293
- ...(entry.version === null ? [] : [`, now version ${entry.version}`]),
294
- ],
295
- },
352
+ const TEMPLATES: Record<LogAction, Template> = {
353
+ 'secret.read': { did: ({ entry }) => READ_VERBS[text(entry.metadata.purpose) ?? 'reveal'] ?? READ_VERBS.reveal!, what: secrets },
354
+ // One key as what was done to it; a batch as what was done to every key, or as written.
355
+ 'secret.write': writeSentence,
356
+ // A nature marked looser in place, by an Owner of the project: its own action, as 0.14.7 logged it.
357
+ 'secret.loosen': writeSentence,
296
358
  'secret.rename': {
297
359
  did: 'renamed',
298
- tried: 'rename',
299
- what: ({ entry }) => [...place(entry), ...(text(entry.metadata.nextKey) === null ? [] : [` to ${text(entry.metadata.nextKey)}`])],
300
- // In a fork, carried down from a rename in its parent.
301
- then: ({ entry }) => (text(entry.metadata.parent) === null ? [] : [`, as ${text(entry.metadata.parent)} did`]),
302
- },
303
- 'secret.archive': { did: 'archived', tried: 'archive', what: ({ entry }) => archivedKeys(entry) },
304
- // In a fork: its own value set aside, kept, for its parent's.
305
- 'secret.reset': {
306
- did: 'reset',
307
- tried: 'reset',
308
- what: ({ entry }) => place(entry),
309
- then: ({ entry }) => (text(entry.metadata.from) === null ? [] : [` to ${text(entry.metadata.from)}'s value`]),
360
+ what: ({ entry }) => {
361
+ const [here, mine] = asPersonal(entry);
362
+ return [...place({ ...here, key: text(entry.metadata.key) ?? entry.key }), ...(text(entry.metadata.to) === null ? [] : [` to ${text(entry.metadata.to)}`]), ...mine];
363
+ },
364
+ // Carried down to the forks that inherit it.
365
+ then: ({ entry }) => {
366
+ // Each line is a row renamed, moved aside or a dismissal moved or ended, by its environment's id: the first, the key's own.
367
+ const [own, ...rest] = changesOf(entry).map((line) => text(line.environment));
368
+ const forks = new Set(rest.filter((environment) => environment !== null && environment !== own)).size;
369
+ return forks === 0 ? [] : [`, and in ${plural(forks, 'fork')}`];
370
+ },
371
+ unchanged: ({ entry }) => text(entry.metadata.to) === text(entry.metadata.key),
310
372
  },
373
+ 'secret.refile': { did: 'moved', what: ({ entry }) => keysIn(entry, list(entry.metadata.keys)), then: ({ entry }) => intoFolder(entry.metadata.to), unchanged: sameFolder },
374
+ // The source, by id alone in the entry, is no path the page can say.
375
+ 'reference.break': { did: 'broke', what: ({ entry }) => ['the reference ', ...place(entry)] },
376
+ // What changed, by key: dismissed, brought back, both, or neither (asked as it was).
311
377
  'missing.dismiss': {
312
- did: 'dismissed',
313
- tried: 'dismiss',
314
- what: (facts) => missingKeys(facts),
315
- then: () => [' as not needed'],
316
- },
317
- 'missing.restore': { did: 'restored', tried: 'restore', what: (facts) => missingKeys(facts), then: () => [' to the missing keys'] },
318
- 'secret.reference': { did: 'made', tried: 'make', what: ({ entry }) => referenceTo(entry) },
319
- 'reference.create': { did: 'made', tried: 'make', what: ({ entry }) => referenceTo(entry) },
320
- 'reference.end': {
321
- did: ({ entry }) => (entry.metadata.reason === 'replaced' ? 'gave a value of its own to' : entry.metadata.reason === 'abandoned' ? 'abandoned' : 'broke'),
322
- tried: ({ entry }) => (entry.metadata.reason === 'replaced' ? 'replace' : entry.metadata.reason === 'abandoned' ? 'abandon' : 'break'),
378
+ did: ({ entry }) => (list(entry.metadata.dismissed).length > 0 ? 'dismissed' : list(entry.metadata.restored).length > 0 ? 'restored' : 'set which missing keys are dismissed in'),
323
379
  what: ({ entry }) => {
324
- const source = text((entry.metadata.source as { path?: unknown } | undefined)?.path);
325
- const holder = text(entry.metadata.subject);
326
- if (entry.metadata.reason === 'replaced') return [...(holder === null ? ['a reference'] : [{ place: holder }]), ...(source === null ? [] : [', no longer a reference to ', { place: source }])];
327
- return ['the reference ', ...(holder === null ? [] : [{ place: holder }]), ...(source === null ? [] : [' to ', { place: source }])];
380
+ const dismissed = list(entry.metadata.dismissed);
381
+ const restored = list(entry.metadata.restored);
382
+ if (dismissed.length === 0 && restored.length === 0) return keysIn(entry, []);
383
+ return keysIn(entry, dismissed.length > 0 ? dismissed : restored);
328
384
  },
329
- then: ({ entry }) => (entry.metadata.reason === 'abandoned' ? [', which its write never stored'] : []),
330
- },
331
- 'secret.unarchive': { did: 'brought back', tried: 'bring back', what: (facts) => place(facts.entry) },
332
- 'secret.move': { did: 'moved', tried: 'move', what: (facts) => place(facts.entry), then: ({ entry }) => intoFolder(entry) },
333
- ...placeTemplates('project'),
334
- 'project.move': {
335
- did: 'moved',
336
- tried: 'move',
337
- what: ({ entry }) => ['project ', ...place({ ...entry, environment: null, key: null })],
338
- then: ({ entry }) => intoFolder(entry),
339
- },
340
- ...placeTemplates('environment'),
341
- 'environment.fork': {
342
- did: 'forked',
343
- tried: 'fork',
344
- what: ({ entry }) => [...environmentOf(entry), ...(text(entry.metadata.slug) === null ? [] : [` into ${text(entry.metadata.slug)}`])],
345
- },
346
- 'access.grant': {
347
- did: 'gave',
348
- tried: 'give',
349
- what: ({ entry }) => [...subject(entry), ` ${text(entry.metadata.role) ?? 'a role'} on `, ...placeOnly(entry)],
350
- then: ({ entry }) => [
351
- ...(text(entry.metadata.previousRole) === null ? [] : [`, was ${text(entry.metadata.previousRole)}`]),
352
- ...(text(entry.metadata.expiresAt) === null ? [] : [`, until ${text(entry.metadata.expiresAt)!.slice(0, 10)}`]),
353
- ...(entry.metadata.reason === 'every-project' ? [', for a grant on every project'] : []),
354
- ],
355
- },
356
- 'access.revoke': {
357
- did: 'took',
358
- tried: 'take',
359
- what: ({ entry }) => [
360
- ...(text(entry.metadata.previousRole ?? entry.metadata.role) === null ? ['access to '] : [`${text(entry.metadata.previousRole ?? entry.metadata.role)} on `]),
361
- ...placeOnly(entry),
362
- ' from ',
363
- ...subject(entry),
364
- ],
365
- // The vault replacing a grant on every project of 0.4: by what, an instance role or project grants.
366
385
  then: ({ entry }) => {
367
- const by = entry.metadata.replacedBy as { role?: unknown } | undefined;
368
- if (by === undefined) return [];
369
- const role = typeof by.role === 'string' ? roleName(by.role) : null;
370
- return [role === null || role === 'Member' ? ', replaced by project grants' : `, replaced by the global role ${role}`];
386
+ const dismissed = list(entry.metadata.dismissed);
387
+ const restored = list(entry.metadata.restored);
388
+ if (dismissed.length === 0) return restored.length === 0 ? [] : [' to the missing keys'];
389
+ return [' as not needed', ...(restored.length === 0 ? [] : [`, and restored ${restored.length > 3 ? plural(restored.length, 'key') : restored.join(', ')} to the missing keys`])];
371
390
  },
372
- },
373
- 'member.add': {
374
- did: 'added',
375
- tried: 'add',
376
- what: ({ entry }) => [
377
- ...subject(entry),
378
- ...(entry.metadata.rootAdmin === true ? [' as a root admin'] : entry.metadata.owner === true ? [' as an owner'] : asRole(entry)),
379
- ],
380
- then: ({ entry }) => owned(entry),
381
- },
391
+ unchanged: ({ entry }) => list(entry.metadata.dismissed).length === 0 && list(entry.metadata.restored).length === 0,
392
+ },
393
+ 'project.create': created('project'),
394
+ 'project.update': updated('project'),
395
+ 'project.archive': plainly('project', 'archived'),
396
+ 'project.restore': plainly('project', 'restored'),
397
+ 'project.delete': plainly('project', 'deleted'),
398
+ 'project.move': { ...plainly('project', 'moved'), then: ({ entry }) => intoFolder(entry.metadata.to), unchanged: ({ entry }) => entry.metadata.from === entry.metadata.to },
399
+ // A folder renamed, or emptied: every project filed there.
400
+ 'folder.refile': {
401
+ did: ({ entry }) => (text(entry.metadata.to) === null ? 'emptied' : 'renamed'),
402
+ what: ({ entry }) => [text(entry.metadata.folder) === null ? 'a folder' : `the folder ${text(entry.metadata.folder)}`],
403
+ then: ({ entry }) => [...(text(entry.metadata.to) === null ? [] : [` to ${text(entry.metadata.to)}`]), `, ${plural(list(entry.metadata.projects).length, 'project')}`],
404
+ unchanged: sameFolder,
405
+ },
406
+ 'environment.create': created('environment'),
407
+ 'environment.update': updated('environment'),
408
+ 'environment.archive': plainly('environment', 'archived'),
409
+ 'environment.restore': plainly('environment', 'restored'),
410
+ 'environment.delete': plainly('environment', 'deleted'),
411
+ 'environment.protect': { did: 'protected', what: ({ entry }) => environmentOf(entry) },
412
+ 'environment.unprotect': { did: 'unprotected', what: ({ entry }) => environmentOf(entry) },
413
+ // An upstream credential a deployment names, frozen in one environment.
414
+ 'upstream.freeze': { did: 'froze the upstream credential', what: ({ entry }) => [`${text(entry.metadata.upstream) ?? ''} in `, ...environmentOf(entry)] },
415
+ 'upstream.thaw': { did: 'unfroze the upstream credential', what: ({ entry }) => [`${text(entry.metadata.upstream) ?? ''} in `, ...environmentOf(entry)] },
416
+ 'access.grant': accessSentence,
417
+ 'access.revoke': accessSentence,
418
+ 'member.add': { did: 'added', what: ({ entry }) => [...subject(entry), ...asRole(entry)] },
419
+ 'member.restore': { did: 'brought back', what: ({ entry }) => [...subject(entry), ...asRole(entry)] },
382
420
  'member.remove': {
383
421
  did: 'removed',
384
- tried: 'remove',
385
422
  what: (facts) => subject(facts.entry),
386
- then: ({ entry }) => (number(entry.metadata.revoked) === null ? [] : [`, who held ${plural(number(entry.metadata.revoked)!, 'grant')}`]),
387
- },
388
- 'member.restore': {
389
- did: 'brought back',
390
- tried: 'bring back',
391
- what: ({ entry }) => [...subject(entry), ...asRole(entry)],
392
- then: ({ entry }) => owned(entry),
423
+ then: ({ entry }) => (Array.isArray(entry.metadata.revoked) && entry.metadata.revoked.length > 0 ? [`, who held ${plural(entry.metadata.revoked.length, 'grant')}`] : []),
393
424
  },
394
425
  'member.role': {
395
426
  did: 'made',
396
- tried: 'make',
397
427
  what: ({ entry }) => [...subject(entry), ` ${article(roleName(text(entry.metadata.role) ?? 'member') ?? 'Member')}`, ...scoped(entry)],
398
- then: ({ entry }) => {
399
- const before = roleName(text(entry.metadata.previousRole) ?? '');
400
- return [
401
- ...(before === null ? [] : [`, was ${before}`]),
402
- ...(entry.metadata.reason === 'every-project' ? [', for their grants on every project'] : []),
403
- ...owned(entry),
404
- ];
405
- },
406
- },
407
- 'member.owner': {
408
- did: ({ entry }) => (entry.metadata.owner === false ? 'took owner from' : 'made'),
409
- tried: ({ entry }) => (entry.metadata.owner === false ? 'take owner from' : 'make'),
410
- what: ({ entry }) => [...subject(entry), ...(entry.metadata.owner === false ? [] : [' an owner'])],
411
428
  },
412
429
  // Where people set up service accounts themselves, which those who run the instance set.
413
430
  'settings.change': {
414
431
  did: 'set',
415
- tried: 'set',
416
432
  what: ({ entry }) => ['where people set up service accounts', ...setting(entry.metadata.serviceAccounts).map((words) => `: ${words}`)],
417
- then: ({ entry }) => {
418
- const previous = (entry.metadata.previous as { serviceAccounts?: unknown } | undefined)?.serviceAccounts;
419
- return setting(previous).map((words) => `, was ${words}`);
420
- },
433
+ then: ({ entry }) => setting(entry.metadata.was).map((words) => `, was ${words}`),
421
434
  },
422
- // The roles an Owner edits and which environments are protected (docs/design/roles.md), the vault's to change.
435
+ // The roles an Owner edits (docs/design/roles.md), the vault's to change.
423
436
  'policy.change': {
424
- did: ({ entry }) => POLICY_VERBS[policyOf(entry).verb][0],
425
- tried: ({ entry }) => POLICY_VERBS[policyOf(entry).verb][1],
437
+ did: ({ entry }) => policyOf(entry).verb,
426
438
  what: ({ entry }) => policyOf(entry).what,
427
439
  },
428
- // A binding trusts CI runs to sign in as a service; removing one is its tombstone.
440
+ // A binding trusts CI runs or a workload to sign in as a service; removing one is its tombstone. New keys uploaded replace the bindings that named the old.
429
441
  'token.bind': {
430
- did: 'trusted CI runs to sign in as',
431
- tried: 'trust CI runs to sign in as',
432
- what: (facts) => subject(facts.entry),
433
- then: ({ entry }) => [...inGitHubEnvironment(entry), ...reaching(entry)],
434
- },
435
- // The tokens and bindings 0.4 made, given their own scope when 0.5 first checked a credential: what their account held then.
436
- 'token.seal': {
437
- did: 'sealed',
438
- tried: 'seal',
439
- what: ({ entry }) => [`${sealedOf(entry)} of `, ...subject(entry)],
440
- then: ({ entry }) => reaching(entry, ', reaching nothing'),
441
- },
442
- 'token.unbind': {
443
- did: 'stopped trusting CI runs to sign in as',
444
- tried: 'stop trusting CI runs to sign in as',
445
- what: (facts) => subject(facts.entry),
446
- },
447
- // A service signed in through one of its bindings, by its platform's proof: a CI run's, or a workload's session bound
448
- // to its key. Its run is said beside who did it (`runLabel`).
449
- 'token.exchange': {
450
- did: 'signed in',
451
- tried: 'sign in',
452
- what: ({ entry }) => [entry.metadata.proof === 'aws' ? 'with its AWS identity' : `with an ID token from ${issuerName(entry)}`],
453
- then: ({ entry }) => (entry.metadata.kind === 'workload' ? [', for a session bound to its key'] : []),
454
- },
455
- 'vault.tampered': {
456
- did: 'found',
457
- tried: 'check',
458
- what: ({ entry }) => [
459
- ...(entry.subject === null ? ['an entry'] : [...subject(entry), "'s record"]),
460
- ` tampered with: ${TAMPERING[entry.reason ?? ''] ?? 'it fails its seal'}`,
461
- ],
462
- },
463
- // The vault's rotation to a new vault key, or the app's to a new app key, which names the key it moved from.
464
- 'key.rotate': {
465
- did: ({ entry }) => (entry.author === 'app' ? 'moved to its new app key' : 'rotated its key'),
466
- tried: ({ entry }) => (entry.author === 'app' ? 'move to its new app key' : 'rotate its key'),
467
- what: () => [],
468
- },
469
- // An MCP client a person connected, such as Claude: named as the consent page showed it.
470
- 'mcp.connect': { did: 'connected', tried: 'connect', what: ({ entry }) => app(entry) },
471
- // A tool an MCP client called, by its name, and the places it named.
472
- 'mcp.call': { did: 'used', tried: 'use', what: ({ entry }) => tool(entry), then: ({ entry }) => via(entry) },
473
- // A person's decision, on coffre's page, on a change an MCP client asked for; the change's own entries follow, via the client.
474
- 'mcp.approve': { did: 'approved', tried: 'approve', what: ({ entry }) => tool(entry), then: ({ entry }) => [` for ${text(entry.metadata.clientName) ?? 'an app'}`] },
475
- 'mcp.deny': { did: 'turned down', tried: 'turn down', what: ({ entry }) => tool(entry), then: ({ entry }) => [` for ${text(entry.metadata.clientName) ?? 'an app'}`] },
476
- 'mcp.view': { did: 'opened an approval', tried: 'open an approval', what: () => [] },
477
- // The app's prompt declined, which cancels the approval it would have opened.
478
- 'mcp.cancel': { did: 'cancelled', tried: 'cancel', what: ({ entry }) => tool(entry), then: ({ entry }) => via(entry) },
442
+ did: (facts) => (rekeyed(facts) ? 'replaced the keys of' : `trusted ${trusted(facts.entry)} to sign in as`),
443
+ what: (facts) => [...(rekeyed(facts) ? [`${plural(Array.isArray(facts.entry.metadata.bindings) ? facts.entry.metadata.bindings.length : 0, 'trust binding')} of `] : []), ...subject(facts.entry)],
444
+ then: (facts) => (rekeyed(facts) ? [] : [...inGitHubEnvironment(facts.entry), ...reaching(facts.entry)]),
445
+ },
446
+ // Its entry names the binding by id alone, not whom it trusted.
447
+ 'token.unbind': { did: 'removed a trust binding of', what: (facts) => subject(facts.entry) },
448
+ 'workload.freeze': { did: 'froze', what: frozen, then: ({ entry }) => (text(entry.metadata.reason) === null ? [] : [`: ${text(entry.metadata.reason)}`]) },
449
+ 'workload.unfreeze': { did: 'unfroze', what: frozen },
450
+ // An MCP client a person connected, such as Claude.
451
+ 'mcp.connect': { did: 'connected', what: ({ entry }) => app(entry) },
452
+ // A change an MCP client asked for, on its access token: it waits for the person's approval.
453
+ 'mcp.ask': { did: 'was asked by an MCP client for', what: ({ entry }) => tool(entry) },
454
+ // A person's decision, on coffre's page, on a change an MCP client asked for; the change's own entry follows, through the approval.
455
+ 'mcp.approve': { did: 'approved', what: ({ entry }) => tool(entry) },
456
+ 'mcp.deny': { did: 'turned down', what: ({ entry }) => tool(entry) },
479
457
  'mcp.disconnect': {
480
458
  did: 'disconnected',
481
- tried: 'disconnect',
482
- what: ({ entry }) => [...app(entry), ...(entry.metadata.principalId === undefined ? [] : [' of ', ...subject(entry)])],
459
+ // The vault's own, on a code or a token used twice, names whose it was.
460
+ what: ({ entry }) => [...app(entry), ...(entry.actorType === 'system' && text(entry.metadata.principal) !== null ? [' of ', ...subject(entry)] : [])],
483
461
  then: ({ entry }) => [DISCONNECTED[text(entry.metadata.reason) ?? ''] ?? ''],
484
462
  },
463
+ // What lapsed, removed by the vault itself: sessions, sign-in codes, apps never connected.
464
+ 'upkeep.expire': { did: 'removed what had lapsed', what: () => [] },
465
+ // The log's first entry: an instance upgraded from 0.14 names where 0.14's log, archived, ends.
466
+ 'vault.adopt': {
467
+ did: ({ entry }) => (entry.metadata.archive == null ? 'started the log' : 'took over the 0.14 database'),
468
+ what: () => [],
469
+ then: ({ entry }) => (number(record(entry.metadata.archive).seq) === null ? [] : [`, its log archived through entry ${number(record(entry.metadata.archive).seq)}`]),
470
+ },
485
471
 
486
472
  // Detail, hidden unless asked for.
487
473
  sign_in: {
488
474
  did: ({ entry }) => (entry.metadata.kind === 'cli' ? 'signed in to the CLI' : 'signed in'),
489
- tried: 'sign in',
490
475
  what: ({ entry }) => (text(entry.metadata.provider) === null ? [] : [`with ${text(entry.metadata.provider)}`]),
476
+ // Made an Owner by the vault, as the deployment names them one.
477
+ then: ({ entry }) => (entry.metadata.owner === 'made' ? [', made an Owner: the deployment names them one'] : entry.metadata.owner === 'restored' ? [', brought back as an Owner: the deployment names them one'] : []),
491
478
  },
492
- sign_out: { did: 'signed out', tried: 'sign out', what: () => [] },
493
- // A personal token is its person's own, and named by its label; a bearer token is a service account's.
479
+ sign_out: { did: 'signed out', what: () => [] },
480
+ // A personal token is its person's own, a handle a run's; a bearer token is a service account's.
494
481
  'token.create': {
495
- did: ({ entry }) => (entry.metadata.kind === 'handle' ? 'made a handle' : personal(entry) ? 'made a personal token' : 'issued a bearer token to'),
496
- tried: ({ entry }) => (entry.metadata.kind === 'handle' ? 'make a handle' : personal(entry) ? 'make a personal token' : 'issue a bearer token to'),
497
- what: ({ entry }) => (personal(entry) ? labelled(entry) : subject(entry)),
482
+ did: ({ entry }) => (entry.metadata.kind === 'handle' ? 'made a handle' : entry.metadata.kind === 'personal' ? 'made a personal token' : 'issued a bearer token to'),
483
+ what: ({ entry }) => (entry.metadata.kind === 'handle' || entry.metadata.kind === 'personal' ? [] : subject(entry)),
498
484
  then: ({ entry }) => reaching(entry),
499
485
  },
500
- 'token.revoke': {
501
- did: ({ entry }) => (personal(entry) ? 'revoked a personal token of' : 'revoked a bearer token of'),
502
- tried: ({ entry }) => (personal(entry) ? 'revoke a personal token of' : 'revoke a bearer token of'),
503
- what: (facts) => subject(facts.entry),
504
- },
505
- // A personal token refused a route only its person reaches: the route, as the API names it.
506
- 'token.use': {
507
- did: 'used a personal token for',
508
- tried: 'use a personal token for',
509
- what: ({ entry }) => [text(entry.metadata.route) ?? 'something'],
486
+ // One's own, as Connected apps ends it most often, is "of their own": the entry names no subject then, only its principal.
487
+ 'token.revoke': { did: ({ entry }) => REVOKED[text(entry.metadata.kind) ?? ''] ?? 'revoked a token of', what: ({ entry }) => (own(entry) ? ['their own'] : subject(entry)) },
488
+ 'device.start': { did: 'was asked for a CLI sign-in', what: () => [], then: labelled },
489
+ 'device.approve': { did: 'approved a CLI sign-in', what: () => [], then: labelled },
490
+ 'device.deny': { did: 'turned down a CLI sign-in', what: () => [], then: labelled },
491
+ // A CI run's ID token, or a workload's proof, exchanged for a session.
492
+ 'token.exchange': {
493
+ did: ({ entry }) => (entry.metadata.kind === 'workload' ? 'started a workload session' : 'signed in for a CI run'),
494
+ what: () => [],
510
495
  },
511
- 'device.approve': { did: 'approved a CLI sign-in', tried: 'approve a CLI sign-in', what: () => [] },
512
- 'device.deny': { did: 'turned down a CLI sign-in', tried: 'turn down a CLI sign-in', what: () => [] },
513
- 'mcp.read': { did: 'used', tried: 'use', what: ({ entry }) => tool(entry), then: ({ entry }) => via(entry) },
496
+ 'workload.renew': { did: 'renewed its workload session', what: () => [] },
497
+ // Anyone may register an MCP client: what it reaches is the person's to connect.
498
+ 'oauth.register': { did: 'registered an MCP client', what: () => [] },
514
499
  'mcp.token': {
515
500
  did: ({ entry }) => (entry.metadata.grant === 'refresh_token' ? 'refreshed the tokens of' : 'gave its first tokens to'),
516
- tried: 'give tokens to',
517
501
  what: ({ entry }) => app(entry),
518
502
  },
519
- 'account.link': {
520
- did: 'linked',
521
- tried: 'link',
522
- what: ({ entry }) => [`a ${text(entry.metadata.provider) ?? 'sign-in'} account`],
523
- },
524
- 'account.unlink': {
525
- did: 'unlinked',
526
- tried: 'unlink',
527
- what: ({ entry }) => [`a ${text(entry.metadata.provider) ?? 'sign-in'} account`],
528
- },
529
- 'key.wrap': { did: 'sealed the key of', tried: 'seal the key of', what: (facts) => versioned(facts.entry) },
530
- 'key.rewrap': { did: 'resealed the key of', tried: 'reseal the key of', what: (facts) => versioned(facts.entry) },
531
- 'key.intent': { did: 'asked KMS about', tried: 'ask KMS about', what: (facts) => secrets(facts) },
532
- 'key.check': {
533
- did: 'recorded the check value of',
534
- tried: 'check',
535
- what: ({ entry }) => [['the', text(entry.metadata.kekProvider) === 'local' ? null : text(entry.metadata.kekProvider), 'vault key', text(entry.metadata.kekId)].filter((word) => word !== null).join(' ')],
536
- },
537
- 'audit.heartbeat': { did: 'checked in', tried: 'check in', what: () => [] },
538
- // A step of the app key's rotation: the rows it signed again under the new key, the sessions it signed out, any it could not sign.
539
- 'key.reseal': {
540
- did: 'signed rows again under its new app key:',
541
- tried: 'sign rows again under its new app key',
542
- what: ({ entry }) => {
543
- const count = (name: string) => (typeof entry.metadata[name] === 'number' ? (entry.metadata[name] as number) : 0);
544
- const [unsigned, later] = [count('unsignedCount'), count('later')];
545
- return [`${count('resealed')}, and ${count('signedOut')} signed out${later === 0 ? '' : `; ${later} another listed key signed, for its own rotation`}${unsigned === 0 ? '' : `; ${unsigned} no key listed had signed, left as they were`}`];
546
- },
547
- },
548
- // The audit watch's (server plugins/audit-watch.ts): what it found, what cleared it, and an Owner's acceptance.
549
- 'audit.finding': {
550
- did: 'found the log changed',
551
- tried: 'find the log changed',
552
- what: ({ entry }) => [number(entry.metadata.seq) === null ? text(entry.metadata.reason) ?? 'where it walked' : `at entry ${number(entry.metadata.seq)}`],
553
- },
554
- 'audit.finding_cleared': { did: 'found the log whole again', tried: 'find the log whole again', what: () => [] },
555
- 'audit.reanchor': {
556
- did: 're-anchored the log',
557
- tried: 're-anchor the log',
558
- what: ({ entry }) => (number(entry.metadata.at) === null ? [] : [`at entry ${number(entry.metadata.at)}`]),
559
- },
560
- 'audit.loss_accepted': {
561
- did: 'accepted as lost',
562
- tried: 'accept as lost',
563
- what: ({ entry }) => [`entries ${number(entry.metadata.from) ?? '?'} to ${number(entry.metadata.to) ?? '?'}`],
564
- },
565
- 'audit.loss_unapplied': {
566
- did: 'could not apply the acceptance of',
567
- tried: 'apply the acceptance of',
568
- what: ({ entry }) => [`entries ${number(entry.metadata.from) ?? '?'} to ${number(entry.metadata.to) ?? '?'} as lost`],
569
- },
570
- 'audit.checkpoint': {
571
- did: 'signed the log',
572
- tried: 'sign the log',
573
- what: ({ entry }) => (number(entry.metadata.seq) === null ? [] : [`through entry ${number(entry.metadata.seq)}`]),
574
- },
575
-
576
- // Only ever refused: a read of a list, which is not logged when allowed.
577
- 'secret.list': { did: 'listed', tried: 'list', what: ({ entry }) => environmentOf(entry) },
578
- 'secret.history': { did: 'read the history of', tried: 'read the history of', what: (facts) => place(facts.entry) },
579
- 'secret.update': { did: 'changed', tried: 'change', what: (facts) => place(facts.entry) },
503
+ 'account.link': { did: 'linked', what: ({ entry }) => [`a ${text(entry.metadata.provider) ?? 'sign-in'} account`] },
504
+ 'account.unlink': { did: 'unlinked', what: ({ entry }) => [`a ${text(entry.metadata.provider) ?? 'sign-in'} account`] },
580
505
  };
581
506
 
582
- /** " to the folder stripe", or " out of its folder". */
583
- function intoFolder(entry: AuditEntry): Part[] {
584
- const folder = text(entry.metadata.to);
585
- return [folder === null ? ' out of its folder' : ` to the folder ${folder}`];
586
- }
587
-
588
507
  /** An instance role's name, from its slug; null for none it knows. */
589
508
  function roleName(role: string): string | null {
590
509
  return isInstanceRole(role) ? INSTANCE_ROLES[role].name : null;
591
510
  }
592
511
 
593
- /** What a policy change did, and what it did it to, as `did` and `tried` say it. */
594
- const POLICY_VERBS = {
595
- protect: ['protected', 'protect'],
596
- unprotect: ['unprotected', 'unprotect'],
597
- edit: ['edited', 'edit'],
598
- reset: ['reset', 'reset'],
599
- make: ['made', 'make'],
600
- delete: ['deleted', 'delete'],
601
- } as const;
602
-
603
512
  /**
604
- * A `policy.change` entry, from what it names: its `change`, an
605
- * environment's protection or a role's definition, and the role `before`
606
- * it. A built-in role's definition dropped is a reset; one an Owner made, a
607
- * deletion; one that was not there, made. A refusal the app wrote names the
608
- * role alone.
513
+ * A `policy.change` entry, from its role, its `definition` and the one it
514
+ * replaced (`was`): a built-in role put back as it ships is a reset; one
515
+ * an Owner made, gone, a deletion; one that was not there, made.
609
516
  *
610
- * protected market/prod edited the Developer role
611
- * made the Release manager role reset the Auditor instance role
517
+ * edited the Developer role made the Release manager role
518
+ * reset the Auditor instance role deleted the Release manager role
612
519
  */
613
- function policyOf(entry: AuditEntry): { verb: keyof typeof POLICY_VERBS; what: Part[] } {
614
- const change = record(entry.metadata.change);
615
- if (change.kind === 'protect') {
616
- const count = Array.isArray(change.environmentIds) ? change.environmentIds.length : 1;
617
- // A fork's, protected before its row is written, names its project alone.
618
- const what: Part[] = entry.environment !== null
619
- ? place({ ...entry, key: null })
620
- : entry.project === null
621
- ? [count === 1 ? 'an environment' : plural(count, 'environment')]
622
- : [count === 1 ? 'a new environment of ' : `${plural(count, 'environment')} of `, { place: entry.project }];
623
- return { verb: change.protected === false ? 'unprotect' : 'protect', what };
624
- }
625
- const instance = (change.kind ?? entry.metadata.kind) === 'instance-role';
626
- const id = text(change.role) ?? text(entry.metadata.role);
627
- const shipped = id !== null && (instance ? isInstanceRole(id) : isBuiltinRole(id));
628
- const definition = change.definition === null ? null : record(change.definition);
629
- const before = record(entry.metadata.before);
630
- const name = text(definition?.name) ?? text(record(before.definition).name)
631
- ?? (id === null ? null : shipped ? (instance ? INSTANCE_ROLES[id as keyof typeof INSTANCE_ROLES] : ROLES[id as keyof typeof ROLES]).name : id);
632
- // A reset or deletion: the vault's entry says so in its change, a refusal of the app's in its own metadata.
633
- const verb = change.definition === null || entry.metadata.definition === null || entry.reason === 'role_granted'
634
- ? (shipped ? 'reset' : 'delete')
635
- : before.definition === null ? 'make' : 'edit';
636
- return { verb, what: [name === null ? 'a role' : `the ${name} ${instance ? 'global role' : 'role'}`] };
637
- }
638
-
639
- /** An object of the metadata's, or an empty one for anything else. */
640
- function record(value: unknown): Record<string, unknown> {
641
- return typeof value === 'object' && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : {};
520
+ function policyOf(entry: AuditEntry): { verb: 'edited' | 'reset' | 'made' | 'deleted'; what: Part[] } {
521
+ const instance = entry.metadata.instance === true;
522
+ const id = text(entry.metadata.role);
523
+ const shipped = id === null ? null : instance ? (isInstanceRole(id) ? INSTANCE_ROLES[id] : null) : isBuiltinRole(id) ? ROLES[id] : null;
524
+ const definition = entry.metadata.definition === null ? null : record(entry.metadata.definition);
525
+ const name = text(definition?.name) ?? text(record(entry.metadata.was).name) ?? shipped?.name ?? id;
526
+ const verb = definition === null
527
+ ? 'deleted'
528
+ : shipped !== null && JSON.stringify(definition) === JSON.stringify(normalDefinition(shipped))
529
+ ? 'reset'
530
+ : entry.metadata.was === null ? 'made' : 'edited';
531
+ return { verb, what: [name === null ? 'a role' : `the ${name} ${instance ? 'instance role' : 'role'}`] };
642
532
  }
643
533
 
644
534
  function article(name: string): string {
@@ -647,8 +537,9 @@ function article(name: string): string {
647
537
 
648
538
  /** Whether an entry's scope narrows the role; its projects are ids, which a sentence cannot name. */
649
539
  function scoped(entry: AuditEntry): Part[] {
650
- const scope = entry.metadata.scope as { projects?: unknown; environments?: unknown } | undefined;
651
- return scope === undefined || (scope.projects === 'all' && scope.environments === 'all') ? [] : [', with a scope'];
540
+ // An unscoped member's is null, the vault's `standing`.
541
+ const scope = entry.metadata.scope as { projects?: unknown; environments?: unknown } | null | undefined;
542
+ return scope == null || (scope.projects === 'all' && scope.environments === 'all') ? [] : [', with a scope'];
652
543
  }
653
544
 
654
545
  /**
@@ -667,26 +558,12 @@ function reaching(entry: AuditEntry, none = ''): Part[] {
667
558
  return [`, reaching ${[...byRole].map(([role, count]) => `${role} on ${plural(count, 'place')}`).join(', ')}`];
668
559
  }
669
560
 
670
- /** The issuer an ID token came from, by its host: `token.actions.githubusercontent.com`. */
671
- function issuerName(entry: AuditEntry): string {
672
- const issuer = text(entry.metadata.issuer);
673
- if (issuer === null) return 'its platform';
674
- return URL.canParse(issuer) && new URL(issuer).host !== '' ? new URL(issuer).host : issuer;
675
- }
676
-
677
561
  /** The GitHub environment a binding takes its runs from, when it names one. */
678
562
  function inGitHubEnvironment(entry: AuditEntry): Part[] {
679
563
  const environment = text((entry.metadata.claims as Record<string, unknown> | undefined)?.environment);
680
564
  return environment === null || !String(entry.metadata.profile).startsWith('github') ? [] : [`, in GitHub environment ${environment}`];
681
565
  }
682
566
 
683
- /** The tokens and trust bindings a `token.seal` names, counted: `2 tokens and a trust binding`. */
684
- function sealedOf(entry: AuditEntry): string {
685
- const count = (key: string) => (Array.isArray(entry.metadata[key]) ? (entry.metadata[key] as unknown[]).length : 0);
686
- const parts = [[count('tokens'), 'token'], [count('bindings'), 'trust binding']] as const;
687
- return parts.filter(([n]) => n > 0).map(([n, one]) => plural(n, one)).join(' and ') || 'nothing';
688
- }
689
-
690
567
  /**
691
568
  * The setting of where people set up service accounts, in words: its
692
569
  * projects counted, as the log names them by id, its environments by name.
@@ -708,23 +585,82 @@ function asRole(entry: AuditEntry): Part[] {
708
585
  return role === null || role === 'Member' ? [] : [` as ${article(role)}`, ...scoped(entry)];
709
586
  }
710
587
 
711
- function placeOnly(entry: AuditEntry): Part[] {
712
- // A grant on every project names no project: its place is a path in its payload, `*` or `*/dev`.
713
- const everywhere = entry.project === null ? text(entry.metadata.place) : null;
714
- if (everywhere !== null) return [everywhere === '*' ? 'every project' : `${everywhere.slice('*/'.length)} in every project`];
715
- return place({ ...entry, key: null });
716
- }
588
+ /**
589
+ * A refused change in words, after "tried to": its kind alone. The vault
590
+ * logs a refusal once a minute per caller and action (D236), so one entry
591
+ * stands for every one refused them that minute, each asking its own key,
592
+ * kind or direction: none of those is the entry's to say.
593
+ */
594
+ const TRIED: Record<LogAction, string> = {
595
+ 'secret.read': 'read secrets',
596
+ 'secret.write': 'write secrets',
597
+ 'secret.loosen': 'make a sensitive value secret in place',
598
+ 'secret.rename': 'rename a key',
599
+ 'secret.refile': 'move keys between folders',
600
+ 'reference.break': 'break a reference',
601
+ 'missing.dismiss': 'change which missing keys are dismissed',
602
+ 'project.create': 'create a project',
603
+ 'project.update': 'change a project',
604
+ 'project.archive': 'archive a project',
605
+ 'project.restore': 'restore a project',
606
+ 'project.move': 'move a project between folders',
607
+ 'project.delete': 'delete a project',
608
+ 'folder.refile': 'change a folder',
609
+ 'environment.create': 'create an environment',
610
+ 'environment.update': 'change an environment',
611
+ 'environment.archive': 'archive an environment',
612
+ 'environment.restore': 'restore an environment',
613
+ 'environment.delete': 'delete an environment',
614
+ 'environment.protect': 'protect an environment',
615
+ 'environment.unprotect': 'unprotect an environment',
616
+ 'upstream.freeze': 'freeze an upstream credential',
617
+ 'upstream.thaw': 'unfreeze an upstream credential',
618
+ // Every membership asked is logged as an addition, a role change and a return too.
619
+ 'member.add': 'change a membership',
620
+ 'member.restore': 'change a membership',
621
+ 'member.role': "change a member's instance role",
622
+ 'member.remove': 'remove a member',
623
+ 'access.grant': 'change access',
624
+ 'access.revoke': 'take away access',
625
+ 'policy.change': 'change a role',
626
+ 'settings.change': 'change where people set up service accounts',
627
+ sign_in: 'sign in',
628
+ sign_out: 'sign out',
629
+ 'token.create': 'issue a credential',
630
+ 'token.revoke': 'end a credential',
631
+ 'account.link': 'link a sign-in account',
632
+ 'account.unlink': 'unlink a sign-in account',
633
+ 'device.start': 'start a CLI sign-in',
634
+ 'device.approve': 'approve a CLI sign-in',
635
+ 'device.deny': 'turn down a CLI sign-in',
636
+ 'token.exchange': 'start a session from a CI run or a workload',
637
+ 'workload.renew': 'renew a workload session',
638
+ 'token.bind': 'change a trust binding',
639
+ 'token.unbind': 'remove a trust binding',
640
+ 'workload.freeze': 'freeze workloads',
641
+ 'workload.unfreeze': 'unfreeze workloads',
642
+ 'mcp.connect': 'connect an MCP client',
643
+ 'mcp.token': 'get tokens for an MCP client',
644
+ 'mcp.disconnect': 'disconnect an MCP client',
645
+ 'oauth.register': 'register an MCP client',
646
+ 'mcp.ask': 'ask for a change through MCP',
647
+ 'mcp.approve': 'approve a change asked through MCP',
648
+ 'mcp.deny': 'turn down a change asked through MCP',
649
+ 'upkeep.expire': 'remove what had lapsed',
650
+ 'vault.adopt': 'take over the database',
651
+ };
717
652
 
718
- function versioned(entry: AuditEntry): Part[] {
719
- return [...place(entry), ...(entry.version === null ? [] : [`, version ${entry.version}`])];
653
+ /**
654
+ * A refused entry's sentence: what kind of change, where the entry's own
655
+ * rows put it (its project and environment, never a name the caller asked
656
+ * for), and why. "tried to rename a key at market/dev: no access".
657
+ */
658
+ function refusal(entry: AuditEntry): Part[] {
659
+ const kind = Object.hasOwn(TRIED, entry.action) ? TRIED[entry.action as LogAction] : entry.action;
660
+ const at = entry.project === null ? [] : [' at ', { place: [entry.project, entry.environment].filter((part) => part !== null).join('/') }];
661
+ return ['tried to ', kind, ...at, `: ${reasonInWords(entry.reason)}`];
720
662
  }
721
663
 
722
- const TAMPERING: Record<string, string> = {
723
- mac: "it does not carry the vault's seal",
724
- stale: 'an older copy was put back',
725
- forged_entry: 'the vault did not write it',
726
- };
727
-
728
664
  /** Why something was refused, in words. Codes from the vault and the app. */
729
665
  const REASONS: Record<string, string> = {
730
666
  no_grant: 'no grant',
@@ -794,8 +730,8 @@ export function reasonInWords(reason: string | null): string {
794
730
 
795
731
  // --- lines ----------------------------------------------------------------------
796
732
 
797
- /** In a batch of mixed actions, the one the line is named for: a write, not its reads. */
798
- const LEAD = ['secret.write', 'secret.read'];
733
+ /** In a batch of mixed actions, the one its line says first: a write, then its reads, then the rest. */
734
+ const LEAD = ['secret.write', 'secret.loosen', 'secret.read'];
799
735
 
800
736
  export function leadOf(batch: AuditEntry[]): AuditEntry {
801
737
  for (const action of LEAD) {
@@ -806,50 +742,60 @@ export function leadOf(batch: AuditEntry[]): AuditEntry {
806
742
  }
807
743
 
808
744
  /**
809
- * A read of several secrets, logged once for its place, as the entries it
810
- * would be about one secret each: its key and version, and what its own
811
- * part of the metadata says, such as the reference it went through. Any
812
- * other entry as it is.
745
+ * A read, logged once for every key it released, or a write, once for
746
+ * every key it wrote, as the entries it would be about one key each: its
747
+ * key and version, and its own part of the detail (`keys`: a read's
748
+ * `{ key, secret, version, through? }`, a write's line), such as the
749
+ * reference it went through. Any other entry as it is.
813
750
  */
814
751
  export function perSecret<T extends AuditEntry>(entry: T): T[] {
815
- const listed = entry.metadata.secrets;
816
- // One whose list was emptied or mangled, which verification would flag, still reads as itself.
817
- if (entry.secrets === null || entry.secrets.length === 0 || !Array.isArray(listed)) return [entry];
818
- return entry.secrets.map(({ key, version }, i) => {
752
+ const listed = entry.metadata.keys;
753
+ const released = entry.secrets ?? [{ key: entry.key, version: entry.version }];
754
+ // One whose list was emptied or mangled, which its proof would flag, still reads as itself.
755
+ if (!['secret.read', 'secret.write', 'secret.loosen'].includes(entry.action) || !Array.isArray(listed) || released.length === 0 || listed.length !== released.length) return [entry];
756
+ return released.map(({ key, version }, i) => {
819
757
  const own = listed[i];
820
758
  return {
821
759
  ...entry,
822
760
  key,
823
761
  version,
824
762
  secrets: null,
825
- metadata: { ...entry.metadata, secrets: undefined, ...(typeof own === 'object' && own !== null && !Array.isArray(own) ? own : {}) },
763
+ metadata: { ...entry.metadata, keys: undefined, ...(typeof own === 'object' && own !== null && !Array.isArray(own) ? own : {}) },
826
764
  };
827
765
  });
828
766
  }
829
767
 
830
- /** What a line says: one entry, or a batch that shares an operation. */
768
+ /**
769
+ * What a line says: one entry, or a batch that shares an operation. A batch
770
+ * of several actions says each, the lead's first ("revealed market/prod/API_KEY;
771
+ * approved show_secret_value"), and is refused only if each of them was.
772
+ */
831
773
  export function describe(batch: AuditEntry[]): Sentence {
832
- const entry = perSecret(leadOf(batch))[0]!;
833
- const same = batch.filter((other) => other.action === entry.action).flatMap(perSecret);
774
+ const actions = [...new Set([leadOf(batch).action, ...batch.map((entry) => entry.action)])];
775
+ const said = actions.map((action) => describeAction(batch.filter((entry) => entry.action === action)));
776
+ return { parts: said.flatMap((one, i) => (i === 0 ? one.parts : ['; ', ...one.parts])), refused: said.every((one) => one.refused) };
777
+ }
778
+
779
+ /** A batch of one action in words. */
780
+ function describeAction(batch: AuditEntry[]): Sentence {
781
+ const lead = perSecret(batch[0]!)[0]!;
782
+ const same = batch.flatMap(perSecret);
783
+ // A batch is what was done: its refusals are counted after it, never said or counted as done.
784
+ const allowed = same.filter((other) => other.decision !== 'deny');
834
785
  const denied = same.filter((other) => other.decision === 'deny');
835
- const refused = denied.length === same.length;
836
- const facts: Facts = {
837
- entry,
838
- batch: same,
839
- count: new Set(same.map((other) => `${other.project}/${other.environment}/${other.key}`)).size,
840
- refused,
841
- };
842
- const template = TEMPLATES[entry.action];
786
+ const refused = allowed.length === 0;
787
+ if (refused) return { parts: refusal(lead), refused };
788
+ const entry = allowed[0]!;
789
+ const facts: Facts = { entry, batch: allowed, count: new Set(allowed.map((other) => `${other.project}/${other.environment}/${other.key}`)).size };
790
+ const template = Object.hasOwn(TEMPLATES, entry.action) ? TEMPLATES[entry.action as LogAction] : undefined;
843
791
  if (template === undefined) return { parts: [entry.action, ' ', ...place(entry)], refused };
844
- const say = (verb: Template['did']) => (typeof verb === 'string' ? verb : verb(facts));
845
792
  const what = template.what(facts);
846
793
  const gap = what.length === 0 ? [] : [' '];
847
- if (refused) {
848
- const reason = reasonInWords((denied[0] ?? entry).reason);
849
- return { parts: ['tried to ', say(template.tried), ...gap, ...what, `: ${reason}`], refused };
850
- }
851
794
  const partly = denied.length === 0 ? [] : [`, ${denied.length} refused: ${reasonInWords(denied[0]!.reason)}`];
852
- return { parts: [say(template.did), ...gap, ...what, ...(template.then?.(facts) ?? []), ...partly], refused };
795
+ // A change that changed nothing, and one made through an MCP client's approval, say so.
796
+ const unchanged = entry.metadata.unchanged === true || template.unchanged?.(facts) === true ? [', unchanged'] : [];
797
+ const approved = text(entry.metadata.via) === null ? [] : [', approved through MCP'];
798
+ return { parts: [typeof template.did === 'string' ? template.did : template.did(facts), ...gap, ...what, ...(template.then?.(facts) ?? []), ...unchanged, ...approved, ...partly], refused };
853
799
  }
854
800
 
855
801
  /** Who acted, as a part: a member links to their page; coffre itself is text. */
@@ -900,3 +846,18 @@ export function plain(parts: Part[]): string {
900
846
  )
901
847
  .join('');
902
848
  }
849
+
850
+ /**
851
+ * The CI run an entry was written for, as its issuer stated it at the
852
+ * exchange: `acme/api run 7001 at 3f2a9c1`, a GitLab pipeline, or the
853
+ * token's subject. Null for an entry no trust binding's credential wrote.
854
+ */
855
+ export function runLabel(run: { claims: Record<string, string | number> } | null): string | null {
856
+ if (run === null) return null;
857
+ const { claims } = run;
858
+ const text = (name: string) => (typeof claims[name] === 'string' || typeof claims[name] === 'number' ? String(claims[name]) : null);
859
+ const at = text('sha') === null ? '' : ` at ${text('sha')!.slice(0, 7)}`;
860
+ if (text('repository') !== null && text('run_id') !== null) return `${text('repository')} run ${text('run_id')}${at}`;
861
+ if (text('project_path') !== null && text('pipeline_id') !== null) return `${text('project_path')} pipeline ${text('pipeline_id')}${at}`;
862
+ return text('sub') === null ? 'a CI run' : `CI run ${text('sub')}`;
863
+ }