@intentic/sandbox-contract 1.397.0 → 1.398.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentic/sandbox-contract",
3
- "version": "1.397.0",
3
+ "version": "1.398.0",
4
4
  "description": "oRPC wire contract for the intentic sandbox daemon, shared by the daemon and its browser client",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -373,10 +373,10 @@
373
373
  }
374
374
  },
375
375
  "dependencies": {
376
- "@intentic/base": "1.397.0",
377
- "@intentic/constants": "1.397.0",
378
- "@intentic/extension-manifest": "1.397.0",
379
- "@intentic/registry": "1.397.0",
376
+ "@intentic/base": "1.398.0",
377
+ "@intentic/constants": "1.398.0",
378
+ "@intentic/extension-manifest": "1.398.0",
379
+ "@intentic/registry": "1.398.0",
380
380
  "@orpc/contract": "1.16.1",
381
381
  "zod": "4.6.7"
382
382
  },
@@ -14,6 +14,15 @@ import {
14
14
  PrivacyShieldPolicySchema,
15
15
  PrivacyShieldStatusSchema,
16
16
  } from "../schemas/privacy.js";
17
+ import {
18
+ PRIVACY_LEAK_ID,
19
+ PRIVACY_PROPOSAL_ID,
20
+ PRIVACY_SCAN_CONVERSATIONS_MAX,
21
+ PrivacyHardeningMeasureSchema,
22
+ PrivacyHardeningSchema,
23
+ PrivacyLeakReportSchema,
24
+ PrivacyLeaksSchema,
25
+ } from "../schemas/privacy-leaks.js";
17
26
  import { OkSchema } from "../schemas/shared.js";
18
27
 
19
28
  // The privacy shield's policy, its log, and the datasets taught to it. The policy is stored off the workspace (an agent
@@ -120,6 +129,104 @@ export const privacyContract = {
120
129
  }),
121
130
  )
122
131
  .output(z.object({ added: z.number().int(), known: z.number().int() })),
