@kriya-ai/harness 2.1.1 → 2.2.1
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 +19 -0
- package/RELEASE_NOTES.md +22 -0
- package/bin/kriya.js +43 -47
- package/bundle/cordis.patch.yml +8 -0
- package/install.sh +1 -1
- package/package.json +1 -1
- package/plugins/brand/client.js +1 -1
- package/plugins/brand/src/client.js +1 -1
- package/plugins/cockpit/client.js +89 -4
- package/plugins/cockpit/index.js +51 -24
- package/plugins/kriya-tools/index.js +3 -0
- package/plugins/remote/index.js +2 -2
- package/plugins/runstrip/index.js +1 -1
- package/src/api.js +5 -0
- package/src/edit/director/gateway.js +18 -6
- package/src/edit/director/local.js +148 -0
- package/src/edit/host/projects.js +22 -8
- package/src/edit/host/server.js +18 -5
- package/src/edit/runtime/cli.js +65 -14
- package/src/edit/runtime/doctor.js +8 -2
- package/src/edit/runtime/fetch.js +20 -4
- package/src/gateway-proxy.js +6 -2
- package/src/intent.js +2 -1
- package/src/launch.js +129 -26
- package/src/local-model.js +5 -3
- package/src/modes.js +11 -3
- package/src/own-usage.js +5 -1
- package/src/store.js +3 -0
- package/studio/dist/studio.js +3 -3
package/src/launch.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process"
|
|
2
|
+
import { readFileSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
2
4
|
|
|
3
5
|
import { broadcastRun } from "./daemon.js"
|
|
4
6
|
import { BODY_ENCODING, ORCHESTRA_ALIAS, startGatewayProxy } from "./gateway-proxy.js"
|
|
5
|
-
import { BASE_PATH, models } from "./api.js"
|
|
6
|
-
import { applyWorkforce, DEFAULT_MODE, modeEnv, SET_BY_PERSON } from "./modes.js"
|
|
7
|
+
import { BASE_PATH, KriyaError, models, unreachable } from "./api.js"
|
|
8
|
+
import { applyWorkforce, DEFAULT_MODE, modeEnv, SET_BY_PERSON, STANDALONE_SWITCHES } from "./modes.js"
|
|
7
9
|
import { LOCAL_WORKER, localWorker } from "./local-model.js"
|
|
8
10
|
import { launchOwn, ownFile, readOwn } from "./own-models.js"
|
|
9
11
|
import { usageReporter } from "./own-usage.js"
|
|
@@ -30,9 +32,10 @@ export const START_TIERS = ["balanced", "budget", "escalation"]
|
|
|
30
32
|
* When Kriya can't be asked, all of them: the gateway still refuses what
|
|
31
33
|
* the plan lacks, and a short outage mustn't leave the picker empty.
|
|
32
34
|
*/
|
|
33
|
-
export async function planTiers(device, list = models) {
|
|
35
|
+
export async function planTiers(device, list = models, { standalone = false } = {}) {
|
|
34
36
|
const all = { start: START_TIERS[0], allowed: [...START_TIERS], names: {}, limits: {}, images: [], encodings: [] }
|
|
35
|
-
if (!device) return
|
|
37
|
+
if (!device) return standaloneTiers("signed_out")
|
|
38
|
+
if (standalone) return standaloneTiers("requested")
|
|
36
39
|
try {
|
|
37
40
|
const answer = await list(device.url, device.token)
|
|
38
41
|
const data = answer.data
|
|
@@ -52,12 +55,30 @@ export async function planTiers(device, list = models) {
|
|
|
52
55
|
// Own models: the person may use their own keys and orchestration (Kriya's harness.ownModels)
|
|
53
56
|
const ownModels = answer.ownModels === 1
|
|
54
57
|
return allowed.length ? { start: allowed[0], allowed, names: modelNames(data, allowed), limits: modelLimits(data, allowed), images: allowed.filter((tier) => data.find((m) => m.id === tier)?.images === true), encodings, ...(orchestra && { orchestra }), ...(workforce && { workforce }), ...(localModels && { localModels }), ...(cockpit && { cockpit }), ...(ownModels && { ownModels }) } : { ...all, encodings }
|
|
55
|
-
} catch {
|
|
56
|
-
//
|
|
58
|
+
} catch (error) {
|
|
59
|
+
// A suspended host (Render's 503), a network error or a timeout: this computer carries on alone
|
|
60
|
+
if (unreachable(error)) return standaloneTiers("server_unreachable")
|
|
61
|
+
// Kriya refused: said as such, never bypassed (the gateway refuses every request the same way)
|
|
62
|
+
if (error instanceof KriyaError && REFUSED.has(error.status)) return { ...all, refused: { status: error.status, code: error.code, message: error.message } }
|
|
63
|
+
// Anything else: Kriya answers the first request with the reason if it's refused
|
|
57
64
|
return all
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
67
|
|
|
68
|
+
// Sign-in, suspension and version refusals: these stay Kriya's to decide
|
|
69
|
+
const REFUSED = new Set([401, 403, 426])
|
|
70
|
+
export { unreachable }
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Standalone Mode: no Kriya account, `--standalone`, or Kriya unreachable.
|
|
74
|
+
* Every Harness 2.0 feature runs on this computer, on the person's own keys and
|
|
75
|
+
* local model through the local relay; no Kriya tier is offered (none answers).
|
|
76
|
+
* @param {"signed_out" | "server_unreachable" | "requested"} reason
|
|
77
|
+
*/
|
|
78
|
+
export function standaloneTiers(reason) {
|
|
79
|
+
return { start: START_TIERS[0], allowed: [], names: {}, limits: {}, images: [], encodings: [], standalone: true, reason, workforce: true, cockpit: true, ownModels: true, localModels: true }
|
|
80
|
+
}
|
|
81
|
+
|
|
61
82
|
// The contract's own rule for a model name (contract/contract.json /models)
|
|
62
83
|
const MODEL_NAME = /^[\p{L}\p{N} .()+\/:_-]{1,60}$/u
|
|
63
84
|
|
|
@@ -116,17 +137,24 @@ export function orchestraName(orchestra, names = {}) {
|
|
|
116
137
|
return `Orchestration · ${plain(orchestra.head)} leads, ${plain(orchestra.worker)} builds`.slice(0, 120)
|
|
117
138
|
}
|
|
118
139
|
|
|
119
|
-
export function launchEnv(device, base = process.env, mode = DEFAULT_MODE, tier = START_TIERS[0], allowed = START_TIERS, names = {}, limits = {}, images = [], orchestra, pick = false, local = null, own = null) {
|
|
140
|
+
export function launchEnv(device, base = process.env, mode = DEFAULT_MODE, tier = START_TIERS[0], allowed = START_TIERS, names = {}, limits = {}, images = [], orchestra, pick = false, local = null, own = null, standalone = false) {
|
|
120
141
|
// Own models (src/own-models.js): ids, names and windows only; keys stay in the launcher's relay
|
|
121
142
|
const ownModels = pick && own?.models?.length ? own.models : []
|
|
122
143
|
const ownIds = ownModels.map((m) => m.id)
|
|
123
144
|
// The person's own orchestration, when it's the one chosen (and the relay that routes it is on)
|
|
124
145
|
const personal = Boolean(pick && own?.orchestra && orchestra === own.orchestra)
|
|
125
146
|
// S-1: a found local server builds as the owner's orchestra's worker; in the person's own, only where they chose it
|
|
126
|
-
|
|
127
|
-
const
|
|
147
|
+
// Standalone, it may also be a model of its own in the picker, with no orchestration
|
|
148
|
+
const localOn = Boolean(local && pick && (orchestra ? !personal || orchestra.worker === LOCAL_WORKER : standalone))
|
|
149
|
+
const levels = personal || !orchestra ? orchestra : localOn ? { ...orchestra, worker: LOCAL_WORKER } : orchestra
|
|
128
150
|
const named = { ...names, ...(localOn && { [LOCAL_WORKER]: `Local · ${local.model}`.slice(0, 80) }), ...Object.fromEntries(ownModels.map((m) => [m.id, m.name])) }
|
|
129
151
|
const usable = (id) => START_TIERS.includes(id) || ownIds.includes(id) || (id === LOCAL_WORKER && localOn)
|
|
152
|
+
const hidden = Boolean(standalone) && (ownIds.length > 0 || localOn)
|
|
153
|
+
// Standalone: `{ reason, keep, keepName }`; `keep` is a Kriya tier the person pinned as DSH's default
|
|
154
|
+
// model, kept in the picker (the relay sends it to their own model) so DSH doesn't refuse to start
|
|
155
|
+
const sa = standalone ? (typeof standalone === "string" ? { reason: standalone } : standalone) : null
|
|
156
|
+
const keep = hidden && START_TIERS.includes(sa?.keep) ? sa.keep : null
|
|
157
|
+
if (keep) named[keep] = `${String(sa.keepName ?? "Your model").slice(0, 50)} · your saved default`
|
|
130
158
|
const env = {
|
|
131
159
|
...base,
|
|
132
160
|
// The mode always comes from `--mode` (or the default), never the shell
|
|
@@ -137,7 +165,8 @@ export function launchEnv(device, base = process.env, mode = DEFAULT_MODE, tier
|
|
|
137
165
|
KRIYA_CLIENT_VERSION: CLIENT_VERSION,
|
|
138
166
|
KRIYA_START_TIER: START_TIERS.includes(tier) ? tier : START_TIERS[0],
|
|
139
167
|
// Read by the kriya provider row: the models the picker offers. Never from the shell
|
|
140
|
-
|
|
168
|
+
// Standalone with a model of the person's own: no Kriya tier (none would answer); "none" matches no tier
|
|
169
|
+
KRIYA_ALLOWED_TIERS: hidden ? (keep ?? "none") : (allowed.filter((t) => START_TIERS.includes(t)).length ? allowed.filter((t) => START_TIERS.includes(t)) : START_TIERS).join(","),
|
|
141
170
|
// The picker's name per tier (modelNames), as JSON. Never from the shell
|
|
142
171
|
KRIYA_MODEL_NAMES: JSON.stringify(Object.fromEntries(Object.entries(named).filter(([t, n]) => usable(t) && typeof n === "string" && n.length <= 80))),
|
|
143
172
|
// Each tier's context window, output cap and compaction headroom (modelLimits), as JSON. Never from the shell
|
|
@@ -155,6 +184,19 @@ export function launchEnv(device, base = process.env, mode = DEFAULT_MODE, tier
|
|
|
155
184
|
delete env.KRIYA_OWN_MODELS
|
|
156
185
|
delete env.KRIYA_OWN_MODEL_IDS
|
|
157
186
|
delete env.KRIYA_KEY_HASHES
|
|
187
|
+
// Standalone Mode only from the launcher, never the shell (plugins read it: src/api.js deviceFromEnv)
|
|
188
|
+
delete env.KRIYA_STANDALONE
|
|
189
|
+
delete env.KRIYA_STANDALONE_REASON
|
|
190
|
+
if (sa) {
|
|
191
|
+
env.KRIYA_STANDALONE = "on"
|
|
192
|
+
if (sa.reason) env.KRIYA_STANDALONE_REASON = sa.reason
|
|
193
|
+
}
|
|
194
|
+
// Standalone, the session starts on the person's own model, else the local one
|
|
195
|
+
if (hidden) env.KRIYA_START_TIER = ownIds[0] ?? LOCAL_WORKER
|
|
196
|
+
if (standalone && localOn) {
|
|
197
|
+
env.KRIYA_LOCAL_MODEL_ID = local.model
|
|
198
|
+
env.KRIYA_LOCAL_MODEL_LABEL = named[LOCAL_WORKER]
|
|
199
|
+
}
|
|
158
200
|
if (ownModels.length) {
|
|
159
201
|
// The picker's extra models and their windows (no key, no address), and the key hashes DSH redacts by
|
|
160
202
|
env.KRIYA_OWN_MODELS = JSON.stringify(ownModels.map((m) => ({ id: m.id, name: m.name, contextWindow: m.contextWindow })))
|
|
@@ -294,17 +336,67 @@ function relines(stream, write) {
|
|
|
294
336
|
stream.on("end", () => partial && write(rebrand(partial)))
|
|
295
337
|
}
|
|
296
338
|
|
|
339
|
+
export const STANDALONE_TOKEN = "kriya-standalone"
|
|
340
|
+
const STANDALONE_WHY = {
|
|
341
|
+
signed_out: "Not signed in to Kriya.",
|
|
342
|
+
server_unreachable: "Kriya isn't reachable right now (offline, suspended or restarting).",
|
|
343
|
+
requested: "--standalone:",
|
|
344
|
+
}
|
|
345
|
+
const REFUSAL_HINT = {
|
|
346
|
+
401: "Run kriya login to sign this device in again.",
|
|
347
|
+
403: "Ask your Kriya owner to turn Kriya Harness on, or resume the account.",
|
|
348
|
+
426: "Update Kriya Harness: npm install -g @kriya-ai/harness.",
|
|
349
|
+
}
|
|
350
|
+
const OFFLINE_CORE = "select one of your own models or the local model in the model picker (set them up in the Developer tab), or run kriya login."
|
|
351
|
+
/** What a Kriya tier answers in Standalone Mode, per reason */
|
|
352
|
+
export const OFFLINE = {
|
|
353
|
+
signed_out: `Kriya Harness is signed out, so Kriya's models aren't available: ${OFFLINE_CORE}`,
|
|
354
|
+
server_unreachable: `The Kriya server is offline, so Kriya's models aren't available: ${OFFLINE_CORE.replace("or run kriya login.", "or restart kriya once Kriya is back.")}`,
|
|
355
|
+
requested: `Kriya Harness runs with --standalone, so Kriya's models aren't available: ${OFFLINE_CORE.replace("or run kriya login.", "or restart kriya without --standalone.")}`,
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* The model the person pinned as DSH's default for this profile (Settings or the
|
|
360
|
+
* picker writes `agent-default-model` into their own patch files), when it's Kriya's
|
|
361
|
+
* provider; null otherwise. Their files are only read, never changed.
|
|
362
|
+
* shortcut: a line match on the block DSH itself writes, not a YAML parser; a hand-written
|
|
363
|
+
* flow-style row is missed (then DSH's own error says which model it lacks)
|
|
364
|
+
*/
|
|
365
|
+
export function pinnedModel(profile, home = kriyaHome()) {
|
|
366
|
+
let found = null
|
|
367
|
+
for (const file of [join(home, "profiles", profile, "cordis.patch.yml"), join(home, "cordis.patch.yml")]) {
|
|
368
|
+
let text
|
|
369
|
+
try {
|
|
370
|
+
text = readFileSync(file, "utf8")
|
|
371
|
+
} catch {
|
|
372
|
+
continue
|
|
373
|
+
}
|
|
374
|
+
const block = /^- id: agent-default-model\n((?:[ \t]+.*\n?)*)/m.exec(text)?.[1]
|
|
375
|
+
if (!block) continue
|
|
376
|
+
const provider = /^\s+provider:\s*['"]?([\w.-]+)/m.exec(block)?.[1]
|
|
377
|
+
const model = /^\s+model:\s*['"]?([\w.:\/@+-]+)/m.exec(block)?.[1]
|
|
378
|
+
// Later layers win (the home patch over the profile's)
|
|
379
|
+
if (model) found = provider === undefined || provider === "kriya" ? model : null
|
|
380
|
+
}
|
|
381
|
+
return found
|
|
382
|
+
}
|
|
383
|
+
|
|
297
384
|
/** Runs DSH in the foreground, passing the terminal through; resolves with its exit code. */
|
|
298
|
-
export async function runDsh(profile, rest, device, mode = DEFAULT_MODE) {
|
|
385
|
+
export async function runDsh(profile, rest, device, mode = DEFAULT_MODE, { standalone: asked = false } = {}) {
|
|
299
386
|
ensureProfile(profile)
|
|
300
387
|
const headless = profile === "kriya-run"
|
|
301
|
-
const tiers = await planTiers(device)
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
388
|
+
const tiers = await planTiers(device, models, { standalone: asked })
|
|
389
|
+
const { standalone } = tiers
|
|
390
|
+
const say = (text) => process.stderr.write(`kriya: ${text}\n`)
|
|
391
|
+
if (tiers.refused) say(`Kriya refused this device (${tiers.refused.status}): ${tiers.refused.message} ${REFUSAL_HINT[tiers.refused.status]}`)
|
|
392
|
+
if (standalone) say(`${STANDALONE_WHY[tiers.reason]} Standalone Mode: Harness 2.0 runs on this computer with your own API keys or a local model (Developer tab). Kriya's own models come back with kriya login${tiers.reason === "requested" ? " and without --standalone" : ""}.`)
|
|
393
|
+
// Harness 2.0: the owner's switches (standalone: this computer's), where the person set none of their own (src/modes.js applyWorkforce)
|
|
394
|
+
const turned = applyWorkforce(process.env, tiers.workforce, standalone ? STANDALONE_SWITCHES : undefined)
|
|
395
|
+
// The Developer tab from the owner's settings (standalone: always), unless the person said --no-cockpit
|
|
305
396
|
if (tiers.cockpit && !(process.env[SET_BY_PERSON] ?? "").split(",").includes("cockpit")) process.env.KRIYA_COCKPIT = "on"
|
|
306
|
-
if (turned.length)
|
|
307
|
-
|
|
397
|
+
if (turned.length) say(`Harness 2.0 is on${standalone ? "" : " from your Kriya owner settings"}: ${turned.join(", ")}. Turn one off with --no-<name>, e.g. --no-${turned[0]}.`)
|
|
398
|
+
// Standalone, the relay is the only way to a model, so KRIYA_RELAY=off doesn't apply
|
|
399
|
+
const relayOn = standalone || (Boolean(device) && process.env.KRIYA_RELAY !== "off")
|
|
308
400
|
// Own models (src/own-models.js): the person's keys and orchestration, with the owner's
|
|
309
401
|
// harness.ownModels and the relay that routes them; keys stay in this process
|
|
310
402
|
const own = tiers.ownModels && relayOn ? launchOwn(ownFile(), { allowed: tiers.allowed, local: true }) : null
|
|
@@ -317,12 +409,13 @@ export async function runDsh(profile, rest, device, mode = DEFAULT_MODE) {
|
|
|
317
409
|
const orchestrating = process.env.KRIYA_ORCHESTRA === "on" && process.env.KRIYA_LOOP === "on"
|
|
318
410
|
let orchestra = orchestrating ? (own?.orchestra ?? tiers.orchestra) : undefined
|
|
319
411
|
// S-1: `--local-model`, with the owner's offer, the orchestra and the relay (which sends the local model's requests)
|
|
320
|
-
const { local, note } = await localWorker(process.env, { offered: Boolean(tiers.localModels) && relayOn, orchestra })
|
|
321
|
-
if (note)
|
|
412
|
+
const { local, note } = await localWorker(process.env, { offered: Boolean(tiers.localModels) && relayOn, orchestra, alone: standalone })
|
|
413
|
+
if (note) say(note)
|
|
322
414
|
if (orchestra && orchestra === own?.orchestra && orchestra.worker === LOCAL_WORKER && !local) {
|
|
323
|
-
|
|
415
|
+
say(standalone ? "your orchestration builds on the local model, which isn't available now; using your models one at a time." : "your orchestration builds on the local model, which isn't available now; using Kriya's orchestration instead.")
|
|
324
416
|
orchestra = tiers.orchestra
|
|
325
417
|
}
|
|
418
|
+
if (standalone && !own?.models.length && !local) say("no model is set up yet: open the Developer tab and add an API key (OpenRouter, OpenAI, …) or start Ollama / LM Studio and run kriya --local-model, or run kriya login.")
|
|
326
419
|
if (orchestra && orchestra === own?.orchestra) {
|
|
327
420
|
const name = (id) => own.models.find((m) => m.id === id)?.name ?? (id === LOCAL_WORKER ? `Local · ${local?.model}` : tiers.names?.[id] ?? `Kriya ${id}`)
|
|
328
421
|
process.stderr.write(`kriya: your orchestration: ${name(orchestra.head)} leads, ${name(orchestra.worker)} builds.\n`)
|
|
@@ -331,28 +424,37 @@ export async function runDsh(profile, rest, device, mode = DEFAULT_MODE) {
|
|
|
331
424
|
process.env.KRIYA_OWN_MODELS_OFFER = tiers.ownModels && relayOn ? "on" : "off"
|
|
332
425
|
process.env.KRIYA_LOCAL_MODELS_OFFER = tiers.localModels && relayOn ? "on" : "off"
|
|
333
426
|
// Counts of own-key and local calls for Kriya (src/own-usage.js); never content or keys
|
|
334
|
-
|
|
427
|
+
// Standalone: a Kriya tier pinned as the default model goes to the session's own start (else DSH can't start)
|
|
428
|
+
const keepTo = standalone ? (orchestra?.head ?? own?.models[0]?.id ?? (local ? LOCAL_WORKER : null)) : null
|
|
429
|
+
const pinned = keepTo ? pinnedModel(profile) : null
|
|
430
|
+
const keep = START_TIERS.includes(pinned) ? pinned : null
|
|
431
|
+
const keepName = keep ? (own?.models.find((m) => m.id === keepTo)?.name ?? (keepTo === LOCAL_WORKER ? `Local · ${local.model}` : keepTo)) : null
|
|
432
|
+
if (keep) say(`your saved default model is Kriya ${keep}; in Standalone Mode it runs on ${keepName}.`)
|
|
433
|
+
// Standalone, nothing is sent: there is no Kriya to count for
|
|
434
|
+
const reporter = own && device && !standalone ? usageReporter({ device, log: say }) : null
|
|
335
435
|
// DSH and the Kriya plugins reach Kriya through the local relay
|
|
336
436
|
// (src/gateway-proxy.js): encoded bodies past the host's firewall, and a
|
|
337
437
|
// block said as such. KRIYA_RELAY=off talks to Kriya directly, as before
|
|
338
438
|
const relay =
|
|
339
439
|
relayOn
|
|
340
440
|
? await startGatewayProxy({
|
|
341
|
-
|
|
441
|
+
// Standalone: no Kriya behind it; only the person's own and local models answer
|
|
442
|
+
target: standalone ? null : device.url,
|
|
443
|
+
...(standalone && { offline: OFFLINE[tiers.reason] }),
|
|
342
444
|
encode: tiers.encodings.includes(BODY_ENCODING),
|
|
343
445
|
// Harness 2.0: the picker's Orchestration choice reaches Kriya as the head tier
|
|
344
|
-
...(orchestra && { aliases: { [ORCHESTRA_ALIAS]: orchestra.head } }),
|
|
446
|
+
...((orchestra || keep) && { aliases: { ...(orchestra && { [ORCHESTRA_ALIAS]: orchestra.head }), ...(keep && { [keep]: keepTo }) } }),
|
|
345
447
|
...(local && { local }),
|
|
346
448
|
...(own && { routes: own.routes }),
|
|
347
449
|
...(reporter && { onUsage: reporter.add }),
|
|
348
450
|
// A Kriya deployed after launch is picked up without a restart
|
|
349
|
-
checkSupport: async () => ((await models(device.url, device.token)).bodyEncodings ?? []).includes(BODY_ENCODING),
|
|
451
|
+
...(!standalone && { checkSupport: async () => ((await models(device.url, device.token)).bodyEncodings ?? []).includes(BODY_ENCODING) }),
|
|
350
452
|
log: (text) => process.stderr.write(`kriya: ${text}\n`),
|
|
351
453
|
})
|
|
352
454
|
: null
|
|
353
455
|
// What this process runs, for Kriya's Control Center (no task text; nothing on a Kriya without it)
|
|
354
456
|
const on = (name) => process.env[name] === "on"
|
|
355
|
-
const broadcast = broadcastRun(device, {
|
|
457
|
+
const broadcast = broadcastRun(standalone ? null : device, {
|
|
356
458
|
kind: profile === "kriya-run" ? "run" : profile === "kriya-acp" ? "acp" : "app",
|
|
357
459
|
mode,
|
|
358
460
|
switches: { loop: on("KRIYA_LOOP"), loopV2: on("KRIYA_LOOP_V2"), budget: on("KRIYA_BUDGET"), anchor: on("KRIYA_ANCHOR"), browser: on("KRIYA_BROWSER") },
|
|
@@ -362,7 +464,8 @@ export async function runDsh(profile, rest, device, mode = DEFAULT_MODE) {
|
|
|
362
464
|
// stdout: the answer (kriya run) and ACP's protocol frames pass untouched;
|
|
363
465
|
// the Web UI's stdout carries only log lines, rebranded like stderr
|
|
364
466
|
stdio: ["inherit", profile === "kriya" ? "pipe" : "inherit", "pipe"],
|
|
365
|
-
|
|
467
|
+
// Standalone: a stand-in token (DSH's route needs one; the relay never sends it anywhere)
|
|
468
|
+
env: launchEnv(relay ? { ...(standalone ? { token: STANDALONE_TOKEN } : device), url: relay.url } : device, process.env, mode, orchestra ? orchestra.head : tiers.start, tiers.allowed, tiers.names, tiers.limits, tiers.images, orchestra, Boolean(relay), local ?? null, own, standalone && { reason: tiers.reason, keep, keepName }),
|
|
366
469
|
})
|
|
367
470
|
let explained = null
|
|
368
471
|
const filter = htmlFilter((text) => process.stderr.write(rebrand(text)))
|
package/src/local-model.js
CHANGED
|
@@ -96,13 +96,15 @@ export function localModelArgs(args, env = process.env) {
|
|
|
96
96
|
* orchestra is on (the local model only builds), and a server answered.
|
|
97
97
|
* @returns {Promise<{ local?: { url: string, model: string, server: string }, note?: string }>}
|
|
98
98
|
*/
|
|
99
|
-
export async function localWorker(env, { offered, orchestra }, find = findLocalModel) {
|
|
99
|
+
export async function localWorker(env, { offered, orchestra, alone = false }, find = findLocalModel) {
|
|
100
100
|
const asked = env.KRIYA_LOCAL_MODEL
|
|
101
101
|
if (!asked || asked === "off") return {}
|
|
102
102
|
if (!offered) return { note: "local models aren't turned on for your Kriya account yet (the owner's harness.localModels); using Kriya's models." }
|
|
103
|
-
|
|
103
|
+
// Standalone, the local model may run the whole session by itself
|
|
104
|
+
if (!orchestra && !alone) return { note: "a local model builds the orchestra's worker steps, and the orchestra is off; using Kriya's models." }
|
|
104
105
|
const found = await find({ url: asked === "on" ? undefined : asked, name: env.KRIYA_LOCAL_MODEL_NAME || undefined })
|
|
105
|
-
if ("error" in found) return { note: `${found.error} Using Kriya's models
|
|
106
|
+
if ("error" in found) return { note: `${found.error} ${alone ? "Using your own models only." : "Using Kriya's models."}` }
|
|
107
|
+
if (!orchestra) return { local: found, note: `${found.model} (${found.server}, ${found.url}) runs on this computer; choose it in the model picker.` }
|
|
106
108
|
return {
|
|
107
109
|
local: found,
|
|
108
110
|
note: `${found.model} (${found.server}, ${found.url}) builds on this computer; Kriya's ${orchestra.head} plans, reviews and takes over when it's stuck.${found.server === "Ollama" ? " Give Ollama a 32k context: OLLAMA_CONTEXT_LENGTH=32768 ollama serve." : ""}`,
|
package/src/modes.js
CHANGED
|
@@ -212,17 +212,25 @@ export function switchEnv(args, env = process.env, saved = savedSwitches()) {
|
|
|
212
212
|
*/
|
|
213
213
|
export const WORKFORCE_SWITCHES = Object.freeze(["cartridges", "orchestra", "gates", "critic", "milestones", "grounding", "explore", "runstrip", "mcp"])
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Standalone Mode (no Kriya account, or Kriya unreachable): the Harness 2.0
|
|
217
|
+
* switches that run on this computer alone. MCP reads the owner's registry
|
|
218
|
+
* from Kriya, so it stays off.
|
|
219
|
+
*/
|
|
220
|
+
export const STANDALONE_SWITCHES = Object.freeze(WORKFORCE_SWITCHES.filter((flag) => flag !== "mcp"))
|
|
221
|
+
|
|
215
222
|
/**
|
|
216
223
|
* Turns on the owner's Harness 2.0 switches the person didn't set, when Kriya
|
|
217
|
-
* advertises them
|
|
224
|
+
* advertises them (or Standalone Mode, with its own list). Without the
|
|
225
|
+
* advertisement nothing changes (HT-REG).
|
|
218
226
|
* @returns {string[]} the switches this turned on
|
|
219
227
|
*/
|
|
220
|
-
export function applyWorkforce(env = process.env, advertised = false) {
|
|
228
|
+
export function applyWorkforce(env = process.env, advertised = false, list = WORKFORCE_SWITCHES) {
|
|
221
229
|
if (!advertised) return []
|
|
222
230
|
const chosen = new Set((env[SET_BY_PERSON] ?? "").split(",").filter(Boolean))
|
|
223
231
|
const turned = []
|
|
224
232
|
for (const [flag, name] of SWITCHES) {
|
|
225
|
-
if (!
|
|
233
|
+
if (!list.includes(flag) || chosen.has(flag) || env[name] === "on") continue
|
|
226
234
|
env[name] = "on"
|
|
227
235
|
turned.push(flag)
|
|
228
236
|
}
|
package/src/own-usage.js
CHANGED
|
@@ -17,6 +17,8 @@ export function usageReporter({ device, post = (body) => call(device.url, "POST"
|
|
|
17
17
|
const pending = new Map()
|
|
18
18
|
let stopped = false
|
|
19
19
|
let flushing = null
|
|
20
|
+
// One line per outage, not one every FLUSH_MS
|
|
21
|
+
let warned = false
|
|
20
22
|
const add = (e) => {
|
|
21
23
|
if (stopped || !e?.provider || !e?.model) return
|
|
22
24
|
const key = `${e.provider}\0${e.model}`
|
|
@@ -36,6 +38,7 @@ export function usageReporter({ device, post = (body) => call(device.url, "POST"
|
|
|
36
38
|
for (const e of batch) pending.delete(`${e.provider}\0${e.model}`)
|
|
37
39
|
try {
|
|
38
40
|
await post({ entries: batch.map((e) => ({ ...e, requests: Math.min(e.requests, 10_000) })) })
|
|
41
|
+
warned = false
|
|
39
42
|
} catch (error) {
|
|
40
43
|
if (error instanceof KriyaError && error.status === 404) {
|
|
41
44
|
stopped = true
|
|
@@ -44,7 +47,8 @@ export function usageReporter({ device, post = (body) => call(device.url, "POST"
|
|
|
44
47
|
}
|
|
45
48
|
// Kept for the next try, bounded
|
|
46
49
|
for (const e of batch) if (pending.size < MAX_KEYS) pending.set(`${e.provider}\0${e.model}`, e)
|
|
47
|
-
log(`own-model usage not sent yet (${error?.code ?? error?.message ?? "error"}); will retry`)
|
|
50
|
+
if (!warned) log(`own-model usage not sent yet (${error?.code ?? error?.message ?? "error"}); will retry quietly`)
|
|
51
|
+
warned = true
|
|
48
52
|
return
|
|
49
53
|
}
|
|
50
54
|
}
|
package/src/store.js
CHANGED
|
@@ -31,6 +31,9 @@ export function readDevice() {
|
|
|
31
31
|
return null
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/** Inside DSH: the sign-in, unless the launcher started in Standalone Mode (Kriya unreachable or --standalone) */
|
|
35
|
+
export const activeDevice = (env = process.env) => (env.KRIYA_STANDALONE === "on" ? null : readDevice())
|
|
36
|
+
|
|
34
37
|
/** @param {{ url: string, token: string, deviceId: string }} device */
|
|
35
38
|
export function writeDevice(device) {
|
|
36
39
|
ensureHome()
|