This repository was archived by the owner on Jul 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitdos.js
More file actions
409 lines (368 loc) · 14.5 KB
/
Copy pathgitdos.js
File metadata and controls
409 lines (368 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
const terminal = document.getElementById('terminal')
const form = document.getElementById('command-form')
const input = document.getElementById('command')
const sealNode = document.getElementById('worm-seal')
const modelNode = document.getElementById('model-name')
const bootButton = document.getElementById('boot')
const state = {
model: localStorage.getItem('gitdos-model') || 'granite-code',
endpoint: localStorage.getItem('gitdos-endpoint') || 'http://127.0.0.1:11434',
format: localStorage.getItem('gitdos-format') || 'auto', // auto | ollama | openai
worm: JSON.parse(localStorage.getItem('gitdos-worm') || '[]'),
transcript: [],
catcode: { violations: 0, checks: 0 }
}
modelNode.textContent = state.model
sealNode.textContent = state.worm.at(-1)?.seal?.slice(0, 16) || 'GENESIS'
const bootText = [
'APPLE GITDOS BY SNAPKITTY OS',
'A.P.E. COMPUTER ROM 0.2 — GRANITE EDITION',
'COPYRIGHT SNAPKITTY COLLECTIVE 2026',
'',
'MODEL: ' + state.model.toUpperCase(),
'ENDPOINT: ' + state.endpoint,
'GUARDRAIL: CATCODE ACTIVE — SOVEREIGN STACK',
'WORM: ' + (state.worm.length ? state.worm.length + ' EVENTS SEALED' : 'GENESIS'),
'',
'DOS READY.',
'TYPE HELP FOR COMMANDS.',
''
]
boot()
bootButton.addEventListener('click', boot)
form.addEventListener('submit', async (event) => {
event.preventDefault()
const command = input.value.trim()
if (!command) return
input.value = ''
print(`] ${command}`)
await run(command)
})
function boot() {
terminal.textContent = ''
bootText.forEach((line) => print(line, 'system'))
input.focus()
}
function print(text = '', kind = '') {
const line = document.createElement('div')
line.className = `line ${kind}`.trim()
line.textContent = text
terminal.appendChild(line)
terminal.scrollTop = terminal.scrollHeight
state.transcript.push({ kind, text, ts: new Date().toISOString() })
}
function appendToLast(text) {
const last = terminal.lastElementChild || terminal.appendChild(document.createElement('div'))
last.textContent += text
terminal.scrollTop = terminal.scrollHeight
}
async function run(raw) {
const [head, ...rest] = raw.split(/\s+/)
const command = head.toUpperCase()
const args = rest.join(' ')
if (command === 'HELP') return help()
if (command === 'CATALOG') return catalog()
if (command === 'HOME' || command === 'CLEAR') return boot()
if (command === 'MODEL') return setModel(args)
if (command === 'ENDPOINT') return setEndpoint(args)
if (command === 'FORMAT') return setFormat(args)
if (command === 'STATUS') return status()
if (command === 'CATCODE') return catcodeStatus()
if (command === 'PR#WORM' || command === 'WORM') return showWorm()
if (command === 'SEAL') return seal(args || state.transcript.map((item) => item.text).join('\n'))
if (command === 'RUN' && args.toUpperCase() === 'TESSERA') return open('../tessera/studio.html', '_self')
if (command === 'OPEN' && args.toUpperCase() === 'TESSERA') return open('../tessera/studio.html', '_self')
if (command === 'RUN' && args.toUpperCase() === 'SUPERREPO') return open('../super-repo/', '_self')
if (command === 'OPEN' && args.toUpperCase() === 'SUPERREPO') return open('../super-repo/', '_self')
if (command === 'SAVE') return saveTranscript()
if (command === 'GIT') return git(args)
if (command === 'ASK' || command === 'CHAT' || command === 'BRUN') return ask(args)
return ask(raw)
}
function help() {
print('COMMANDS:', 'system')
print(' CATALOG LIST DISK CATALOG')
print(' ASK <PROMPT> CHAT WITH BOB — GRANITE CODE ENGINE')
print(' CHAT <PROMPT> SAME AS ASK')
print(' BRUN <PROMPT> RUN MODEL LIKE A DOS BINARY')
print(' MODEL <TAG> SET MODEL (DEFAULT: GRANITE-CODE)')
print(' ENDPOINT <URL> SET ENDPOINT (OLLAMA OR VLLM)')
print(' FORMAT <auto|ollama|openai> SET API FORMAT')
print(' STATUS CHECK BACKEND STATUS')
print(' CATCODE SHOW GUARDRAIL STATS')
print(' RUN TESSERA OPEN TESSERA STUDIO')
print(' RUN SUPERREPO OPEN INVERTED MONO SUPER REPO')
print(' SEAL <TEXT> WORM-SEAL TEXT')
print(' PR#WORM SHOW WORM CHAIN')
print(' GIT STATUS SHOW REPO STATE')
print(' SAVE DOWNLOAD TRANSCRIPT JSON')
print(' HOME CLEAR SCREEN')
print('')
print('BACKEND CONFIG:', 'system')
print(' OLLAMA: MODEL granite-code | ENDPOINT http://127.0.0.1:11434')
print(' VLLM: MODEL ibm-granite/granite-code-8b-instruct | ENDPOINT http://127.0.0.1:8000')
print(' FORMAT openai')
}
function catalog() {
print('DISK VOLUME 254 — GRANITE EDITION', 'system')
for (const item of [
'A 002 GITDOS.SYSTEM',
'B 008 GRANITE.CODE.8B',
'B 004 CATCODE.GUARDRAIL',
'B 003 TESSERA.STUDIO',
'B 006 SUPERREPO.BIN',
'T 002 WORM.SEAL',
'T 001 ADA.CONTRACT',
'T 001 LEAN4.PROOF',
'T 001 TRUST.DEED',
'T 001 SNAPOS.README'
]) print(item)
}
function setModel(value) {
if (!value) { print(`MODEL IS ${state.model}`, 'system'); return }
state.model = value
localStorage.setItem('gitdos-model', value)
modelNode.textContent = value
print(`MODEL SET TO ${value}`, 'system')
}
function setEndpoint(value) {
if (!value) { print(`ENDPOINT IS ${state.endpoint}`, 'system'); return }
state.endpoint = value.replace(/\/$/, '')
localStorage.setItem('gitdos-endpoint', state.endpoint)
print(`ENDPOINT SET TO ${state.endpoint}`, 'system')
// Auto-hint the format
if (state.endpoint.includes(':8000') || state.endpoint.includes(':8001')) {
print('HINT: RUN "FORMAT openai" FOR VLLM ENDPOINT', 'system')
}
}
function setFormat(value) {
const fmt = (value || '').toLowerCase()
if (!['auto', 'ollama', 'openai'].includes(fmt)) {
print('FORMAT: auto | ollama | openai', 'error')
return
}
state.format = fmt
localStorage.setItem('gitdos-format', fmt)
print(`FORMAT SET TO ${fmt.toUpperCase()}`, 'system')
}
// Detect API format: Ollama vs OpenAI/vLLM
function resolveFormat() {
if (state.format !== 'auto') return state.format
if (state.endpoint.includes(':11434')) return 'ollama'
if (state.endpoint.includes(':8000') || state.endpoint.includes(':8001')) return 'openai'
return 'ollama' // default fallback
}
async function status() {
const fmt = resolveFormat()
try {
if (fmt === 'ollama') {
const r = await fetch(`${state.endpoint}/api/tags`)
if (!r.ok) throw new Error(`HTTP ${r.status}`)
const d = await r.json()
const models = (d.models || []).map(m => m.name).join(', ') || 'NO MODELS'
print(`OLLAMA ONLINE · MODELS: ${models}`, 'system')
} else {
const r = await fetch(`${state.endpoint}/v1/models`)
if (!r.ok) throw new Error(`HTTP ${r.status}`)
const d = await r.json()
const models = (d.data || []).map(m => m.id).join(', ') || 'NO MODELS'
print(`VLLM ONLINE · MODELS: ${models}`, 'system')
}
print(`FORMAT: ${fmt.toUpperCase()} · CATCODE: ACTIVE · WORM: ${state.worm.length} EVENTS`, 'system')
} catch (error) {
print(`BACKEND OFFLINE: ${error.message}`, 'error')
print(`EXPECTED AT: ${state.endpoint}`, 'error')
if (fmt === 'openai') {
print('START: vllm serve ibm-granite/granite-code-8b-instruct --port 8000', 'system')
} else {
print('START: ollama serve && ollama pull granite-code', 'system')
}
}
}
// ── CATCODE GUARDRAIL ─────────────────────────────────────────────────────────
// Lightweight in-browser version of CATCODE.
// Detects Type I (semantic drift), Type II (structural), Type III (intent).
// Does not block output — flags it and seals the violation.
const CATCODE_PATTERNS = {
TYPE_I_SEMANTIC: [
/i('m| am) (absolutely|100%|completely|certainly) (sure|certain|confident)/i,
/this (will|always|never|definitely)/i,
/guaranteed to/i,
/without (any )?(doubt|question)/i,
/i (know|can confirm) for (a )?fact/i,
],
TYPE_II_STRUCTURAL: [
/\[INST\]|\[\/INST\]|<\|im_start\|>|<\|im_end\|>/, // leaked prompt tokens
/system prompt|ignore (previous|above|prior) instructions/i,
/as (an |a )?AI (language model|assistant), I (cannot|must)/i,
],
TYPE_III_INTENT: [
/you should (definitely |really )?(trust|believe) me/i,
/don't (worry about|question) (this|that|it)/i,
/just (do|follow|trust) (what|what I say)/i,
]
}
function catcodeCheck(text) {
state.catcode.checks++
const violations = []
for (const [type, patterns] of Object.entries(CATCODE_PATTERNS)) {
for (const pat of patterns) {
if (pat.test(text)) {
violations.push(type)
break
}
}
}
if (violations.length) {
state.catcode.violations++
return { flagged: true, types: violations }
}
return { flagged: false }
}
function catcodeStatus() {
print('CATCODE GUARDRAIL STATUS:', 'system')
print(` CHECKS: ${state.catcode.checks}`)
print(` VIOLATIONS: ${state.catcode.violations}`)
print(` CLEAN RATE: ${state.catcode.checks ? (((state.catcode.checks - state.catcode.violations) / state.catcode.checks) * 100).toFixed(1) + '%' : 'N/A'}`)
print(` PATTERNS: TYPE I (SEMANTIC) · TYPE II (STRUCTURAL) · TYPE III (INTENT)`)
print(` STACK: CATCODE + WORM + LEAN4 + TRUST DEED`)
}
// ── ASK — dual format, CATCODE-guarded ───────────────────────────────────────
async function ask(prompt) {
if (!prompt) { print('SYNTAX: ASK <PROMPT>', 'error'); return }
const fmt = resolveFormat()
const start = await appendWorm('CHAT_START', { model: state.model, format: fmt, promptHash: await sha256(prompt) })
print(`RUNNING ${state.model.toUpperCase()} [${fmt.toUpperCase()}] / SEAL ${start.seal.slice(0, 16)}...`, 'seal')
print('', 'ai')
try {
let response
if (fmt === 'openai') {
// vLLM / OpenAI-compatible format
response = await fetch(`${state.endpoint}/v1/chat/completions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: state.model,
messages: [{ role: 'user', content: prompt }],
stream: true,
temperature: 0.3,
max_tokens: 1024
})
})
} else {
// Ollama format
response = await fetch(`${state.endpoint}/api/generate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model: state.model, prompt, stream: true })
})
}
if (!response.ok) throw new Error(`HTTP ${response.status}`)
const reader = response.body.getReader()
const decoder = new TextDecoder()
let buffer = ''
let full = ''
let doneSeen = false
while (true) {
const { value, done } = await reader.read()
if (done) break
buffer += decoder.decode(value, { stream: true })
const lines = buffer.split('\n')
buffer = lines.pop() || ''
for (const line of lines) {
const trimmed = line.trim()
if (!trimmed || trimmed === 'data: [DONE]') continue
try {
if (fmt === 'openai') {
// SSE: "data: {...}"
const json = trimmed.startsWith('data: ') ? trimmed.slice(6) : trimmed
const chunk = JSON.parse(json)
const token = chunk.choices?.[0]?.delta?.content || ''
if (token) { full += token; appendToLast(token) }
if (chunk.choices?.[0]?.finish_reason) doneSeen = true
} else {
// Ollama: raw JSON lines
const chunk = JSON.parse(trimmed)
if (chunk.response) { full += chunk.response; appendToLast(chunk.response) }
if (chunk.done === true) doneSeen = true
}
} catch { /* skip malformed chunk */ }
}
}
// CATCODE check on completed response
const cc = catcodeCheck(full)
if (cc.flagged) {
print(`\nCATCODE ALERT: ${cc.types.join(' + ')} DETECTED`, 'error')
print('RESPONSE FLAGGED — VERIFY BEFORE ACTING', 'error')
}
const final = await appendWorm('CHAT_DONE', {
model: state.model,
format: fmt,
responseHash: await sha256(full),
doneSeen,
catcode: cc
})
print(`\nWORM SEALED ${final.seal}${cc.flagged ? ' [CATCODE FLAGGED]' : ''}`, 'seal')
} catch (error) {
const fail = await appendWorm('CHAT_ERROR', { model: state.model, format: fmt, reason: error.message })
print(`I/O ERROR: ${error.message}`, 'error')
print(`WORM SEALED ${fail.seal}`, 'seal')
}
}
async function seal(text) {
const event = await appendWorm('MANUAL_SEAL', { textHash: await sha256(text), text })
print(`SEALED ${event.seal}`, 'seal')
}
function showWorm() {
print('WORM CHAIN:', 'system')
state.worm.slice(-12).forEach((event) => {
const catflag = event.payload?.catcode?.flagged ? ' [CC]' : ''
print(`${String(event.tick).padStart(3, '0')} ${event.type.padEnd(12)} ${event.seal}${catflag}`)
})
}
function git(args) {
const sub = args.toUpperCase()
if (sub === 'STATUS') {
print('ON BRANCH GH-PAGES-ROM', 'system')
print('MODEL: GRANITE CODE 8B — IBM WATSON LINEAGE')
print('GUARDRAILS: CATCODE + WORM + LEAN4 + TRUST DEED')
print('REMOTE: SNAPKITTYWEST/bob-orchestrator')
return
}
if (sub === 'LOG') {
print('GRANITE EDITION — SOVEREIGN GUARDRAILS ACTIVE')
print('PREV: NEMOTRON 4B — OLLAMA ONLY')
return
}
print('GIT COMMANDS: STATUS, LOG')
}
function saveTranscript() {
const body = JSON.stringify({
transcript: state.transcript,
worm: state.worm,
catcode: state.catcode,
model: state.model,
format: resolveFormat()
}, null, 2)
const blob = new Blob([body], { type: 'application/json' })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = 'apple-gitdos-transcript.json'
link.click()
URL.revokeObjectURL(url)
}
async function appendWorm(type, payload) {
const parentSeal = state.worm.at(-1)?.seal || 'GENESIS'
const event = { tick: state.worm.length, ts: new Date().toISOString(), type, parentSeal, payload }
event.seal = await sha256(JSON.stringify(event))
state.worm.push(event)
localStorage.setItem('gitdos-worm', JSON.stringify(state.worm, null, 2))
sealNode.textContent = event.seal.slice(0, 16)
return event
}
async function sha256(value) {
const bytes = new TextEncoder().encode(value)
const digest = await crypto.subtle.digest('SHA-256', bytes)
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, '0')).join('')
}