132
+ // Leaks and hardening (schemas/privacy-leaks.ts). Reporting, scanning, measuring and proposing only ever lead to masking
133
+ // more, so the agent's CLI may do them; judging a leak, applying a proposal and dismissing one are the owner's.
134
+ leaks: procedure
135
+ .route({
136
+ method: "GET",
137
+ path: "/privacy/leaks",
138
+ summary: "Personal data that reached a provider unmasked, and the proposals to catch more like it",
139
+ description:
140
+ "Every reported or suspected leak with its outline, the field label before it, what the name lists say of its words and what finds it now without its exact copy in the vault; and the hardening proposals waiting for the owner. Values and the text around them only for a person who runs the shield, or an agent whose conversation runs on a trusted or local provider.",
141
+ })
142
+ // Values ride this read for a person, so it floors where the policy does rather than at a read's viewer.
143
+ .meta({ floor: "maintainer", agent: true, right: "privacy" })
144
+ .output(PrivacyLeaksSchema),
145
+ report: procedure
146
+ .route({
147
+ method: "POST",
148
+ path: "/privacy/leaks",
149
+ summary: "Report a value the shield should have masked",
150
+ description:
151
+ "Kept as a confirmed leak, and its exact value taught to the vault: masked wherever it appears from now on. Reporting only ever masks more, so the agent may do it.",
152
+ })
153
+ .meta({ agent: true, right: "privacy" })
154
+ .input(PrivacyLeakReportSchema)
155
+ .output(z.object({ id: z.string() })),
156
+ judge: procedure
157
+ .route({
158
+ method: "POST",
159
+ path: "/privacy/leaks/judge",
160
+ summary: "Confirm or dismiss a leak",
161
+ description:
162
+ "Confirming teaches its exact value to the vault, so it is masked from now on. Dismissing says it is no personal data: a value taught for it is forgotten, and a scan does not suggest it again.",
163
+ })
164
+ .meta({ floor: "maintainer", right: "privacy", control: "never", panel: false })
165
+ .input(z.object({ id: z.string().regex(PRIVACY_LEAK_ID), state: z.enum(["confirmed", "dismissed"]) }))
166
+ .output(OkSchema),
167
+ scan: procedure
168
+ .route({
169
+ method: "POST",
170
+ path: "/privacy/leaks/scan",
171
+ summary: "Look for leaks in recent conversations, on this machine",
172
+ description:
173
+ "Reads the most recent conversations here and suspects every value nothing masks that the local name model reads as a name, or that stands under a field labelled as personal data (PESEL, passport, e-mail…). Nothing leaves this machine and nothing is taught: the owner confirms or dismisses each.",
174
+ })
175
+ .meta({ agent: true, right: "privacy" })
176
+ .input(z.object({ conversations: z.number().int().min(1).max(PRIVACY_SCAN_CONVERSATIONS_MAX).optional() }))
177
+ .output(z.object({ conversations: z.number().int(), chars: z.number().int(), suspected: z.number().int() })),
178
+ tryHardening: procedure
179
+ .route({
180
+ method: "POST",
181
+ path: "/privacy/leaks/try",
182
+ summary: "Measure rules and name-list words before proposing them",
183
+ description:
184
+ "Adds them to the policy as saved and measures, on this machine: how many confirmed leaks they catch that nothing catches now, and what they would mask in recent conversations that nothing masks today, as outlines (values only for a reader who may read them). Nothing is saved.",
185
+ })
186
+ .meta({ agent: true, right: "privacy" })
187
+ .input(PrivacyHardeningSchema)
188
+ .output(PrivacyHardeningMeasureSchema),
189
+ propose: procedure
190
+ .route({
191
+ method: "POST",
192
+ path: "/privacy/proposals",
193
+ summary: "Propose rules and name-list words to the owner",
194
+ description:
195
+ "Measured as tryHardening measures them, and kept for the owner, who applies or dismisses it on the privacy page. A rule whose pattern cannot be saved is refused here.",
196
+ })
197
+ .meta({ agent: true, right: "privacy" })
198
+ .input(z.object({ title: z.string().min(1).max(80), why: z.string().max(2000).default(""), hardening: PrivacyHardeningSchema }))
199
+ .output(z.object({ id: z.string(), measured: PrivacyHardeningMeasureSchema })),
200
+ applyProposal: procedure
201
+ .route({
202
+ method: "POST",
203
+ path: "/privacy/proposals/apply",
204
+ summary: "Apply a hardening proposal to the policy",
205
+ description:
206
+ "Its rules are added and switched on, and its words go onto the owner's own list of the same title and kind, or a new one; a word named by its leak is read from that leak here.",
207
+ })
208
+ .meta({ floor: "maintainer", right: "privacy", control: "never", panel: false })
209
+ .input(z.object({ id: z.string().regex(PRIVACY_PROPOSAL_ID) }))
210
+ .output(OkSchema),
211
+ dismissProposal: procedure
212
+ .route({
213
+ method: "POST",
214
+ path: "/privacy/proposals/dismiss",
215
+ summary: "Dismiss a hardening proposal",
216
+ })
217
+ .meta({ floor: "maintainer", right: "privacy", control: "never", panel: false })
218
+ .input(z.object({ id: z.string().regex(PRIVACY_PROPOSAL_ID) }))
219
+ .output(OkSchema),
220
+ hardeningSession: procedure
221
+ .route({
222
+ method: "POST",
223
+ path: "/privacy/leaks/session",
224
+ summary: "Note the hardening session started from the page",
225
+ description: "So the page offers to open it rather than starting a second one while it is still on the board.",
226
+ })
227
+ .meta({ right: "privacy", panel: false })
228
+ .input(z.object({ conversationId: z.string().min(1).max(200) }))
229
+ .output(OkSchema),
123
230
  forget: procedure
