@yaks/browse 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +324 -2
- package/_dist/app.d.ts +8 -0
- package/_dist/app.d.ts.map +1 -0
- package/_dist/cli.d.ts +16 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/hosting.d.ts +24 -0
- package/_dist/hosting.d.ts.map +1 -0
- package/_dist/mod.d.ts +7 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/types.d.ts +5 -0
- package/_dist/types.d.ts.map +1 -0
- package/_dist/url.d.ts +2 -0
- package/_dist/url.d.ts.map +1 -0
- package/app.js +10 -0
- package/app.js.map +1 -0
- package/app.ts +10 -0
- package/browser-links.js +22 -0
- package/browser-links.js.map +1 -0
- package/browser-links.ts +28 -0
- package/cli.js +172 -0
- package/cli.js.map +1 -0
- package/cli.ts +168 -0
- package/client.js +748 -0
- package/client.js.map +1 -0
- package/client.ts +734 -0
- package/clipboard.js +18 -0
- package/clipboard.js.map +1 -0
- package/clipboard.ts +17 -0
- package/commands.js +1157 -0
- package/commands.js.map +1 -0
- package/commands.ts +1108 -0
- package/components/Ansi.tsx +160 -0
- package/components/App.tsx +446 -0
- package/components/Canvas.tsx +625 -0
- package/components/Card.tsx +276 -0
- package/components/Chat.tsx +205 -0
- package/components/Configuration.tsx +218 -0
- package/components/Decision.tsx +49 -0
- package/components/Dot.tsx +52 -0
- package/components/Entity.tsx +609 -0
- package/components/Fault.tsx +43 -0
- package/components/Filter.tsx +103 -0
- package/components/Keybindings.tsx +100 -0
- package/components/Keys.tsx +67 -0
- package/components/Markdown.tsx +90 -0
- package/components/Navigation.tsx +161 -0
- package/components/New.tsx +490 -0
- package/components/Peek.tsx +168 -0
- package/components/Prio.tsx +20 -0
- package/components/Run.tsx +263 -0
- package/components/Search.tsx +280 -0
- package/components/Stamp.tsx +44 -0
- package/components/Status.tsx +514 -0
- package/components/Sync.tsx +173 -0
- package/components/Tile.tsx +50 -0
- package/components/answered.js +23 -0
- package/components/answered.js.map +1 -0
- package/components/answered.ts +25 -0
- package/components/comp.js +11 -0
- package/components/comp.js.map +1 -0
- package/components/comp.ts +10 -0
- package/components/drag.js +173 -0
- package/components/drag.js.map +1 -0
- package/components/drag.ts +198 -0
- package/components/fields.tsx +90 -0
- package/components/fixtures/README.md +10 -0
- package/components/fixtures/archetypes.json +3646 -0
- package/components/hits.js +63 -0
- package/components/hits.js.map +1 -0
- package/components/hits.ts +84 -0
- package/components/icons.tsx +177 -0
- package/components/inspect.tsx +331 -0
- package/components/mount.ts +79 -0
- package/components/nav.tsx +479 -0
- package/components/offers.js +26 -0
- package/components/offers.js.map +1 -0
- package/components/offers.ts +54 -0
- package/components/page.js +21 -0
- package/components/page.js.map +1 -0
- package/components/page.ts +18 -0
- package/components/read.js +5 -0
- package/components/read.js.map +1 -0
- package/components/read.ts +7 -0
- package/components/registry.js +285 -0
- package/components/registry.js.map +1 -0
- package/components/registry.ts +317 -0
- package/components/session_status.tsx +115 -0
- package/components/subscriptions.js +149 -0
- package/components/subscriptions.js.map +1 -0
- package/components/subscriptions.ts +161 -0
- package/components/title.tsx +21 -0
- package/components/useQuery.js +166 -0
- package/components/useQuery.js.map +1 -0
- package/components/useQuery.ts +211 -0
- package/components/views/Board.tsx +450 -0
- package/components/views/BoardTile.tsx +65 -0
- package/components/views/Dashboard.tsx +148 -0
- package/components/views/Debug.tsx +445 -0
- package/components/views/Dependency.tsx +51 -0
- package/components/views/Entry.tsx +500 -0
- package/components/views/Gist.tsx +28 -0
- package/components/views/Inline.tsx +54 -0
- package/components/views/Json.tsx +19 -0
- package/components/views/Layout.tsx +211 -0
- package/components/views/List.tsx +238 -0
- package/components/views/Md.tsx +43 -0
- package/components/views/Media.tsx +48 -0
- package/components/views/Memory.tsx +32 -0
- package/components/views/Relate.tsx +205 -0
- package/components/views/Search.tsx +42 -0
- package/components/views/Session.tsx +850 -0
- package/components/views/SessionManage.tsx +127 -0
- package/components/views/Show.tsx +758 -0
- package/components/views/Shown.tsx +72 -0
- package/components/views/Split.tsx +58 -0
- package/components/views/TaskTile.tsx +37 -0
- package/components/views/Title.tsx +105 -0
- package/components/views/Wake.tsx +77 -0
- package/components/views/Web.tsx +49 -0
- package/components/wells.js +30 -0
- package/components/wells.js.map +1 -0
- package/components/wells.ts +33 -0
- package/configuration.js +38 -0
- package/configuration.js.map +1 -0
- package/configuration.ts +41 -0
- package/decision_sync.js +88 -0
- package/decision_sync.js.map +1 -0
- package/decision_sync.ts +93 -0
- package/deno.json +1 -0
- package/domain-host.tsx +108 -0
- package/edge.js +193 -0
- package/edge.js.map +1 -0
- package/edge.ts +196 -0
- package/entry_log.js +241 -0
- package/entry_log.js.map +1 -0
- package/entry_log.ts +214 -0
- package/failure.js +22 -0
- package/failure.js.map +1 -0
- package/failure.ts +34 -0
- package/front.json +61 -0
- package/highlight.js +143 -0
- package/highlight.js.map +1 -0
- package/highlight.ts +149 -0
- package/history.js +68 -0
- package/history.js.map +1 -0
- package/history.ts +72 -0
- package/host_commands.js +107 -0
- package/host_commands.js.map +1 -0
- package/host_commands.ts +38 -0
- package/hosting.js +53 -0
- package/hosting.js.map +1 -0
- package/hosting.ts +72 -0
- package/idb.js +14 -0
- package/idb.js.map +1 -0
- package/idb.ts +15 -0
- package/index.js +232 -0
- package/index.js.map +1 -0
- package/index.ts +252 -0
- package/keybindings.js +136 -0
- package/keybindings.js.map +1 -0
- package/keybindings.ts +37 -0
- package/kit.js +103 -0
- package/kit.js.map +1 -0
- package/kit.ts +119 -0
- package/layout.js +254 -0
- package/layout.js.map +1 -0
- package/layout.ts +210 -0
- package/legacy_outbox.js +53 -0
- package/legacy_outbox.js.map +1 -0
- package/legacy_outbox.ts +63 -0
- package/live.js +2883 -0
- package/live.js.map +1 -0
- package/live.ts +3334 -0
- package/live_archetypes.js +92 -0
- package/live_archetypes.js.map +1 -0
- package/live_archetypes.ts +113 -0
- package/live_client.js +145 -0
- package/live_client.js.map +1 -0
- package/live_client.ts +120 -0
- package/main.tsx +5 -0
- package/mod.js +7 -0
- package/mod.js.map +1 -0
- package/mod.ts +7 -0
- package/mount.tsx +50 -0
- package/navigation.js +120 -0
- package/navigation.js.map +1 -0
- package/navigation.ts +152 -0
- package/near.js +83 -0
- package/near.js.map +1 -0
- package/near.ts +83 -0
- package/new.js +295 -0
- package/new.js.map +1 -0
- package/new.ts +361 -0
- package/outbox.js +112 -0
- package/outbox.js.map +1 -0
- package/outbox.ts +129 -0
- package/owner.js +39 -0
- package/owner.js.map +1 -0
- package/owner.ts +37 -0
- package/package.json +81 -4
- package/paste.js +157 -0
- package/paste.js.map +1 -0
- package/paste.ts +122 -0
- package/props.js +303 -0
- package/props.js.map +1 -0
- package/props.ts +358 -0
- package/providers.js +136 -0
- package/providers.js.map +1 -0
- package/providers.ts +194 -0
- package/query.js +987 -0
- package/query.js.map +1 -0
- package/query.ts +1113 -0
- package/remote.js +37 -0
- package/remote.js.map +1 -0
- package/remote.ts +46 -0
- package/resolver.js +149 -0
- package/resolver.js.map +1 -0
- package/resolver.ts +213 -0
- package/rfc2047.js +37 -0
- package/rfc2047.js.map +1 -0
- package/rfc2047.ts +40 -0
- package/row_holds.js +107 -0
- package/row_holds.js.map +1 -0
- package/row_holds.ts +93 -0
- package/served.ts +42 -0
- package/session_worktree.js +7 -0
- package/session_worktree.js.map +1 -0
- package/session_worktree.ts +16 -0
- package/sessions.js +57 -0
- package/sessions.js.map +1 -0
- package/sessions.ts +53 -0
- package/sha.js +161 -0
- package/sha.js.map +1 -0
- package/sha.ts +164 -0
- package/styles.css +2823 -0
- package/subs.js +36 -0
- package/subs.js.map +1 -0
- package/subs.ts +40 -0
- package/terminal-route.js +13 -0
- package/terminal-route.js.map +1 -0
- package/terminal-route.ts +17 -0
- package/terminal.js +251 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +186 -0
- package/time.js +142 -0
- package/time.js.map +1 -0
- package/time.ts +133 -0
- package/title.js +25 -0
- package/title.js.map +1 -0
- package/title.ts +50 -0
- package/tui/doc.ts +6 -0
- package/tui/testing.ts +19 -0
- package/twin.js +11 -0
- package/twin.js.map +1 -0
- package/twin.ts +13 -0
- package/types.js +456 -0
- package/types.js.map +1 -0
- package/types.ts +1370 -0
- package/url.js +77 -0
- package/url.js.map +1 -0
- package/url.ts +85 -0
- package/verb.js +82 -0
- package/verb.js.map +1 -0
- package/verb.ts +137 -0
- package/warmth.js +41 -0
- package/warmth.js.map +1 -0
- package/warmth.ts +54 -0
- package/wire.js +86 -0
- package/wire.js.map +1 -0
- package/wire.ts +63 -0
package/row_holds.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Concurrent row readers share a bounded immutable request. Each reader keeps
|
|
2
|
+
// its own lifetime; the request closes only after its last reader leaves.
|
|
3
|
+
export let rowHolds = (
|
|
4
|
+
open: (name: string, query: string) => void,
|
|
5
|
+
close: (name: string) => void,
|
|
6
|
+
later: (run: () => void) => void = queueMicrotask,
|
|
7
|
+
) => {
|
|
8
|
+
type Group = { name: string; readers: Set<string> }
|
|
9
|
+
let groups = new Map<string, Group>()
|
|
10
|
+
let held = new Map<string, { ids: string[]; uses: number; group?: Group }>()
|
|
11
|
+
let pending = new Set<string>()
|
|
12
|
+
let queued = false
|
|
13
|
+
let generation = 0
|
|
14
|
+
let start = (names: string[], ids: string[]) => {
|
|
15
|
+
let key = `rows:${ids.join(',')}`
|
|
16
|
+
let group = groups.get(key)
|
|
17
|
+
if (!group) {
|
|
18
|
+
groups.set(key, group = { name: key, readers: new Set() })
|
|
19
|
+
open(key, `id=${ids.join(',')}`)
|
|
20
|
+
}
|
|
21
|
+
for (let name of names) {
|
|
22
|
+
let reader = held.get(name)
|
|
23
|
+
if (reader) {
|
|
24
|
+
group.readers.add(name)
|
|
25
|
+
reader.group = group
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
let flush = () => {
|
|
30
|
+
queued = false
|
|
31
|
+
let wave: { names: string[]; ids: Set<string> }[] = []
|
|
32
|
+
for (let name of pending) {
|
|
33
|
+
let reader = held.get(name)
|
|
34
|
+
if (!reader) continue
|
|
35
|
+
let group = wave.at(-1)
|
|
36
|
+
let ids = new Set([...(group?.ids ?? []), ...reader.ids])
|
|
37
|
+
if (!group || ids.size > 60) {
|
|
38
|
+
group = { names: [], ids: new Set(reader.ids) }
|
|
39
|
+
wave.push(group)
|
|
40
|
+
} else group.ids = ids
|
|
41
|
+
group.names.push(name)
|
|
42
|
+
}
|
|
43
|
+
pending.clear()
|
|
44
|
+
for (let group of wave) start(group.names, [...group.ids])
|
|
45
|
+
}
|
|
46
|
+
let hold = (ids: string[]): () => void => {
|
|
47
|
+
if (!ids.length) return () => {}
|
|
48
|
+
let name = `rows:${ids.join(',')}`
|
|
49
|
+
let reader = held.get(name)
|
|
50
|
+
if (reader) reader.uses++
|
|
51
|
+
else {
|
|
52
|
+
reader = { ids: [...ids], uses: 1 }
|
|
53
|
+
held.set(name, reader)
|
|
54
|
+
if (ids.length > 60) start([name], ids)
|
|
55
|
+
else {
|
|
56
|
+
pending.add(name)
|
|
57
|
+
if (!queued) {
|
|
58
|
+
queued = true
|
|
59
|
+
let epoch = generation
|
|
60
|
+
later(() => {
|
|
61
|
+
if (epoch == generation) flush()
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let owned = reader
|
|
67
|
+
let active = true
|
|
68
|
+
return () => {
|
|
69
|
+
if (!active) return
|
|
70
|
+
active = false
|
|
71
|
+
let reader = held.get(name)
|
|
72
|
+
if (reader != owned || --reader.uses) return
|
|
73
|
+
held.delete(name)
|
|
74
|
+
pending.delete(name)
|
|
75
|
+
let group = reader.group
|
|
76
|
+
if (!group) return
|
|
77
|
+
group.readers.delete(name)
|
|
78
|
+
if (!group.readers.size) {
|
|
79
|
+
groups.delete(group.name)
|
|
80
|
+
close(group.name)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return Object.assign(hold, {
|
|
85
|
+
clear: () => {
|
|
86
|
+
generation++
|
|
87
|
+
queued = false
|
|
88
|
+
pending.clear()
|
|
89
|
+
held.clear()
|
|
90
|
+
groups.clear()
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
}
|
package/served.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Who a claude process serves: the ONE session its channel plugin delivers
|
|
2
|
+
// to. A pid names a PROCESS, not a conversation — /clear reifies a NEW
|
|
3
|
+
// session entity under the same one, so a pid can wear several rows, and
|
|
4
|
+
// the newest (latest creation stamp) is the live conversation; the rest are ghosts
|
|
5
|
+
// nothing renders for. A subagent is a tool call INSIDE its operator's
|
|
6
|
+
// process and reifies wearing no pid at all (cli.ts) — a child has no
|
|
7
|
+
// process of its own to claim.
|
|
8
|
+
//
|
|
9
|
+
// Two sides ask this question and must answer it the same: the knock
|
|
10
|
+
// ladder, deciding whether to stamp `cast` (door.ts, over SQL rows), and
|
|
11
|
+
// the channel plugin, deciding whom to deliver to (channels/tasks, over
|
|
12
|
+
// its stream index). While the copies were independent they disagreed,
|
|
13
|
+
// and a knock stamped a confident lie — `cast S-…` for a session that
|
|
14
|
+
// never heard it (T-7288). So the rule lives here, once, db-free so both
|
|
15
|
+
// may import it.
|
|
16
|
+
|
|
17
|
+
export type Seat = {
|
|
18
|
+
eid: string
|
|
19
|
+
num?: number
|
|
20
|
+
at?: string
|
|
21
|
+
pid?: number | null
|
|
22
|
+
id?: string | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// A conversation row always carries the provider's session id — reify
|
|
26
|
+
// keys on it (SessionStart, the managed launcher). A row wearing the pid
|
|
27
|
+
// WITHOUT one is an artifact (a hand-reified probe row, a malformed
|
|
28
|
+
// reify), and letting it win by recency shadows the live conversation:
|
|
29
|
+
// everything aimed at the operator session goes invisible while the
|
|
30
|
+
// channel serves a row nothing renders for (T-15147's channel half —
|
|
31
|
+
// S-14232 sat sid-less on the operator's pid and ate its comments). So
|
|
32
|
+
// the newest sid-bearing row is the seat; only a pid with no sid-bearing
|
|
33
|
+
// rows at all falls back to bare recency.
|
|
34
|
+
export let served = (seats: Seat[], pid?: number | null): Seat | undefined => {
|
|
35
|
+
if (pid == null) return undefined
|
|
36
|
+
let worn = seats.filter((s) => s.pid == pid).sort((a, b) =>
|
|
37
|
+
(b.at ?? '').localeCompare(a.at ?? '') ||
|
|
38
|
+
(!a.at && !b.at ? (b.num ?? 0) - (a.num ?? 0) : 0) ||
|
|
39
|
+
b.eid.localeCompare(a.eid)
|
|
40
|
+
)
|
|
41
|
+
return worn.find((s) => s.id) ?? worn[0]
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Display ids (S#…) are not filesystem or git-ref names. A checkout's identity
|
|
2
|
+
// is eid-derived and stays put even when the session later acquires a num.
|
|
3
|
+
export let sessionHandle = (eid)=>eid.replaceAll('-', '').slice(0, 10).toLowerCase();
|
|
4
|
+
// Recognize trees we already cut under older conventions, but never mint those
|
|
5
|
+
// spellings again. Attached branches belong to the caller, not the runner.
|
|
6
|
+
export let ownsSessionBranch = (eid, branch, num)=>!branch || branch == `session/${sessionHandle(eid)}` || branch == `session/${eid}` || branch == `session/S#${sessionHandle(eid)}` || num != null && branch == `session/S-${num}`;
|
|
7
|
+
//# sourceMappingURL=session_worktree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session_worktree.js","sources":["./session_worktree.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,2EAA2E;AAC3E,OAAO,IAAI,gBAAgB,CAAC,MAC1B,IAAI,UAAU,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,IAAI,WAAW,GAAE;AAEpD,+EAA+E;AAC/E,2EAA2E;AAC3E,OAAO,IAAI,oBAAoB,CAC7B,KACA,QACA,MAEA,CAAC,UAAU,UAAU,CAAC,QAAQ,EAAE,cAAc,MAAM,IACpD,UAAU,CAAC,QAAQ,EAAE,KAAK,IAC1B,UAAU,CAAC,UAAU,EAAE,cAAc,MAAM,IAC1C,OAAO,QAAQ,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Display ids (S#…) are not filesystem or git-ref names. A checkout's identity
|
|
2
|
+
// is eid-derived and stays put even when the session later acquires a num.
|
|
3
|
+
export let sessionHandle = (eid: string) =>
|
|
4
|
+
eid.replaceAll('-', '').slice(0, 10).toLowerCase()
|
|
5
|
+
|
|
6
|
+
// Recognize trees we already cut under older conventions, but never mint those
|
|
7
|
+
// spellings again. Attached branches belong to the caller, not the runner.
|
|
8
|
+
export let ownsSessionBranch = (
|
|
9
|
+
eid: string,
|
|
10
|
+
branch: unknown,
|
|
11
|
+
num?: number | null,
|
|
12
|
+
) =>
|
|
13
|
+
!branch || branch == `session/${sessionHandle(eid)}` ||
|
|
14
|
+
branch == `session/${eid}` ||
|
|
15
|
+
branch == `session/S#${sessionHandle(eid)}` ||
|
|
16
|
+
(num != null && branch == `session/S-${num}`)
|
package/sessions.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The session queries browse draws, in a module the socket worker can import
|
|
2
|
+
// (live.ts is the browser's): the Sessions page's history list, a session
|
|
3
|
+
// row's columns, and the columns a session's dot decides with.
|
|
4
|
+
// A session's dot, projected (D-22567 §3). A session entity's eager bag is
|
|
5
|
+
// its whole history: the final_text and usage_json and stderr of every run
|
|
6
|
+
// that ever finished, plus the created/updated/worktree/spawn provenance
|
|
7
|
+
// around them. So a dot asks for the columns it decides and paints with, and
|
|
8
|
+
// nothing else: the session's status and standing (@yaks/session), who it
|
|
9
|
+
// acts for, its process, and when it was made.
|
|
10
|
+
export let dotFields = [
|
|
11
|
+
'session.status',
|
|
12
|
+
'session.standing',
|
|
13
|
+
'session.actor',
|
|
14
|
+
'process.pid',
|
|
15
|
+
'exit.code',
|
|
16
|
+
'created.at'
|
|
17
|
+
].map((f)=>{
|
|
18
|
+
let [comp, prop] = f.split('.');
|
|
19
|
+
return {
|
|
20
|
+
comp,
|
|
21
|
+
prop,
|
|
22
|
+
wake: true
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
// What a session row paints beside its dot.
|
|
26
|
+
export let sessionFields = [
|
|
27
|
+
...dotFields.map((f)=>`${f.comp}.${f.prop}`),
|
|
28
|
+
'using.model',
|
|
29
|
+
'using.effort',
|
|
30
|
+
'doc.title',
|
|
31
|
+
'session.source',
|
|
32
|
+
'session.operator',
|
|
33
|
+
'session.transcript',
|
|
34
|
+
'native'
|
|
35
|
+
];
|
|
36
|
+
// The Sessions destination (navigation.ts): a view of the store, not a saved
|
|
37
|
+
// board or a new entity. A history list, newest first.
|
|
38
|
+
export let allSessionsPath = '/?page=sessions';
|
|
39
|
+
export let allSessionsQuery = '.session&.order=-created.at&.fields=' + sessionFields.join(',');
|
|
40
|
+
/** Session rows over this host's declared transcript and runtime columns:
|
|
41
|
+
* `detail` is a row's columns, `all` the Sessions page's history list. */ export let sessionQueries = (vocab)=>{
|
|
42
|
+
if (!vocab.comp('session')) return {
|
|
43
|
+
detail: '',
|
|
44
|
+
all: ''
|
|
45
|
+
};
|
|
46
|
+
let offered = sessionFields.filter((field)=>{
|
|
47
|
+
let [comp, prop] = field.split('.');
|
|
48
|
+
return prop ? vocab.prop(comp, prop) : vocab.comp(comp);
|
|
49
|
+
});
|
|
50
|
+
let order = vocab.prop('created', 'at') ? '&.order=-created.at' : '';
|
|
51
|
+
let detail = '.session&.fields=' + offered.join(',');
|
|
52
|
+
return {
|
|
53
|
+
detail,
|
|
54
|
+
all: detail + order
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=sessions.js.map
|
package/sessions.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions.js","sources":["./sessions.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,+DAA+D;AAG/D,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,6EAA6E;AAC7E,0EAA0E;AAC1E,+CAA+C;AAC/C,OAAO,IAAI,YAAqB;EAC9B;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,GAAG,CAAC,CAAC;EACL,IAAI,CAAC,MAAM,KAAK,GAAG,EAAE,KAAK,CAAC;EAC3B,OAAO;IAAE;IAAM;IAAM,MAAM;EAAK;AAClC,GAAE;AAEF,4CAA4C;AAC5C,OAAO,IAAI,gBAAgB;KACtB,UAAU,GAAG,CAAC,CAAC,IAAM,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE;EAC7C;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAA;AAED,6EAA6E;AAC7E,uDAAuD;AACvD,OAAO,IAAI,kBAAkB,kBAAiB;AAC9C,OAAO,IAAI,mBAAmB,yCAC5B,cAAc,IAAI,CAAC,KAAI;AAEzB;wEACwE,GACxE,OAAO,IAAI,iBAAiB,CAAC;EAC3B,IAAI,CAAC,MAAM,IAAI,CAAC,YAAY,OAAO;IAAE,QAAQ;IAAI,KAAK;EAAG;EACzD,IAAI,UAAU,cAAc,MAAM,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC;IAC/B,OAAO,OAAO,MAAM,IAAI,CAAC,MAAM,QAAQ,MAAM,IAAI,CAAC;EACpD;EACA,IAAI,QAAQ,MAAM,IAAI,CAAC,WAAW,QAAQ,wBAAwB;EAClE,IAAI,SAAS,sBAAsB,QAAQ,IAAI,CAAC;EAChD,OAAO;IAAE;IAAQ,KAAK,SAAS;EAAM;AACvC,EAAC"}
|
package/sessions.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// The session queries browse draws, in a module the socket worker can import
|
|
2
|
+
// (live.ts is the browser's): the Sessions page's history list, a session
|
|
3
|
+
// row's columns, and the columns a session's dot decides with.
|
|
4
|
+
import type { Field } from './query.ts'
|
|
5
|
+
|
|
6
|
+
// A session's dot, projected (D-22567 §3). A session entity's eager bag is
|
|
7
|
+
// its whole history: the final_text and usage_json and stderr of every run
|
|
8
|
+
// that ever finished, plus the created/updated/worktree/spawn provenance
|
|
9
|
+
// around them. So a dot asks for the columns it decides and paints with, and
|
|
10
|
+
// nothing else: the session's status and standing (@yaks/session), who it
|
|
11
|
+
// acts for, its process, and when it was made.
|
|
12
|
+
export let dotFields: Field[] = [
|
|
13
|
+
'session.status',
|
|
14
|
+
'session.standing',
|
|
15
|
+
'session.actor',
|
|
16
|
+
'process.pid',
|
|
17
|
+
'exit.code',
|
|
18
|
+
'created.at',
|
|
19
|
+
].map((f) => {
|
|
20
|
+
let [comp, prop] = f.split('.')
|
|
21
|
+
return { comp, prop, wake: true }
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// What a session row paints beside its dot.
|
|
25
|
+
export let sessionFields = [
|
|
26
|
+
...dotFields.map((f) => `${f.comp}.${f.prop}`),
|
|
27
|
+
'using.model',
|
|
28
|
+
'using.effort',
|
|
29
|
+
'doc.title',
|
|
30
|
+
'session.source',
|
|
31
|
+
'session.operator',
|
|
32
|
+
'session.transcript',
|
|
33
|
+
'native',
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
// The Sessions destination (navigation.ts): a view of the store, not a saved
|
|
37
|
+
// board or a new entity. A history list, newest first.
|
|
38
|
+
export let allSessionsPath = '/?page=sessions'
|
|
39
|
+
export let allSessionsQuery = '.session&.order=-created.at&.fields=' +
|
|
40
|
+
sessionFields.join(',')
|
|
41
|
+
|
|
42
|
+
/** Session rows over this host's declared transcript and runtime columns:
|
|
43
|
+
* `detail` is a row's columns, `all` the Sessions page's history list. */
|
|
44
|
+
export let sessionQueries = (vocab: import('jsr:@yaks/vocab@0.2.36').Vocab) => {
|
|
45
|
+
if (!vocab.comp('session')) return { detail: '', all: '' }
|
|
46
|
+
let offered = sessionFields.filter((field) => {
|
|
47
|
+
let [comp, prop] = field.split('.')
|
|
48
|
+
return prop ? vocab.prop(comp, prop) : vocab.comp(comp)
|
|
49
|
+
})
|
|
50
|
+
let order = vocab.prop('created', 'at') ? '&.order=-created.at' : ''
|
|
51
|
+
let detail = '.session&.fields=' + offered.join(',')
|
|
52
|
+
return { detail, all: detail + order }
|
|
53
|
+
}
|
package/sha.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// What a precondition compares, and what an edge is NAMED by, defined ONCE.
|
|
2
|
+
// `apply()` hashes the stored value and the caller hashes the value it read; if
|
|
3
|
+
// the two ends computed the hash with different code, a guard could pass or
|
|
4
|
+
// refuse for no reason the caller can see. apply() owns the rule, a read hands
|
|
5
|
+
// agents their token, and edge.ts derives an edge's eid from its sentence — so
|
|
6
|
+
// the function lives here rather than in any of them.
|
|
7
|
+
//
|
|
8
|
+
// A column holds text, a number or a bool in one slot, so String() is the
|
|
9
|
+
// single normalization both ends apply. null is never hashed: it IS the
|
|
10
|
+
// sentinel for "I read no value", which is how expected-absent compares equal
|
|
11
|
+
// without colliding with the hash of some value.
|
|
12
|
+
//
|
|
13
|
+
// SHA-256 written out rather than taken from `node:crypto`, because the BROWSER
|
|
14
|
+
// hashes too now: a client that mints an edge computes its eid, and a node
|
|
15
|
+
// builtin has no import-map answer on a page (browser_test walks the served
|
|
16
|
+
// graph for exactly this). WebCrypto is async and a guard token is read inline,
|
|
17
|
+
// so the algorithm itself is the portable answer. ~1µs per short value, which
|
|
18
|
+
// is the same order as the native call once the FFI hop is counted.
|
|
19
|
+
// FIPS 180-4 §4.2.2: the first 32 bits of the fractional parts of the cube
|
|
20
|
+
// roots of the first 64 primes.
|
|
21
|
+
let K = new Uint32Array([
|
|
22
|
+
0x428a2f98,
|
|
23
|
+
0x71374491,
|
|
24
|
+
0xb5c0fbcf,
|
|
25
|
+
0xe9b5dba5,
|
|
26
|
+
0x3956c25b,
|
|
27
|
+
0x59f111f1,
|
|
28
|
+
0x923f82a4,
|
|
29
|
+
0xab1c5ed5,
|
|
30
|
+
0xd807aa98,
|
|
31
|
+
0x12835b01,
|
|
32
|
+
0x243185be,
|
|
33
|
+
0x550c7dc3,
|
|
34
|
+
0x72be5d74,
|
|
35
|
+
0x80deb1fe,
|
|
36
|
+
0x9bdc06a7,
|
|
37
|
+
0xc19bf174,
|
|
38
|
+
0xe49b69c1,
|
|
39
|
+
0xefbe4786,
|
|
40
|
+
0x0fc19dc6,
|
|
41
|
+
0x240ca1cc,
|
|
42
|
+
0x2de92c6f,
|
|
43
|
+
0x4a7484aa,
|
|
44
|
+
0x5cb0a9dc,
|
|
45
|
+
0x76f988da,
|
|
46
|
+
0x983e5152,
|
|
47
|
+
0xa831c66d,
|
|
48
|
+
0xb00327c8,
|
|
49
|
+
0xbf597fc7,
|
|
50
|
+
0xc6e00bf3,
|
|
51
|
+
0xd5a79147,
|
|
52
|
+
0x06ca6351,
|
|
53
|
+
0x14292967,
|
|
54
|
+
0x27b70a85,
|
|
55
|
+
0x2e1b2138,
|
|
56
|
+
0x4d2c6dfc,
|
|
57
|
+
0x53380d13,
|
|
58
|
+
0x650a7354,
|
|
59
|
+
0x766a0abb,
|
|
60
|
+
0x81c2c92e,
|
|
61
|
+
0x92722c85,
|
|
62
|
+
0xa2bfe8a1,
|
|
63
|
+
0xa81a664b,
|
|
64
|
+
0xc24b8b70,
|
|
65
|
+
0xc76c51a3,
|
|
66
|
+
0xd192e819,
|
|
67
|
+
0xd6990624,
|
|
68
|
+
0xf40e3585,
|
|
69
|
+
0x106aa070,
|
|
70
|
+
0x19a4c116,
|
|
71
|
+
0x1e376c08,
|
|
72
|
+
0x2748774c,
|
|
73
|
+
0x34b0bcb5,
|
|
74
|
+
0x391c0cb3,
|
|
75
|
+
0x4ed8aa4a,
|
|
76
|
+
0x5b9cca4f,
|
|
77
|
+
0x682e6ff3,
|
|
78
|
+
0x748f82ee,
|
|
79
|
+
0x78a5636f,
|
|
80
|
+
0x84c87814,
|
|
81
|
+
0x8cc70208,
|
|
82
|
+
0x90befffa,
|
|
83
|
+
0xa4506ceb,
|
|
84
|
+
0xbef9a3f7,
|
|
85
|
+
0xc67178f2
|
|
86
|
+
]);
|
|
87
|
+
let utf8 = new TextEncoder();
|
|
88
|
+
let w = new Uint32Array(64);
|
|
89
|
+
let hex = Array.from({
|
|
90
|
+
length: 256
|
|
91
|
+
}, (_, i)=>i.toString(16).padStart(2, '0'));
|
|
92
|
+
// The digest of the bytes, as lowercase hex — the one shape every caller uses.
|
|
93
|
+
export let sha256 = (bytes)=>{
|
|
94
|
+
// Padding: the message, a 1 bit, zeros, then the 64-bit bit-length.
|
|
95
|
+
let len = bytes.length;
|
|
96
|
+
let blocks = (len + 8 >> 6) + 1;
|
|
97
|
+
let buf = new Uint8Array(blocks << 6);
|
|
98
|
+
buf.set(bytes);
|
|
99
|
+
buf[len] = 0x80;
|
|
100
|
+
let bits = len * 8;
|
|
101
|
+
// The length is 64 bits; a JS number carries 53, so the high word is the
|
|
102
|
+
// overflow above 2^32 rather than a shift (which would wrap at 32).
|
|
103
|
+
new DataView(buf.buffer).setUint32(buf.length - 8, Math.floor(bits / 2 ** 32));
|
|
104
|
+
new DataView(buf.buffer).setUint32(buf.length - 4, bits >>> 0);
|
|
105
|
+
// The first 32 bits of the fractional parts of the square roots of the first
|
|
106
|
+
// eight primes.
|
|
107
|
+
let h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
|
|
108
|
+
for(let i = 0; i < buf.length; i += 64){
|
|
109
|
+
for(let t = 0; t < 16; t++){
|
|
110
|
+
let j = i + t * 4;
|
|
111
|
+
w[t] = buf[j] << 24 | buf[j + 1] << 16 | buf[j + 2] << 8 | buf[j + 3];
|
|
112
|
+
}
|
|
113
|
+
for(let t = 16; t < 64; t++){
|
|
114
|
+
let a = w[t - 15], b = w[t - 2];
|
|
115
|
+
let s0 = (a >>> 7 | a << 25) ^ (a >>> 18 | a << 14) ^ a >>> 3;
|
|
116
|
+
let s1 = (b >>> 17 | b << 15) ^ (b >>> 19 | b << 13) ^ b >>> 10;
|
|
117
|
+
w[t] = w[t - 16] + s0 + w[t - 7] + s1 >>> 0;
|
|
118
|
+
}
|
|
119
|
+
let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
|
|
120
|
+
for(let t = 0; t < 64; t++){
|
|
121
|
+
let S1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
122
|
+
let ch = e & f ^ ~e & g;
|
|
123
|
+
let t1 = h + S1 + ch + K[t] + w[t] >>> 0;
|
|
124
|
+
let S0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
125
|
+
let maj = a & b ^ a & c ^ b & c;
|
|
126
|
+
let t2 = S0 + maj >>> 0;
|
|
127
|
+
h = g;
|
|
128
|
+
g = f;
|
|
129
|
+
f = e;
|
|
130
|
+
e = d + t1 >>> 0;
|
|
131
|
+
d = c;
|
|
132
|
+
c = b;
|
|
133
|
+
b = a;
|
|
134
|
+
a = t1 + t2 >>> 0;
|
|
135
|
+
}
|
|
136
|
+
h0 = h0 + a >>> 0;
|
|
137
|
+
h1 = h1 + b >>> 0;
|
|
138
|
+
h2 = h2 + c >>> 0;
|
|
139
|
+
h3 = h3 + d >>> 0;
|
|
140
|
+
h4 = h4 + e >>> 0;
|
|
141
|
+
h5 = h5 + f >>> 0;
|
|
142
|
+
h6 = h6 + g >>> 0;
|
|
143
|
+
h7 = h7 + h >>> 0;
|
|
144
|
+
}
|
|
145
|
+
let out = '';
|
|
146
|
+
for (let v of [
|
|
147
|
+
h0,
|
|
148
|
+
h1,
|
|
149
|
+
h2,
|
|
150
|
+
h3,
|
|
151
|
+
h4,
|
|
152
|
+
h5,
|
|
153
|
+
h6,
|
|
154
|
+
h7
|
|
155
|
+
]){
|
|
156
|
+
out += hex[v >>> 24 & 0xff] + hex[v >>> 16 & 0xff] + hex[v >>> 8 & 0xff] + hex[v & 0xff];
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
};
|
|
160
|
+
export let sha = (v)=>sha256(utf8.encode(String(v)));
|
|
161
|
+
//# sourceMappingURL=sha.js.map
|
package/sha.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha.js","sources":["./sha.ts"],"names":[],"mappings":"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"}
|
package/sha.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// What a precondition compares, and what an edge is NAMED by, defined ONCE.
|
|
2
|
+
// `apply()` hashes the stored value and the caller hashes the value it read; if
|
|
3
|
+
// the two ends computed the hash with different code, a guard could pass or
|
|
4
|
+
// refuse for no reason the caller can see. apply() owns the rule, a read hands
|
|
5
|
+
// agents their token, and edge.ts derives an edge's eid from its sentence — so
|
|
6
|
+
// the function lives here rather than in any of them.
|
|
7
|
+
//
|
|
8
|
+
// A column holds text, a number or a bool in one slot, so String() is the
|
|
9
|
+
// single normalization both ends apply. null is never hashed: it IS the
|
|
10
|
+
// sentinel for "I read no value", which is how expected-absent compares equal
|
|
11
|
+
// without colliding with the hash of some value.
|
|
12
|
+
//
|
|
13
|
+
// SHA-256 written out rather than taken from `node:crypto`, because the BROWSER
|
|
14
|
+
// hashes too now: a client that mints an edge computes its eid, and a node
|
|
15
|
+
// builtin has no import-map answer on a page (browser_test walks the served
|
|
16
|
+
// graph for exactly this). WebCrypto is async and a guard token is read inline,
|
|
17
|
+
// so the algorithm itself is the portable answer. ~1µs per short value, which
|
|
18
|
+
// is the same order as the native call once the FFI hop is counted.
|
|
19
|
+
|
|
20
|
+
// FIPS 180-4 §4.2.2: the first 32 bits of the fractional parts of the cube
|
|
21
|
+
// roots of the first 64 primes.
|
|
22
|
+
let K = new Uint32Array([
|
|
23
|
+
0x428a2f98,
|
|
24
|
+
0x71374491,
|
|
25
|
+
0xb5c0fbcf,
|
|
26
|
+
0xe9b5dba5,
|
|
27
|
+
0x3956c25b,
|
|
28
|
+
0x59f111f1,
|
|
29
|
+
0x923f82a4,
|
|
30
|
+
0xab1c5ed5,
|
|
31
|
+
0xd807aa98,
|
|
32
|
+
0x12835b01,
|
|
33
|
+
0x243185be,
|
|
34
|
+
0x550c7dc3,
|
|
35
|
+
0x72be5d74,
|
|
36
|
+
0x80deb1fe,
|
|
37
|
+
0x9bdc06a7,
|
|
38
|
+
0xc19bf174,
|
|
39
|
+
0xe49b69c1,
|
|
40
|
+
0xefbe4786,
|
|
41
|
+
0x0fc19dc6,
|
|
42
|
+
0x240ca1cc,
|
|
43
|
+
0x2de92c6f,
|
|
44
|
+
0x4a7484aa,
|
|
45
|
+
0x5cb0a9dc,
|
|
46
|
+
0x76f988da,
|
|
47
|
+
0x983e5152,
|
|
48
|
+
0xa831c66d,
|
|
49
|
+
0xb00327c8,
|
|
50
|
+
0xbf597fc7,
|
|
51
|
+
0xc6e00bf3,
|
|
52
|
+
0xd5a79147,
|
|
53
|
+
0x06ca6351,
|
|
54
|
+
0x14292967,
|
|
55
|
+
0x27b70a85,
|
|
56
|
+
0x2e1b2138,
|
|
57
|
+
0x4d2c6dfc,
|
|
58
|
+
0x53380d13,
|
|
59
|
+
0x650a7354,
|
|
60
|
+
0x766a0abb,
|
|
61
|
+
0x81c2c92e,
|
|
62
|
+
0x92722c85,
|
|
63
|
+
0xa2bfe8a1,
|
|
64
|
+
0xa81a664b,
|
|
65
|
+
0xc24b8b70,
|
|
66
|
+
0xc76c51a3,
|
|
67
|
+
0xd192e819,
|
|
68
|
+
0xd6990624,
|
|
69
|
+
0xf40e3585,
|
|
70
|
+
0x106aa070,
|
|
71
|
+
0x19a4c116,
|
|
72
|
+
0x1e376c08,
|
|
73
|
+
0x2748774c,
|
|
74
|
+
0x34b0bcb5,
|
|
75
|
+
0x391c0cb3,
|
|
76
|
+
0x4ed8aa4a,
|
|
77
|
+
0x5b9cca4f,
|
|
78
|
+
0x682e6ff3,
|
|
79
|
+
0x748f82ee,
|
|
80
|
+
0x78a5636f,
|
|
81
|
+
0x84c87814,
|
|
82
|
+
0x8cc70208,
|
|
83
|
+
0x90befffa,
|
|
84
|
+
0xa4506ceb,
|
|
85
|
+
0xbef9a3f7,
|
|
86
|
+
0xc67178f2,
|
|
87
|
+
])
|
|
88
|
+
|
|
89
|
+
let utf8 = new TextEncoder()
|
|
90
|
+
let w = new Uint32Array(64)
|
|
91
|
+
let hex = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'))
|
|
92
|
+
|
|
93
|
+
// The digest of the bytes, as lowercase hex — the one shape every caller uses.
|
|
94
|
+
export let sha256 = (bytes: Uint8Array): string => {
|
|
95
|
+
// Padding: the message, a 1 bit, zeros, then the 64-bit bit-length.
|
|
96
|
+
let len = bytes.length
|
|
97
|
+
let blocks = ((len + 8) >> 6) + 1
|
|
98
|
+
let buf = new Uint8Array(blocks << 6)
|
|
99
|
+
buf.set(bytes)
|
|
100
|
+
buf[len] = 0x80
|
|
101
|
+
let bits = len * 8
|
|
102
|
+
// The length is 64 bits; a JS number carries 53, so the high word is the
|
|
103
|
+
// overflow above 2^32 rather than a shift (which would wrap at 32).
|
|
104
|
+
new DataView(buf.buffer).setUint32(buf.length - 8, Math.floor(bits / 2 ** 32))
|
|
105
|
+
new DataView(buf.buffer).setUint32(buf.length - 4, bits >>> 0)
|
|
106
|
+
// The first 32 bits of the fractional parts of the square roots of the first
|
|
107
|
+
// eight primes.
|
|
108
|
+
let h0 = 0x6a09e667,
|
|
109
|
+
h1 = 0xbb67ae85,
|
|
110
|
+
h2 = 0x3c6ef372,
|
|
111
|
+
h3 = 0xa54ff53a,
|
|
112
|
+
h4 = 0x510e527f,
|
|
113
|
+
h5 = 0x9b05688c,
|
|
114
|
+
h6 = 0x1f83d9ab,
|
|
115
|
+
h7 = 0x5be0cd19
|
|
116
|
+
for (let i = 0; i < buf.length; i += 64) {
|
|
117
|
+
for (let t = 0; t < 16; t++) {
|
|
118
|
+
let j = i + t * 4
|
|
119
|
+
w[t] = (buf[j] << 24) | (buf[j + 1] << 16) | (buf[j + 2] << 8) |
|
|
120
|
+
buf[j + 3]
|
|
121
|
+
}
|
|
122
|
+
for (let t = 16; t < 64; t++) {
|
|
123
|
+
let a = w[t - 15], b = w[t - 2]
|
|
124
|
+
let s0 = ((a >>> 7) | (a << 25)) ^ ((a >>> 18) | (a << 14)) ^ (a >>> 3)
|
|
125
|
+
let s1 = ((b >>> 17) | (b << 15)) ^ ((b >>> 19) | (b << 13)) ^ (b >>> 10)
|
|
126
|
+
w[t] = (w[t - 16] + s0 + w[t - 7] + s1) >>> 0
|
|
127
|
+
}
|
|
128
|
+
let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7
|
|
129
|
+
for (let t = 0; t < 64; t++) {
|
|
130
|
+
let S1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^
|
|
131
|
+
((e >>> 25) | (e << 7))
|
|
132
|
+
let ch = (e & f) ^ (~e & g)
|
|
133
|
+
let t1 = (h + S1 + ch + K[t] + w[t]) >>> 0
|
|
134
|
+
let S0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^
|
|
135
|
+
((a >>> 22) | (a << 10))
|
|
136
|
+
let maj = (a & b) ^ (a & c) ^ (b & c)
|
|
137
|
+
let t2 = (S0 + maj) >>> 0
|
|
138
|
+
h = g
|
|
139
|
+
g = f
|
|
140
|
+
f = e
|
|
141
|
+
e = (d + t1) >>> 0
|
|
142
|
+
d = c
|
|
143
|
+
c = b
|
|
144
|
+
b = a
|
|
145
|
+
a = (t1 + t2) >>> 0
|
|
146
|
+
}
|
|
147
|
+
h0 = (h0 + a) >>> 0
|
|
148
|
+
h1 = (h1 + b) >>> 0
|
|
149
|
+
h2 = (h2 + c) >>> 0
|
|
150
|
+
h3 = (h3 + d) >>> 0
|
|
151
|
+
h4 = (h4 + e) >>> 0
|
|
152
|
+
h5 = (h5 + f) >>> 0
|
|
153
|
+
h6 = (h6 + g) >>> 0
|
|
154
|
+
h7 = (h7 + h) >>> 0
|
|
155
|
+
}
|
|
156
|
+
let out = ''
|
|
157
|
+
for (let v of [h0, h1, h2, h3, h4, h5, h6, h7]) {
|
|
158
|
+
out += hex[(v >>> 24) & 0xff] + hex[(v >>> 16) & 0xff] +
|
|
159
|
+
hex[(v >>> 8) & 0xff] + hex[v & 0xff]
|
|
160
|
+
}
|
|
161
|
+
return out
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export let sha = (v: unknown) => sha256(utf8.encode(String(v)))
|