typevault 0.1.0 → 0.3.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/README.md +156 -115
- package/package.json +14 -2
- package/src/access/env.ts +77 -17
- package/src/access/keys.ts +14 -14
- package/src/access/schemas.ts +6 -12
- package/src/access/scope.ts +14 -9
- package/src/access/scoped.ts +118 -44
- package/src/access/sealed-access.ts +50 -23
- package/src/access/sealed.ts +56 -31
- package/src/access/types.ts +27 -30
- package/src/admin.ts +68 -0
- package/src/audit/log.ts +28 -12
- package/src/cli/commands/admin.ts +93 -48
- package/src/cli/commands/daemon.ts +42 -17
- package/src/cli/commands/entries.ts +195 -60
- package/src/cli/commands/grant.ts +24 -22
- package/src/cli/commands/members.ts +307 -0
- package/src/cli/commands/run.ts +191 -44
- package/src/cli/context.ts +163 -15
- package/src/cli/index.ts +33 -5
- package/src/cli/password.ts +74 -0
- package/src/cli/web-prompt.ts +79 -0
- package/src/core/admin.ts +144 -76
- package/src/core/adopt.ts +40 -9
- package/src/core/crypto.ts +6 -4
- package/src/core/doctor.ts +15 -16
- package/src/core/entries.ts +66 -52
- package/src/core/errors.ts +8 -2
- package/src/core/fsx.ts +7 -3
- package/src/core/holder.ts +87 -0
- package/src/core/identity.ts +132 -0
- package/src/core/init.ts +73 -23
- package/src/core/json-file.ts +20 -0
- package/src/core/keyring.ts +100 -56
- package/src/core/layout.ts +143 -26
- package/src/core/lock.ts +128 -16
- package/src/core/naming.ts +150 -50
- package/src/core/password.ts +111 -0
- package/src/core/payload.ts +42 -38
- package/src/core/revisions.ts +11 -6
- package/src/core/rotate.ts +59 -42
- package/src/core/state.ts +102 -54
- package/src/core/txn.ts +9 -7
- package/src/core/vault.ts +108 -46
- package/src/core/worktrees.ts +51 -0
- package/src/daemon/admin-routes.ts +33 -21
- package/src/daemon/agent-routes.ts +31 -11
- package/src/daemon/client.ts +24 -2
- package/src/daemon/daemon.ts +218 -33
- package/src/daemon/grants.ts +25 -7
- package/src/daemon/http.ts +11 -2
- package/src/daemon/live-access.ts +8 -4
- package/src/daemon/protocol.ts +17 -12
- package/src/daemon/requests.ts +75 -51
- package/src/daemon/spawn.ts +218 -9
- package/src/export/1password.ts +157 -0
- package/src/import/1password-live.ts +399 -0
- package/src/import/1password.ts +26 -5
- package/src/import/bitwarden.ts +3 -3
- package/src/import/csv.ts +1 -1
- package/src/import/dotenv.ts +4 -3
- package/src/import/index.ts +1 -0
- package/src/import/keepass.ts +2 -2
- package/src/import/lastpass.ts +2 -2
- package/src/import/shared.ts +67 -10
- package/src/import/typeclaw.ts +2 -2
- package/src/import/types.ts +1 -1
- package/src/index.ts +58 -0
- package/src/owner.ts +156 -0
- package/src/prompt/browser.ts +48 -15
- package/src/prompt/index.ts +121 -64
- package/src/prompt/page.ts +27 -11
- package/src/prompt/styles.ts +64 -34
- package/src/prompt/types.ts +7 -4
- package/src/redact/index.ts +48 -12
- package/src/redact/scrub-file.ts +15 -7
package/src/prompt/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto'
|
|
2
2
|
|
|
3
3
|
import { TypeVaultError } from '../core/errors'
|
|
4
|
-
import { pageAssets, promptPage, expiredPage } from './page'
|
|
4
|
+
import { pageAssets, promptPage, expiredPage, rejectedPage } from './page'
|
|
5
5
|
import type { PromptHandle, PromptServer, PromptView } from './types'
|
|
6
6
|
|
|
7
7
|
export type { PromptHandle, PromptServer, PromptView } from './types'
|
|
@@ -11,7 +11,13 @@ type Pending = {
|
|
|
11
11
|
readonly view: PromptView
|
|
12
12
|
readonly resolve: (bytes: Uint8Array) => void
|
|
13
13
|
readonly reject: (error: TypeVaultError) => void
|
|
14
|
+
readonly accepted: Promise<void>
|
|
15
|
+
readonly accept: () => void
|
|
16
|
+
readonly refuse: (error: TypeVaultError) => void
|
|
17
|
+
readonly responded: Promise<void>
|
|
18
|
+
readonly respond: () => void
|
|
14
19
|
timer: ReturnType<typeof setTimeout> | undefined
|
|
20
|
+
submitted: boolean
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
const MAX_BODY = 64 * 1024
|
|
@@ -46,7 +52,9 @@ export async function startPromptServer(
|
|
|
46
52
|
|
|
47
53
|
function expire(token: string, entry: Pending): void {
|
|
48
54
|
retire(token, entry)
|
|
49
|
-
|
|
55
|
+
const error = new TypeVaultError('expired', 'Prompt expired or was cancelled')
|
|
56
|
+
entry.reject(error)
|
|
57
|
+
if (entry.submitted) entry.refuse(error)
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
function schedule(token: string, entry: Pending): void {
|
|
@@ -58,69 +66,96 @@ export async function startPromptServer(
|
|
|
58
66
|
entry.timer = setTimeout(() => schedule(token, entry), Math.min(remaining, 2_147_483_647))
|
|
59
67
|
}
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return response(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
let server: Bun.Server<undefined>
|
|
70
|
+
try {
|
|
71
|
+
server = Bun.serve({
|
|
72
|
+
hostname: '127.0.0.1',
|
|
73
|
+
port: options.port ?? 0,
|
|
74
|
+
// Enforce the limit while streaming so Bun's automatic 413 cannot omit security headers.
|
|
75
|
+
maxRequestBodySize: Number.MAX_SAFE_INTEGER,
|
|
76
|
+
async fetch(request) {
|
|
77
|
+
const path = new URL(request.url).pathname
|
|
78
|
+
const match = /^\/r\/([A-Za-z0-9_-]{22})$/.exec(path)
|
|
79
|
+
const token = match?.[1]
|
|
80
|
+
if (token === undefined || (request.method !== 'GET' && request.method !== 'POST')) return response(404)
|
|
81
|
+
const entry = pending.get(token)
|
|
82
|
+
if (entry === undefined) return gone.has(token) ? response(410, expiredPage()) : response(404)
|
|
83
|
+
if (entry.view.expiresAt.getTime() <= Date.now()) {
|
|
84
|
+
expire(token, entry)
|
|
85
|
+
return response(410, expiredPage())
|
|
86
|
+
}
|
|
87
|
+
if (request.method === 'GET') return response(200, promptPage(entry.view, assets.script))
|
|
88
|
+
if (entry.submitted) return response(410, expiredPage())
|
|
89
|
+
if (Number(request.headers.get('content-length')) > MAX_BODY) return response(413)
|
|
90
|
+
if (request.headers.get('content-type')?.split(';')[0]?.trim() !== 'application/octet-stream') {
|
|
91
|
+
return response(415)
|
|
92
|
+
}
|
|
93
|
+
const reader = request.body?.getReader()
|
|
94
|
+
const chunks: Uint8Array[] = []
|
|
95
|
+
let size = 0
|
|
96
|
+
try {
|
|
97
|
+
if (reader !== undefined) {
|
|
98
|
+
while (true) {
|
|
99
|
+
const chunk = await reader.read()
|
|
100
|
+
if (chunk.done) break
|
|
101
|
+
size += chunk.value.byteLength
|
|
102
|
+
if (size > MAX_BODY) {
|
|
103
|
+
await reader.cancel()
|
|
104
|
+
return response(413)
|
|
105
|
+
}
|
|
106
|
+
chunks.push(chunk.value)
|
|
94
107
|
}
|
|
95
|
-
chunks.push(chunk.value)
|
|
96
108
|
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error instanceof Error) return response(400)
|
|
111
|
+
throw error
|
|
112
|
+
} finally {
|
|
113
|
+
reader?.releaseLock()
|
|
97
114
|
}
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
// Another upload, cancellation or expiry may win while the body is being read.
|
|
116
|
+
if (entry.submitted) return response(410, expiredPage())
|
|
117
|
+
if (pending.get(token) !== entry) return response(410, expiredPage())
|
|
118
|
+
if (entry.view.expiresAt.getTime() <= Date.now()) {
|
|
119
|
+
expire(token, entry)
|
|
120
|
+
return response(410, expiredPage())
|
|
121
|
+
}
|
|
122
|
+
const bytes = new Uint8Array(size)
|
|
123
|
+
let offset = 0
|
|
124
|
+
for (const chunk of chunks) {
|
|
125
|
+
bytes.set(chunk, offset)
|
|
126
|
+
offset += chunk.byteLength
|
|
127
|
+
}
|
|
128
|
+
entry.submitted = true
|
|
129
|
+
clearTimeout(entry.timer)
|
|
130
|
+
entry.timer = undefined
|
|
131
|
+
entry.resolve(bytes)
|
|
132
|
+
try {
|
|
133
|
+
await entry.accepted
|
|
134
|
+
retire(token, entry)
|
|
135
|
+
const accepted = response(204)
|
|
136
|
+
entry.respond()
|
|
137
|
+
return accepted
|
|
138
|
+
} catch (error) {
|
|
139
|
+
retire(token, entry)
|
|
140
|
+
if (error instanceof TypeVaultError) {
|
|
141
|
+
const rejected = response(error.code === 'tampered' ? 422 : 403, rejectedPage())
|
|
142
|
+
entry.respond()
|
|
143
|
+
return rejected
|
|
144
|
+
}
|
|
145
|
+
throw error
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
error() {
|
|
149
|
+
return response(500)
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (!(error instanceof Error) || !('code' in error) || typeof error.code !== 'string') throw error
|
|
154
|
+
throw new TypeVaultError(
|
|
155
|
+
'unavailable',
|
|
156
|
+
`The secret page could not listen on 127.0.0.1:${options.port ?? 0} (${error.code}); set TYPEVAULT_PROMPT_PORT to use another port`,
|
|
157
|
+
)
|
|
158
|
+
}
|
|
124
159
|
|
|
125
160
|
const port = server.port
|
|
126
161
|
if (port === undefined) {
|
|
@@ -129,23 +164,45 @@ export async function startPromptServer(
|
|
|
129
164
|
}
|
|
130
165
|
return {
|
|
131
166
|
port,
|
|
132
|
-
open(view): PromptHandle {
|
|
167
|
+
open(view, openOptions = {}): PromptHandle {
|
|
133
168
|
if (stopped) throw new TypeVaultError('unavailable', 'Prompt server is stopped')
|
|
134
169
|
if (!Number.isFinite(view.expiresAt.getTime())) throw new TypeVaultError('invalid', 'Invalid prompt expiry')
|
|
135
170
|
const token = randomBytes(16).toString('base64url')
|
|
136
171
|
const id = randomBytes(16).toString('base64url')
|
|
137
172
|
const { promise: done, resolve, reject } = Promise.withResolvers<Uint8Array>()
|
|
173
|
+
const { promise: accepted, resolve: accept, reject: refuse } = Promise.withResolvers<void>()
|
|
174
|
+
const { promise: responded, resolve: respond } = Promise.withResolvers<void>()
|
|
138
175
|
const entry: Pending = {
|
|
139
176
|
id,
|
|
140
177
|
view: { ...view, recipients: [...view.recipients], expiresAt: new Date(view.expiresAt) },
|
|
141
178
|
resolve,
|
|
142
179
|
reject,
|
|
180
|
+
accepted,
|
|
181
|
+
accept,
|
|
182
|
+
refuse,
|
|
183
|
+
responded,
|
|
184
|
+
respond,
|
|
143
185
|
timer: undefined,
|
|
186
|
+
submitted: false,
|
|
144
187
|
}
|
|
145
188
|
pending.set(token, entry)
|
|
146
189
|
ids.set(id, token)
|
|
147
190
|
schedule(token, entry)
|
|
148
|
-
|
|
191
|
+
if (openOptions.validate !== true) accept()
|
|
192
|
+
return {
|
|
193
|
+
id,
|
|
194
|
+
url: `${options.publicUrl ?? `http://127.0.0.1:${port}`}/r/${token}`,
|
|
195
|
+
done,
|
|
196
|
+
accept: async () => {
|
|
197
|
+
accept()
|
|
198
|
+
await responded
|
|
199
|
+
},
|
|
200
|
+
reject: async (error) => {
|
|
201
|
+
if (!entry.submitted) return
|
|
202
|
+
refuse(error)
|
|
203
|
+
await responded
|
|
204
|
+
},
|
|
205
|
+
}
|
|
149
206
|
},
|
|
150
207
|
cancel(id) {
|
|
151
208
|
const token = ids.get(id)
|
package/src/prompt/page.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
2
3
|
|
|
3
4
|
import { TypeVaultError } from '../core/errors'
|
|
4
5
|
import { styles } from './styles'
|
|
@@ -13,7 +14,7 @@ export function pageAssets(): ReturnType<typeof buildAssets> {
|
|
|
13
14
|
|
|
14
15
|
async function buildAssets() {
|
|
15
16
|
const result = await Bun.build({
|
|
16
|
-
entrypoints: [new URL('./browser.ts', import.meta.url)
|
|
17
|
+
entrypoints: [fileURLToPath(new URL('./browser.ts', import.meta.url))],
|
|
17
18
|
target: 'browser',
|
|
18
19
|
minify: true,
|
|
19
20
|
})
|
|
@@ -35,6 +36,11 @@ async function buildAssets() {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
const LOCK_ICON =
|
|
40
|
+
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>'
|
|
41
|
+
const CHECK_ICON =
|
|
42
|
+
'<svg width="44" height="44" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="m8 12.5 2.5 2.5L16 9.5"/></svg>'
|
|
43
|
+
|
|
38
44
|
function escapeHtml(value: string): string {
|
|
39
45
|
return value.replace(/[&<>"']/g, (char) => {
|
|
40
46
|
const entities: Readonly<Record<string, string>> = {
|
|
@@ -60,17 +66,19 @@ export function promptPage(view: PromptView, script: string): string {
|
|
|
60
66
|
return shell(
|
|
61
67
|
'Secret request',
|
|
62
68
|
`
|
|
69
|
+
<header><p class="eyebrow">Secret request</p>
|
|
63
70
|
<h1>${escapeHtml(view.name)}</h1>
|
|
64
|
-
<p class="
|
|
65
|
-
<
|
|
66
|
-
<
|
|
67
|
-
<section class="match" aria-label="Match code"><p class="
|
|
68
|
-
<p class="hint">
|
|
71
|
+
<p class="reason">${escapeHtml(view.reason)}</p>
|
|
72
|
+
<dl class="meta"><div><dt>Requested by</dt><dd>${escapeHtml(view.requester)}</dd></div>
|
|
73
|
+
<div><dt>Readable by</dt><dd>${escapeHtml(view.tier)}</dd></div></dl></header>
|
|
74
|
+
<section class="match" aria-label="Match code"><div class="match-text"><p class="match-label">Match code</p>
|
|
75
|
+
<p class="hint">Make sure your chat shows the same code.</p></div>
|
|
76
|
+
<p class="code">${escapeHtml(view.code)}</p></section>
|
|
69
77
|
<form id="prompt"><div id="fields"></div>
|
|
70
|
-
<
|
|
78
|
+
<div class="actions"><p id="status" role="alert"></p>
|
|
71
79
|
<button id="submit" type="submit">Encrypt and submit</button>
|
|
72
|
-
<p
|
|
73
|
-
<section id="success" hidden role="status" tabindex="-1"
|
|
80
|
+
<p class="note">${LOCK_ICON}<span>Encrypted in your browser. Only the selected tier's recipients can read this secret.</span></p></div></form>
|
|
81
|
+
<section id="success" class="done" hidden role="status" tabindex="-1">${CHECK_ICON}<h2>Secret submitted</h2>
|
|
74
82
|
<p>Your encrypted secret was delivered. You can close this page.</p></section>
|
|
75
83
|
<noscript>JavaScript is required to encrypt your secret before it leaves this browser.</noscript>
|
|
76
84
|
<script type="application/json" id="tv-data">${data}</script><script type="module">${script}</script>`,
|
|
@@ -80,7 +88,15 @@ export function promptPage(view: PromptView, script: string): string {
|
|
|
80
88
|
export function expiredPage(): string {
|
|
81
89
|
return shell(
|
|
82
90
|
'Request unavailable',
|
|
83
|
-
`<h1>Expired or already used</h1>
|
|
84
|
-
<p>This one-time request is no longer available. Ask the agent for a new link and match code.</p>`,
|
|
91
|
+
`<p class="eyebrow">Secret request</p><h1>Expired or already used</h1>
|
|
92
|
+
<p class="reason">This one-time request is no longer available. Ask the agent for a new link and match code.</p>`,
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function rejectedPage(): string {
|
|
97
|
+
return shell(
|
|
98
|
+
'Submission rejected',
|
|
99
|
+
`<p class="eyebrow">Secret request</p><h1>Secret not accepted</h1>
|
|
100
|
+
<p class="reason">The encrypted submission did not match this request. Ask the agent for a new link and match code.</p>`,
|
|
85
101
|
)
|
|
86
102
|
}
|
package/src/prompt/styles.ts
CHANGED
|
@@ -1,57 +1,87 @@
|
|
|
1
1
|
export const styles = `
|
|
2
2
|
:root {
|
|
3
3
|
color-scheme: light dark;
|
|
4
|
-
--canvas: #
|
|
5
|
-
--line: #
|
|
6
|
-
--hover: #
|
|
4
|
+
--canvas: #f5f6fa; --surface: #ffffff; --ink: #141a2e; --muted: #575f7c;
|
|
5
|
+
--line: #e1e6f4; --field: #8d98c4; --soft: #f1f3fa; --accent: #4f5ed7; --on-accent: #ffffff;
|
|
6
|
+
--hover: #3f4ec4; --error: #b42335; --error-soft: #fcf0f1; --focus: #4f5ed7;
|
|
7
|
+
--ring: rgb(79 94 215 / .18); --shadow: 0 1px 2px rgb(13 23 54 / .05), 0 12px 32px rgb(13 23 54 / .08);
|
|
7
8
|
font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
8
|
-
scrollbar-color: var(--
|
|
9
|
+
scrollbar-color: var(--field) var(--canvas);
|
|
9
10
|
}
|
|
10
11
|
@media (prefers-color-scheme: dark) {
|
|
11
12
|
:root {
|
|
12
|
-
--canvas: #
|
|
13
|
-
--line: #
|
|
14
|
-
--hover: #
|
|
13
|
+
--canvas: #0a0f1f; --surface: #121a31; --ink: #eef1fb; --muted: #a9b2d6;
|
|
14
|
+
--line: #232d4d; --field: #4d5d9e; --soft: #1a2343; --accent: #9da7d2; --on-accent: #0d1736;
|
|
15
|
+
--hover: #c3cae6; --error: #ffabb5; --error-soft: #3a1d2a; --focus: #9da7d2;
|
|
16
|
+
--ring: rgb(157 167 210 / .22); --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 12px 32px rgb(0 0 0 / .3);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
* { box-sizing: border-box; }
|
|
18
|
-
body { margin: 0; min-height: 100dvh; display: grid; place-items: center; padding:
|
|
19
|
-
background: var(--canvas); color: var(--ink); }
|
|
20
|
-
main { width: min(100%,
|
|
21
|
-
overflow-wrap: anywhere; }
|
|
22
|
-
h1 { font-size:
|
|
20
|
+
body { margin: 0; min-height: 100dvh; display: grid; place-items: center; padding: 40px 16px;
|
|
21
|
+
background: var(--canvas); color: var(--ink); -webkit-font-smoothing: antialiased; }
|
|
22
|
+
main { width: min(100%, 480px); background: var(--surface); border: 1px solid var(--line);
|
|
23
|
+
border-radius: 20px; padding: 36px; box-shadow: var(--shadow); overflow-wrap: anywhere; }
|
|
24
|
+
h1 { font-size: 26px; line-height: 1.25; letter-spacing: -.02em; margin: 0; }
|
|
25
|
+
h2 { font-size: 20px; line-height: 1.3; margin: 0 0 6px; }
|
|
23
26
|
p { margin: 0; }
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
.reason { white-space: pre-wrap; }
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
|
|
28
|
+
color: var(--accent); margin-bottom: 6px; }
|
|
29
|
+
.reason { white-space: pre-wrap; margin-top: 12px; }
|
|
30
|
+
.meta { display: flex; flex-wrap: wrap; gap: 4px 24px; margin: 16px 0 0; font-size: 14px; }
|
|
31
|
+
.meta div { display: flex; gap: 6px; min-width: 0; }
|
|
32
|
+
.meta dt { color: var(--muted); }
|
|
33
|
+
.meta dd { margin: 0; font-weight: 500; }
|
|
34
|
+
.match { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px;
|
|
35
|
+
margin: 28px 0; padding: 16px 20px; background: var(--soft); border-radius: 12px; }
|
|
36
|
+
.match-text { flex: 1 1 200px; }
|
|
37
|
+
.match-label { font-weight: 600; font-size: 14px; }
|
|
38
|
+
.code { font: 600 26px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em;
|
|
39
|
+
font-variant-numeric: tabular-nums; }
|
|
40
|
+
.hint, .note { font-size: 14px; color: var(--muted); }
|
|
41
|
+
.match .hint { margin-top: 2px; }
|
|
42
|
+
form, #fields { display: grid; gap: 20px; }
|
|
43
|
+
form { gap: 24px; }
|
|
44
|
+
.field { display: grid; gap: 6px; }
|
|
45
|
+
label { font-weight: 600; font-size: 15px; }
|
|
46
|
+
.optional { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
|
|
47
|
+
.input-row { position: relative; }
|
|
48
|
+
input, textarea { display: block; width: 100%; min-width: 0; min-height: 46px; border: 1px solid var(--field);
|
|
49
|
+
border-radius: 10px; padding: 11px 12px; background: var(--surface); color: var(--ink); font: inherit;
|
|
50
|
+
caret-color: var(--accent); transition: border-color .15s, box-shadow .15s; }
|
|
51
|
+
input:hover, textarea:hover { border-color: var(--muted); }
|
|
52
|
+
input:focus, textarea:focus { outline: 2px solid transparent; outline-offset: 2px; border-color: var(--focus); box-shadow: 0 0 0 4px var(--ring); }
|
|
53
|
+
.input-row:has(.toggle) input, .input-row:has(.toggle) textarea { padding-right: 76px;
|
|
54
|
+
font-family: ui-monospace, "SF Mono", Menlo, monospace; }
|
|
55
|
+
textarea { min-height: 128px; resize: vertical; }
|
|
38
56
|
.concealed { -webkit-text-security: disc; }
|
|
39
|
-
button { min-height: 48px; border: 0; border-radius:
|
|
40
|
-
font: 600 16px/1.5 system-ui, sans-serif; color: var(--on-accent); background: var(--accent);
|
|
57
|
+
button { min-height: 48px; border: 0; border-radius: 10px; padding: 12px 16px; cursor: pointer;
|
|
58
|
+
font: 600 16px/1.5 system-ui, sans-serif; color: var(--on-accent); background: var(--accent);
|
|
59
|
+
transition: background-color .15s; }
|
|
41
60
|
button:hover { background: var(--hover); }
|
|
42
61
|
button:active { opacity: .85; }
|
|
43
62
|
button:disabled { cursor: default; opacity: .65; }
|
|
44
|
-
.toggle {
|
|
45
|
-
|
|
63
|
+
.toggle { position: absolute; top: 7px; right: 7px; min-height: 32px; width: 60px; padding: 4px 0;
|
|
64
|
+
font-size: 13px; border-radius: 7px; background: var(--soft); color: var(--ink); }
|
|
65
|
+
.toggle:hover { background: var(--line); }
|
|
46
66
|
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
|
|
47
67
|
::selection { background: var(--accent); color: var(--on-accent); }
|
|
68
|
+
.actions { display: grid; gap: 12px; }
|
|
69
|
+
.note { display: flex; gap: 8px; align-items: flex-start; }
|
|
70
|
+
.note svg, .done svg { flex-shrink: 0; }
|
|
71
|
+
.note svg { margin-top: 2px; }
|
|
48
72
|
#submit { width: 100%; }
|
|
49
|
-
#status { color: var(--error); }
|
|
73
|
+
#status { color: var(--error); background: var(--error-soft); padding: 10px 14px; border-radius: 10px; font-size: 14px; }
|
|
50
74
|
#status:empty { display: none; }
|
|
51
|
-
#success { margin-top:
|
|
75
|
+
#success { margin-top: 4px; }
|
|
76
|
+
.done { display: grid; justify-items: center; text-align: center; gap: 4px; padding: 12px 0 4px; }
|
|
77
|
+
.done svg { color: var(--accent); margin-bottom: 8px; }
|
|
78
|
+
.done p { color: var(--muted); }
|
|
79
|
+
noscript { display: block; margin-top: 16px; color: var(--error); }
|
|
52
80
|
[hidden] { display: none !important; }
|
|
53
81
|
@media (max-width: 480px) {
|
|
54
|
-
body { padding:
|
|
55
|
-
main { padding:
|
|
82
|
+
body { padding: 12px; place-items: start center; }
|
|
83
|
+
main { padding: 24px 20px; border-radius: 16px; }
|
|
84
|
+
h1 { font-size: 23px; }
|
|
85
|
+
.match { padding: 14px 16px; }
|
|
56
86
|
}
|
|
57
87
|
`
|
package/src/prompt/types.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TypeVaultError } from '../core/errors'
|
|
2
|
+
import type { Preset } from '../core/naming'
|
|
2
3
|
|
|
3
4
|
export type PromptView = {
|
|
4
5
|
readonly name: string
|
|
5
|
-
readonly
|
|
6
|
-
readonly
|
|
6
|
+
readonly preset?: Preset | undefined
|
|
7
|
+
readonly tier: string
|
|
7
8
|
readonly reason: string
|
|
8
9
|
readonly requester: string
|
|
9
10
|
readonly code: string
|
|
@@ -15,11 +16,13 @@ export type PromptHandle = {
|
|
|
15
16
|
readonly id: string
|
|
16
17
|
readonly url: string
|
|
17
18
|
readonly done: Promise<Uint8Array>
|
|
19
|
+
readonly accept: () => Promise<void>
|
|
20
|
+
readonly reject: (error: TypeVaultError) => Promise<void>
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export type PromptServer = {
|
|
21
24
|
readonly port: number
|
|
22
|
-
readonly open: (view: PromptView) => PromptHandle
|
|
25
|
+
readonly open: (view: PromptView, options?: { readonly validate?: boolean }) => PromptHandle
|
|
23
26
|
readonly cancel: (id: string) => void
|
|
24
27
|
readonly stop: () => Promise<void>
|
|
25
28
|
}
|
package/src/redact/index.ts
CHANGED
|
@@ -31,8 +31,10 @@ export function createRedactor(values: readonly string[], options?: { readonly r
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
const patterns: readonly string[] = [...variants].sort((left, right) => right.length - left.length)
|
|
34
|
-
const longest = patterns[0]?.length ?? 1
|
|
35
34
|
const replacement = options?.replacement ?? '[redacted]'
|
|
35
|
+
const bytePatterns = patterns.map((pattern) => Buffer.from(pattern)).sort((left, right) => right.length - left.length)
|
|
36
|
+
const replacementBytes = Buffer.from(replacement)
|
|
37
|
+
const expansion = Math.max(1, ...bytePatterns.map((pattern) => replacementBytes.length / pattern.length))
|
|
36
38
|
|
|
37
39
|
// Consume whole matches, even when they extend beyond the safe emission boundary.
|
|
38
40
|
const consume = (text: string, limit: number): { readonly output: string; readonly rest: string } => {
|
|
@@ -56,21 +58,55 @@ export function createRedactor(values: readonly string[], options?: { readonly r
|
|
|
56
58
|
return {
|
|
57
59
|
redact: (text) => consume(text, text.length).output,
|
|
58
60
|
stream: () => {
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
61
|
+
let pending = Buffer.alloc(0)
|
|
62
|
+
const emit = (input: Buffer, final: boolean, controller: TransformStreamDefaultController<Uint8Array>) => {
|
|
63
|
+
let limit = input.length
|
|
64
|
+
if (!final) {
|
|
65
|
+
for (const pattern of bytePatterns) {
|
|
66
|
+
const start = Math.max(0, input.length - pattern.length + 1)
|
|
67
|
+
for (let index = input.indexOf(pattern.subarray(0, 1), start); index >= 0 && index < limit;) {
|
|
68
|
+
if (input.subarray(index).equals(pattern.subarray(0, input.length - index))) {
|
|
69
|
+
limit = index
|
|
70
|
+
break
|
|
71
|
+
}
|
|
72
|
+
index = input.indexOf(pattern.subarray(0, 1), index + 1)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
let index = 0
|
|
77
|
+
const output = Buffer.allocUnsafe(Math.ceil(input.length * expansion))
|
|
78
|
+
let written = 0
|
|
79
|
+
const matches = bytePatterns.map((pattern) => ({ pattern, at: input.indexOf(pattern) }))
|
|
80
|
+
while (index < limit) {
|
|
81
|
+
let next = input.length
|
|
82
|
+
let match: Buffer | undefined
|
|
83
|
+
for (const candidate of matches) {
|
|
84
|
+
if (candidate.at >= 0 && candidate.at < index) candidate.at = input.indexOf(candidate.pattern, index)
|
|
85
|
+
if (candidate.at >= 0 && candidate.at < next) {
|
|
86
|
+
next = candidate.at
|
|
87
|
+
match = candidate.pattern
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (match === undefined || next >= limit) {
|
|
91
|
+
written += input.copy(output, written, index, limit)
|
|
92
|
+
index = limit
|
|
93
|
+
} else {
|
|
94
|
+
written += input.copy(output, written, index, next)
|
|
95
|
+
written += replacementBytes.copy(output, written)
|
|
96
|
+
index = next + match.length
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (written > 0) controller.enqueue(output.subarray(0, written))
|
|
100
|
+
// Copy only the undecided suffix, so it cannot retain a large input buffer.
|
|
101
|
+
pending = Buffer.from(input.subarray(index))
|
|
102
|
+
}
|
|
62
103
|
return new TransformStream<Uint8Array, Uint8Array>({
|
|
63
104
|
transform(chunk, controller) {
|
|
64
|
-
pending
|
|
65
|
-
|
|
66
|
-
const result = consume(pending, limit)
|
|
67
|
-
pending = result.rest
|
|
68
|
-
if (result.output.length > 0) controller.enqueue(encoder.encode(result.output))
|
|
105
|
+
const input = pending.length > 0 ? Buffer.concat([pending, chunk]) : Buffer.from(chunk)
|
|
106
|
+
emit(input, false, controller)
|
|
69
107
|
},
|
|
70
108
|
flush(controller) {
|
|
71
|
-
pending
|
|
72
|
-
const result = consume(pending, pending.length)
|
|
73
|
-
if (result.output.length > 0) controller.enqueue(encoder.encode(result.output))
|
|
109
|
+
emit(pending, true, controller)
|
|
74
110
|
},
|
|
75
111
|
})
|
|
76
112
|
},
|
package/src/redact/scrub-file.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto'
|
|
2
|
-
import { open, rename, rm } from 'node:fs/promises'
|
|
2
|
+
import { lstat, open, rename, rm } from 'node:fs/promises'
|
|
3
3
|
import { dirname, join } from 'node:path'
|
|
4
4
|
|
|
5
5
|
import { TypeVaultError } from '../core/errors'
|
|
@@ -9,22 +9,28 @@ export async function scrubFile(path: string, redactor: Redactor): Promise<boole
|
|
|
9
9
|
let temporary: string | undefined
|
|
10
10
|
try {
|
|
11
11
|
try {
|
|
12
|
+
const info = await lstat(path)
|
|
13
|
+
if (info.isSymbolicLink())
|
|
14
|
+
throw new TypeVaultError('invalid', 'Refusing to scrub a symbolic link; name its target')
|
|
15
|
+
if (!info.isFile()) throw new TypeVaultError('invalid', 'Not a regular file')
|
|
12
16
|
const original = await open(path, 'r')
|
|
13
17
|
const snapshot = await (async () => {
|
|
14
18
|
try {
|
|
15
|
-
return {
|
|
19
|
+
return { bytes: await original.readFile(), mode: (await original.stat()).mode & 0o7777 }
|
|
16
20
|
} finally {
|
|
17
21
|
await original.close()
|
|
18
22
|
}
|
|
19
23
|
})()
|
|
20
|
-
const redacted =
|
|
21
|
-
|
|
24
|
+
const redacted = Buffer.from(
|
|
25
|
+
await new Response(new Blob([snapshot.bytes]).stream().pipeThrough(redactor.stream())).arrayBuffer(),
|
|
26
|
+
)
|
|
27
|
+
if (redacted.equals(snapshot.bytes)) return false
|
|
22
28
|
|
|
23
29
|
const candidate = join(dirname(path), `.typevault-redact-${randomUUID()}`)
|
|
24
30
|
const file = await open(candidate, 'wx', 0o600)
|
|
25
31
|
temporary = candidate
|
|
26
32
|
try {
|
|
27
|
-
await file.writeFile(redacted
|
|
33
|
+
await file.writeFile(redacted)
|
|
28
34
|
await file.chmod(snapshot.mode)
|
|
29
35
|
await file.sync()
|
|
30
36
|
} finally {
|
|
@@ -37,7 +43,9 @@ export async function scrubFile(path: string, redactor: Redactor): Promise<boole
|
|
|
37
43
|
if (temporary !== undefined) await rm(temporary, { force: true })
|
|
38
44
|
}
|
|
39
45
|
} catch (error) {
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
throw new TypeVaultError(
|
|
47
|
+
error instanceof TypeVaultError ? error.code : 'unavailable',
|
|
48
|
+
`${path}: ${error instanceof Error ? error.message : String(error)}`,
|
|
49
|
+
)
|
|
42
50
|
}
|
|
43
51
|
}
|