124
231
  .route({
125
232
  method: "POST",
@@ -0,0 +1,212 @@
1
+ // LEAKS AND HARDENING: personal data that reached an untrusted provider as it was, and the work of making the shield
2
+ // catch values like it. A leak is reported by a person ("this should have been masked") or suspected by a scan run on
3
+ // this machine over recent conversations; a confirmed leak's exact value is taught to the vault at once, so it is masked
4
+ // from then on, whoever asks. What a leak teaches beyond itself (a pattern for the form its kind takes here, a list of
5
+ // the surnames this sandbox's data holds) is the hardening session's: an agent reads each leak as its outline, measures a
6
+ // candidate rule against the leaks and against recent text on this machine, and proposes it; the owner applies it.
7
+ //
8
+ // An agent on a provider nobody trusted never reads a leak's value or the text around it: the text around a value can
9
+ // hold other values nobody reported, and the value itself is exactly what the shield did not recognise, so it would
10
+ // leave a second time. It reads the outline, the field label before it and what the name lists say of each word, and
11
+ // names a word it wants on a list by the leak it comes from (PrivacyLeakWordSchema), which the daemon resolves when the
12
+ // owner applies the proposal.
13
+
14
+ import { z } from "zod";
15
+ import {
16
+ PersonalDataClassSchema,
17
+ PrivacyNameListKindSchema,
18
+ PrivacyNameMatchingSchema,
19
+ PRIVACY_PATTERN_MAX,
20
+ PRIVACY_RULE_TERMS_MAX,
21
+ PRIVACY_TERM_MAX,
22
+ PRIVACY_TITLE_MAX,
23
+ PRIVACY_WORD_MAX,
24
+ PrivacyRuleMatchSchema,
25
+ } from "./privacy.js";
26
+
27
+ export const PRIVACY_LEAKS_MAX = 500;
28
+ // How much text on each side of a leak is kept with it, for the owner and a trusted session to read it where it stood.
29
+ export const PRIVACY_LEAK_CONTEXT_REACH = 200;
30
+ export const PRIVACY_LEAK_VALUE_MAX = 500;
31
+ export const PRIVACY_PROPOSALS_MAX = 20;
32
+ // The most recent conversations a scan reads, and the default.
33
+ export const PRIVACY_SCAN_CONVERSATIONS_MAX = 100;
34
+ export const PRIVACY_SCAN_CONVERSATIONS_DEFAULT = 20;
35
+
36
+ // A leak's id as the daemon mints it: `L` and a number, never reused.
37
+ export const PRIVACY_LEAK_ID = /^L[1-9]\d{0,6}$/u;
38
+ export const PRIVACY_PROPOSAL_ID = /^P[1-9]\d{0,6}$/u;
39
+
40
+ // reported: a person (or an agent) said it should have been masked. scan: the local scan found it unmasked where the
41
+ // name model reads a name, or under a field whose label says what it holds.
42
+ export const PrivacyLeakOriginSchema = z.enum(["reported", "scan"]);
43
+ export type PrivacyLeakOrigin = z.infer<typeof PrivacyLeakOriginSchema>;
44
+
45
+ // suspected: a scan's find nobody has judged yet; nothing is taught. confirmed: personal data, taught to the vault.
46
+ // dismissed: not personal data; kept so the next scan does not suggest it again.
47
+ export const PrivacyLeakStateSchema = z.enum(["suspected", "confirmed", "dismissed"]);
48
+ export type PrivacyLeakState = z.infer<typeof PrivacyLeakStateSchema>;
49
+
50
+ // One leak as the daemon keeps it, off the workspace beside the vault: the value as it was written, and the text around it.
51
+ export const PrivacyLeakSchema = z.object({
52
+ id: z.string().regex(PRIVACY_LEAK_ID),
53
+ at: z.string().describe("When it was reported or found, as an ISO timestamp."),
54
+ class: PersonalDataClassSchema,
55
+ value: z.string().min(2).max(PRIVACY_LEAK_VALUE_MAX),
56
+ context: z
57
+ .string()
58
+ .max(PRIVACY_LEAK_CONTEXT_REACH * 2 + PRIVACY_LEAK_VALUE_MAX)
59
+ .default("")
60
+ .describe("The text around the value as it was written, the value in it; empty when it was reported alone."),
61
+ conversationId: z.string().max(200).optional(),
62
+ origin: PrivacyLeakOriginSchema,
63
+ state: PrivacyLeakStateSchema,
64
+ why: z.string().max(200).optional().describe("Why a scan suspects it: the field label it stood under, or the name model."),
65
+ });
66
+ export type PrivacyLeak = z.infer<typeof PrivacyLeakSchema>;
67
+
68
+ // What the name lists say of one word of a leak, for a session that may not read the word.
69
+ export const PrivacyLeakWordFactsSchema = z.object({
70
+ outline: z.string().describe("The word with each capital as A, small letter as a, digit as 9; anything else as it is."),
71
+ firstName: z.boolean(),
72
+ surname: z.boolean(),
73
+ surnameForm: z.boolean().describe("Shaped like a Polish surname (-ski, -cki, -wicz…)."),
74
+ ambiguous: z.boolean().describe("Also an ordinary word in some language."),
75
+ never: z.boolean(),
76
+ });
77
+ export type PrivacyLeakWordFacts = z.infer<typeof PrivacyLeakWordFactsSchema>;
78
+
79
+ // What finds a leak now, without the vault's exact copy of it: the question hardening answers.
80
+ export const PrivacyLeakCaughtSchema = z.enum(["rule", "detector", "model", "no"]);
81
+ export type PrivacyLeakCaught = z.infer<typeof PrivacyLeakCaughtSchema>;
82
+
83
+ // A leak as a reader is shown it: always its outline, the label before it and what the lists say of its words; its value
84
+ // and the text around it only for someone who may read them (`revealed` on the view).
85
+ export const PrivacyLeakViewSchema = z.object({
86
+ id: z.string(),
87
+ at: z.string(),
88
+ class: PersonalDataClassSchema,
89
+ origin: PrivacyLeakOriginSchema,
90
+ state: PrivacyLeakStateSchema,
91
+ why: z.string().optional(),
92
+ conversationId: z.string().optional(),
93
+ outline: z.string().describe("The value with each capital as A, small letter as a, digit as 9; separators as they are."),
94
+ length: z.number().int(),
95
+ label: z
96
+ .string()
97
+ .optional()
98
+ .describe("Up to four words just before the value on its line or in the cell before it (a field's label: `Nr paszportu`), each word that could be a name or holds a digit written as its outline."),
99
+ words: z.array(PrivacyLeakWordFactsSchema).describe("Each word of the value, in order: what a list proposal names by its position."),
100
+ caught: PrivacyLeakCaughtSchema.describe("What finds it now with the policy as saved, its exact copy in the vault set aside."),
101
+ value: z.string().optional().describe("Only for someone who may read it."),
102
+ context: z.string().optional().describe("Only for someone who may read it."),
103
+ });
104
+ export type PrivacyLeakView = z.infer<typeof PrivacyLeakViewSchema>;
105
+
106
+ // One word of a leak's value, by its position (0 is the first): how a session that never read the value puts it on a list.
107
+ export const PrivacyLeakWordSchema = z.object({
108
+ leak: z.string().regex(PRIVACY_LEAK_ID),
109
+ word: z.number().int().min(0).max(20),
110
+ });
111
+ export type PrivacyLeakWord = z.infer<typeof PrivacyLeakWordSchema>;
112
+
113
+ // A rule a session proposes: the owner's rule without its id and switch, which applying mints and turns on.
114
+ export const PrivacyProposedRuleSchema = z.object({
115
+ title: z.string().min(1).max(PRIVACY_TITLE_MAX),
116
+ class: PersonalDataClassSchema,
117
+ match: PrivacyRuleMatchSchema,
118
+ terms: z.array(z.string().min(1).max(PRIVACY_TERM_MAX)).max(PRIVACY_RULE_TERMS_MAX).default([]),
119
+ pattern: z.string().max(PRIVACY_PATTERN_MAX).default(""),
120
+ matchCase: z.boolean().default(false),
121
+ });
122
+ export type PrivacyProposedRule = z.infer<typeof PrivacyProposedRuleSchema>;
123
+
124
+ // Words for a name list a session proposes: written out, or named by the leak they come from. Applied onto the owner's
125
+ // own list of the same title and kind when there is one, else as a new list.
126
+ export const PrivacyProposedListSchema = z.object({
127
+ title: z.string().min(1).max(PRIVACY_TITLE_MAX),
128
+ kind: PrivacyNameListKindSchema,
129
+ matching: PrivacyNameMatchingSchema.default("inflected"),
130
+ words: z.array(z.string().min(1).max(PRIVACY_WORD_MAX)).max(500).default([]),
131
+ fromLeaks: z.array(PrivacyLeakWordSchema).max(500).default([]),
132
+ });
133
+ export type PrivacyProposedList = z.infer<typeof PrivacyProposedListSchema>;
134
+
135
+ // What a session measures and proposes: rules and name-list words added to the policy as saved.
136
+ export const PrivacyHardeningSchema = z.object({
137
+ rules: z.array(PrivacyProposedRuleSchema).max(20).default([]),
138
+ lists: z.array(PrivacyProposedListSchema).max(10).default([]),
139
+ });
140
+ export type PrivacyHardening = z.infer<typeof PrivacyHardeningSchema>;
141
+
142
+ // One value the additions would mask in recent text that nothing masks today: a false positive to look at, or one more leak.
143
+ export const PrivacyHardeningSampleSchema = z.object({
144
+ class: PersonalDataClassSchema,
145
+ outline: z.string(),
146
+ label: z.string().optional(),
147
+ value: z.string().optional().describe("Only for someone who may read it."),
148
+ });
149
+ export type PrivacyHardeningSample = z.infer<typeof PrivacyHardeningSampleSchema>;
150
+
151
+ // What the additions do, measured on this machine: against the confirmed leaks, and against recent conversations.
152
+ export const PrivacyHardeningMeasureSchema = z.object({
153
+ leaks: z.object({
154
+ total: z.number().int().describe("Confirmed leaks measured against."),
155
+ before: z.number().int().describe("Caught by the policy as saved, without the vault's exact copies."),
156
+ after: z.number().int().describe("Caught with the additions."),
157
+ missed: z.array(z.string()).describe("Ids of the confirmed leaks still not caught."),
158
+ }),
159
+ control: z.object({
160
+ conversations: z.number().int(),
161
+ chars: z.number().int(),
162
+ added: z.number().int().describe("Values the additions would mask there that nothing masks today, the leaks themselves left out."),
163
+ samples: z.array(PrivacyHardeningSampleSchema).max(12),
164
+ }),
165
+ problems: z.array(z.string()).describe("Rules that cannot be saved as written, each with why."),
166
+ });
167
+ export type PrivacyHardeningMeasure = z.infer<typeof PrivacyHardeningMeasureSchema>;
168
+
169
+ // A session's proposal, waiting for the owner: what to add, why, and what it measured when proposed.
170
+ export const PrivacyProposalSchema = z.object({
171
+ id: z.string().regex(PRIVACY_PROPOSAL_ID),
172
+ at: z.string(),
173
+ conversationId: z.string().max(200).optional(),
174
+ title: z.string().min(1).max(PRIVACY_TITLE_MAX),
175
+ why: z.string().max(2000).default(""),
176
+ hardening: PrivacyHardeningSchema,
177
+ measured: PrivacyHardeningMeasureSchema,
178
+ });
179
+ export type PrivacyProposal = z.infer<typeof PrivacyProposalSchema>;
180
+
181
+ // The leaks, the proposals and the session working on them, as one reader is shown them.
182
+ export const PrivacyLeaksSchema = z.object({
183
+ leaks: z.array(PrivacyLeakViewSchema),
184
+ proposals: z.array(PrivacyProposalSchema),
185
+ // The proposals' leak words as the reader may read them, by `L3:1`; empty for one who may not.
186
+ words: z.record(z.string(), z.string()),
187
+ revealed: z.boolean().describe("Whether this reader is shown values: a person who runs the shield, or a session on a trusted or local provider."),
188
+ session: z
189
+ .object({ conversationId: z.string(), at: z.string() })
190
+ .optional()
191
+ .describe("The hardening session last started from the page."),
192
+ });
193
+ export type PrivacyLeaks = z.infer<typeof PrivacyLeaksSchema>;
194
+
195
+ export const PrivacyLeakReportSchema = z.object({
196
+ value: z.string().trim().min(2).max(PRIVACY_LEAK_VALUE_MAX),
197
+ class: PersonalDataClassSchema,
198
+ context: z.string().max(20_000).optional().describe("The text it stood in; the daemon keeps the stretch around the value."),
199
+ conversationId: z.string().max(200).optional(),
200
+ });
201
+ export type PrivacyLeakReport = z.infer<typeof PrivacyLeakReportSchema>;
202
+
203
+ // The vault source a confirmed leak's exact value is taught under: one per leak, so dismissing one forgets that value
204
+ // alone. The privacy page lists these with the leaks, not with the datasets.
205
+ export const PRIVACY_LEAK_SOURCE_PREFIX = "leak:";
206
+ export const leakSource = (id: string): string => `${PRIVACY_LEAK_SOURCE_PREFIX}${id}`;
207
+
208
+ // How a leak's words are named in `PrivacyLeaks.words`.
209
+ export const leakWordKey = (word: { readonly leak: string; readonly word: number }): string => `${word.leak}:${String(word.word)}`;
210
+
211
+ // A value's words, as a list proposal counts them.
212
+ export const leakWordsOf = (value: string): string[] => value.split(/[\s,;|]+/u).filter((word) => word !== "");
@@ -42,6 +42,9 @@ export const AUTH_STATE_FILES: readonly StateFile[] = [
42
42
  // The personal data the shield masked, by token, and the pictures it painted over.
43
43
  { path: "privacy-vault.json", portability: "secret" },
44
44
  { path: "privacy-images/", portability: "secret" },
45
+ // Values the shield let through, with the text around them, and the hardening proposals waiting on them
46
+ // (privacy/leaks/leak-store.ts): personal data, so it goes where the vault goes.
47
+ { path: "privacy-leaks.json", portability: "secret" },
45
48
  { path: "ssh-keys/", portability: "secret" },
46
49
  // An update's pre-images of the files above; a vault's copy is a vault.
47
50
  { path: "converting/", portability: "secret" },