robisie 0.2.1 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # Historia zmian klienta / Client changelog
2
2
 
3
+ ## [0.3.0](https://github.com/chuppa12/robisie-app/compare/client-v0.2.2...client-v0.3.0) (2026-11-10)
4
+
5
+
6
+ ### Features
7
+
8
+ * **client:** npx robisie login + poprawki 0.2.3 (NIE SCALAĆ przed migracją 0060) ([b384bfb](https://github.com/chuppa12/robisie-app/commit/b384bfb303bd35440bb2ee8d210ade4bd8cd9b30))
9
+ * **client:** wire login into init, doctor and launcher (E3b) ([1905ded](https://github.com/chuppa12/robisie-app/commit/1905ded276a9cc3bbf6cc3dcaab51ebe06507415))
10
+ * **login:** E3a — klient parowania kodem urządzenia (nowe pliki) ([906c6fb](https://github.com/chuppa12/robisie-app/commit/906c6fbddfcfd9df0d732338bd5643fb5653a971))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **client:** doctor i init nie chodza po przodkach katalogu stanu; smoke wydania inicjuje instalacje ([a77d7a2](https://github.com/chuppa12/robisie-app/commit/a77d7a203954d7ebf4396b621d9474546a6c90d9))
16
+ * **client:** keep uninstall without a manifest a no-op (existing contract) ([92e6cfc](https://github.com/chuppa12/robisie-app/commit/92e6cfccd80f322e8edea0937cca1c0d94620487))
17
+ * **client:** uninstall removes login files and keys; docs: retry/abandon via panel (E3b) ([0e82de2](https://github.com/chuppa12/robisie-app/commit/0e82de22fa5cec4797de97697b673b74c31dac7b))
18
+ * **receiver:** local receiver passes --reasoning-effort low (grok 1.0.13 rejects none) ([813f036](https://github.com/chuppa12/robisie-app/commit/813f03684bd75fd0deb8b7f002e8eee6407355fc))
19
+ * serialize device login with a persistent SQLite mutex ([b73aef8](https://github.com/chuppa12/robisie-app/commit/b73aef849326bb6c68ad6a981b6b12052571401a))
20
+
21
+ ## [0.2.2](https://github.com/chuppa12/robisie-app/compare/client-v0.2.1...client-v0.2.2) (2026-11-10)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * **client:** 8f - jednolity szablon listy ochrony, przyczyna bledu konfiguracji, symlinki w stateDir ([e2a036a](https://github.com/chuppa12/robisie-app/commit/e2a036a55e3ee15236be76fbd896b02977fa7ccf))
27
+ * **client:** 8f - kontrakt paczki i domkniecie silnika po poprawkach recenzji ([83aa6f3](https://github.com/chuppa12/robisie-app/commit/83aa6f39fa35c0e4db896c862d116eee52ebd33e))
28
+ * **client:** 8f - szersza domyslna lista ochrony testera i porada z --engine-config ([9c388e3](https://github.com/chuppa12/robisie-app/commit/9c388e312a2198ef7407870d3445d62d2bf20670))
29
+ * **client:** doctor mówi prawdę o logowaniu pary Codex–Grok ([d8b0c3b](https://github.com/chuppa12/robisie-app/commit/d8b0c3bb71bf2b56325de8e9961cbf0345c197ae))
30
+ * **client:** doctor says the truth about the Codex–Grok pair login ([8787fe2](https://github.com/chuppa12/robisie-app/commit/8787fe259a78b3250d6075e30769878cd3bb6a47))
31
+ * **client:** init i doctor przygotowują wejścia lokalnego silnika (8f) ([7e374cb](https://github.com/chuppa12/robisie-app/commit/7e374cb264b92257e3e5566938c405e7321f019f))
32
+ * **client:** init i doctor przygotowują wejścia lokalnego silnika (8f) ([e511456](https://github.com/chuppa12/robisie-app/commit/e5114561e5855aa217476f71015c17e8fba00379))
33
+ * **client:** silnik na Linuksie - autor commitu, restart hosta, dostawa FF w drzewie, powody odmowy ([c5cfce5](https://github.com/chuppa12/robisie-app/commit/c5cfce56ecdcc4993f9095d89a6f5eabc3bf539e))
34
+ * **client:** silnik na Linuksie - autor commitu, restart hosta, dostawa FF w drzewie, powody odmowy ([dd7d5e5](https://github.com/chuppa12/robisie-app/commit/dd7d5e529b72360b1bdeb174af539cf1ae9d388e))
35
+ * **client:** type the doctor login env for the root typecheck ([3534724](https://github.com/chuppa12/robisie-app/commit/3534724a7924766030272884da008a02364b411f))
36
+
3
37
  ## [0.2.1](https://github.com/chuppa12/robisie-app/compare/client-v0.2.0...client-v0.2.1) (2026-11-09)
4
38
 
5
39
 
package/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # robisie
2
2
 
3
+ W katalogu projektu z konfiguracją silnika uruchom `npx robisie init`, potem `npx robisie doctor`: init przygotuje cel projektu i listę ochrony testera, a doctor sprawdzi oba wejścia.
4
+
3
5
  Przewodniki: [PL — konto → odbiór → odinstalowanie](docs/README.md) · [EN — account → acceptance → uninstall](docs/README.en.md). Przygotuj Node.js 24+ (wydanie użyte przy sprawdzeniach: 24.3.0), npm, program jednego dostawcy AI oraz pusty katalog; silnik w paczce (`dist/engine/tick.cjs`) wymaga systemu Linux. Nie potrzebujesz strony ani własnego pliku `package.json` — utworzy go poniższy krok Node.js przed instalacją. Zacznij od konta i projektu w panelu. Projekt w panelu i katalog na dysku to osobne rzeczy; CEO wymaga dokładnie jednego projektu z `list_projects`.
4
6
 
5
- Konto i klucz są potrzebne do init i pracy ról. Osobne wejście to walidacja offline, gdy CLI jest dostępne: nie sprawdza instalacji, nie uruchamia dostawców i nie wymaga podawania UUID projektu. Osobno `npx robisie doctor --engine-config ./robisie.config.json` sprawdza offline tylko strukturę: nie potwierdza UUID projektu, repo, modeli ani uruchomienia dostawców. Lokalne przewodniki są w `node_modules/robisie/docs/`.
7
+ Konto i klucz są potrzebne do init i pracy ról. Osobne wejście to walidacja offline, gdy CLI jest dostępne: nie sprawdza instalacji, nie uruchamia dostawców i nie wymaga podawania UUID projektu. Osobno `npx robisie doctor --engine-config ./robisie.config.json` sprawdza offline strukturę konfiguracji i wejścia instalacji lokalnej: nie potwierdza UUID projektu, repo, modeli ani uruchomienia dostawców. Lokalne przewodniki są w `node_modules/robisie/docs/`.
8
+
9
+ Zamiast przepisywać klucze możesz uruchomić `npx robisie login`: polecenie wypisuje kod i link, Ty albo Twój agent zatwierdzacie parę kluczy A i B w przeglądarce zalogowanej do robisie.app, a klucze trafiają prosto do plików instalacji — w wersji dla testerów agent i właściciel na tym komputerze to jedna strefa zaufania (agent ma technicznie dostęp także do klucza B).
6
10
 
7
11
  ## Przed init — konto i pierwszy projekt
8
12
 
@@ -119,7 +123,7 @@ Po Connect, init i wczytaniu klucza według bloku powyżej uruchom `npx robisie
119
123
 
120
124
  - **0 projektów, exit 1:** `CEO wymaga dokładnie 1 projektu (projektów: 0).` Następny krok: `Sprawdź gotowość projektu na https://robisie.app/dashboard/plugins/planer.` Wróć do przygotowania projektu opisanego przed init.
121
125
  - **Więcej niż 1 projekt, exit 1** (np. `CEO wymaga dokładnie 1 projektu (projektów: 2).`): Uporządkuj widoczność projektów w `list_projects` do 1; sam wybór projektu w panelu nie zmienia wyniku `list_projects`. Człowiek sam decyduje, który projekt zachować aktywny; przy pozostałych na liście wybiera „Archiwizuj”. „Archiwum” → „Przywróć” cofa archiwizację. Nie usuwaj projektów. Kliknięcie projektu nie zawęża wyniku `list_projects`.
122
- - **1 projekt:** oczekuj dokładnie `✓ Połączenie działa: klucz otwiera tablicę (projektów: 1).` oraz końcowego `Wszystko działa. Uruchom swojego agenta i poproś o rolę robisie CEO.` i exit 0.
126
+ - **1 projekt:** oczekuj dokładnie `✓ Połączenie działa: klucz otwiera tablicę (projektów: 1).` oraz końcowego `Powyższe kontrole przeszły. Uruchom swojego agenta i poproś o rolę robisie CEO.` i exit 0. Linia `Gotowość wykonawców Codex–Grok:` mówi osobno, czy gotowość wykonawców jest `sprawdzona` (Grok tylko „prawdopodobnie zalogowany”), `niegotowa` czy `NIE SPRAWDZONO`.
123
127
 
124
128
  Po zmianie ponów `npx robisie doctor`. Rozwiąż też inne błędy doctor: sam licznik 1 nie wystarcza bez końcowego komunikatu sukcesu i exit 0.
125
129
 
package/dist/cli.d.ts CHANGED
@@ -14,6 +14,10 @@ export interface ParsedArgs {
14
14
  engineConfig: string | null;
15
15
  interval: number;
16
16
  once: boolean;
17
+ /** login: false = `--no-wait`. */
18
+ wait: boolean;
19
+ /** login: `--timeout` seconds; null = DEFAULT_LOGIN_TIMEOUT_SECONDS. */
20
+ timeout: number | null;
17
21
  }
18
22
  export declare function parseArgs(argv: readonly string[]): ParsedArgs;
19
23
  export declare function run(argv: readonly string[], ctx: Ctx): Promise<number>;
package/dist/cli.js CHANGED
@@ -1,16 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  import { lstatSync, realpathSync } from "node:fs";
3
+ import { resolve } from "node:path";
3
4
  import { fileURLToPath } from "node:url";
4
5
  import { AGENT_IDS, isAgentId } from "./agents.js";
5
6
  import { doctor, init, recoveryStep, uninstall } from "./commands.js";
6
7
  import { HELPER_SERVERS, PACKAGE_VERSION } from "./constants.js";
7
8
  import { RobisieError, errorMessage, nodeCtx } from "./context.js";
9
+ import { DEFAULT_LOGIN_TIMEOUT_SECONDS } from "./device-login.js";
8
10
  import { runFactory } from "./factory-run.js";
11
+ import { checkInputs, inputDirectory, INPUTS_OK } from "./engine-inputs.js";
9
12
  import { isHelperServer, runHelper } from "./helpers.js";
13
+ import { closeInstallation, initNeedsLogin, login, openInstallation } from "./login.js";
10
14
  import { ROLE_IDS, ROLE_STEP } from "./manifest.js";
11
15
  import { doctorEngineConfig } from "./role-registry.js";
12
16
  const HELP = `robisie ${PACKAGE_VERSION} — łączy Twojego agenta z tablicą robisie
13
17
 
18
+ npx robisie login paruje instalację: kod i link zatwierdzasz w przeglądarce, klucze A i B trafiają prosto do plików
14
19
  npx robisie init klucze A (ROBISIE_KEY) i B (ROBISIE_REVIEW_KEY), osobne ukryte pytania + konfiguracja MCP + role klienta
15
20
  npx robisie doctor sprawdza A i B, wersję kontraktu i role; enforced: NIE SPRAWDZONO
16
21
  npx robisie uninstall usuwa wpisy robisie i role; zachowuje kopie zapasowe
@@ -26,7 +31,7 @@ Opcje factory run:
26
31
  Ctrl+C zatrzymuje nadzorcę i grupę taktu; odłączone joby mogą działać dalej.
27
32
 
28
33
  Opcje doctor:
29
- --engine-config <path> offline sprawdza strukturę konfiguracji projektu i przypisania czterech ról wykonania
34
+ --engine-config <path> offline sprawdza strukturę konfiguracji projektu i przypisania czterech ról wykonania oraz wejścia instalacji lokalnej
30
35
  --engine-config=<path> ta sama składnia; nie sprawdza uruchomienia dostawców
31
36
  Przykład: npx robisie doctor --engine-config ./robisie.config.json
32
37
  Bez klucza i kontroli instalacji; nie sprawdza UUID projektu, repo, dostępności modeli ani wykonania komend.
@@ -34,11 +39,20 @@ Opcje doctor:
34
39
  Przewodniki i przykłady: node_modules/robisie/docs/README.md oraz README.en.md w tym samym katalogu.
35
40
 
36
41
  Opcje init:
42
+ --engine-config <path> konfiguracja lokalnego silnika; init przygotuje brakujące wejścia projektu
37
43
  --agent <${AGENT_IDS.join("|")}> wybrany dostawca (można powtórzyć albo podać po przecinku); razem z dostawcami mapy, bez --agent również wykryci
38
44
  --role <rola=dostawca> wybór ceo, builder, quality → claude, codex, opencode (można powtórzyć)
39
45
  --role=rola=dostawca ta sama składnia; np. --role=builder=codex zachowuje resztę mapy
40
46
  --no-shell nie dopisuj ROBISIE_KEY i ROBISIE_REVIEW_KEY do profilu powłoki
41
47
  --key-stdin weź tylko klucz A z wejścia standardowego (np. printenv KLUCZ | npx robisie init --key-stdin)
48
+ Bez kluczy, bez terminala i bez --key-stdin init najpierw uruchamia npx robisie login.
49
+
50
+ Opcje login:
51
+ --no-wait tylko wypisz kod i link (albo wznów czekające parowanie) i zakończ kodem 2
52
+ --timeout <sekundy> ile czekać na zatwierdzenie: 1–3600, domyślnie ${DEFAULT_LOGIN_TIMEOUT_SECONDS}; także --timeout=600
53
+ Kody wyjścia: 0 = zalogowano (para zapisana i potwierdzona), 2 = parowanie czeka na zatwierdzenie
54
+ (to jeszcze nie jest zalogowanie — wznów: npx robisie login), 1 = błąd z następnym krokiem.
55
+ Po zalogowaniu init, doctor i factory run biorą klucze z plików instalacji, nie ze starego ENV.
42
56
  `;
43
57
  export function parseArgs(argv) {
44
58
  const args = [...argv];
@@ -52,9 +66,11 @@ export function parseArgs(argv) {
52
66
  let interval = 120;
53
67
  let intervalSet = false;
54
68
  let once = false;
69
+ let wait = true;
70
+ let timeout = null;
55
71
  // Help wins over everything else, so `init --help` never starts an install.
56
72
  if (argv.includes("--help") || argv.includes("-h"))
57
- return { command, help: true, target, agents: null, roles, shell, keyStdin, engineConfig, interval, once };
73
+ return { command, help: true, target, agents: null, roles, shell, keyStdin, engineConfig, interval, once, wait, timeout };
58
74
  if (command === "factory") {
59
75
  target = args.shift() ?? null;
60
76
  if (target !== "run")
@@ -69,8 +85,8 @@ export function parseArgs(argv) {
69
85
  }
70
86
  if (arg === "--engine-config" || arg.startsWith("--engine-config=")) {
71
87
  const step = "Użyj `npx robisie doctor --engine-config <path>` z jedną niepustą ścieżką pliku.";
72
- if (command !== "doctor" && command !== "factory")
73
- throw new RobisieError("Opcja --engine-config jest dostępna tylko dla poleceń doctor i factory run.", step);
88
+ if (command !== "init" && command !== "doctor" && command !== "factory")
89
+ throw new RobisieError("Opcja --engine-config jest dostępna tylko dla poleceń init, doctor i factory run.", step);
74
90
  if (engineConfig !== null)
75
91
  throw new RobisieError("Opcję --engine-config można podać tylko raz.", step);
76
92
  const value = arg === "--engine-config" ? args.shift() ?? "" : arg.slice("--engine-config=".length);
@@ -125,14 +141,24 @@ export function parseArgs(argv) {
125
141
  }
126
142
  else if (command === "mcp" && target === null && !arg.startsWith("-"))
127
143
  target = arg;
144
+ else if (command === "login" && arg === "--no-wait")
145
+ wait = false;
146
+ else if (command === "login" && (arg === "--timeout" || arg.startsWith("--timeout="))) {
147
+ const value = arg === "--timeout" ? args.shift() ?? "" : arg.slice("--timeout=".length);
148
+ if (timeout !== null || !/^\d+$/.test(value) || Number(value) < 1 || Number(value) > 3600) {
149
+ throw new RobisieError("Opcja --timeout wymaga jednej liczby całkowitej sekund 1–3600.", "Zobacz `npx robisie help`.");
150
+ }
151
+ timeout = Number(value);
152
+ }
128
153
  else
129
154
  throw new RobisieError("Nieznana opcja argumentów CLI.", "Zobacz `npx robisie help`.");
130
155
  }
131
156
  if (once && intervalSet)
132
157
  throw new RobisieError("Opcje --once i --interval wykluczają się.", "Zobacz `npx robisie help`.");
133
- return { command, help: false, target, agents: agents.length > 0 ? agents : null, roles, shell, keyStdin, engineConfig, interval, once };
158
+ return { command, help: false, target, agents: agents.length > 0 ? agents : null, roles, shell, keyStdin, engineConfig, interval, once, wait, timeout };
134
159
  }
135
160
  export async function run(argv, ctx) {
161
+ let release = null;
136
162
  try {
137
163
  if (Number(process.versions.node.split(".")[0]) < 24) {
138
164
  throw new RobisieError("Polecenia robisie wymagają Node.js >=24.", "Zainstaluj Node.js 24 lub nowszy i ponów polecenie.");
@@ -142,13 +168,40 @@ export async function run(argv, ctx) {
142
168
  ctx.out(HELP);
143
169
  return 0;
144
170
  }
171
+ if (args.command === "login")
172
+ return await login(ctx, { wait: args.wait, timeoutSeconds: args.timeout ?? undefined });
173
+ if (args.command === "init" && initNeedsLogin(ctx, args.keyStdin)) {
174
+ const code = await login(ctx, { wait: true });
175
+ if (code !== 0)
176
+ return code;
177
+ }
178
+ const held = args.command === "init" ? "init"
179
+ : args.command === "factory" ? "factory run"
180
+ : args.command === "doctor" && args.engineConfig === null ? "doctor" : null;
181
+ if (held) {
182
+ const opened = await openInstallation(ctx, held);
183
+ ctx = opened.ctx;
184
+ release = opened.release;
185
+ // factory run holds the lock only while it reads the pair, never while the engine runs.
186
+ if (held === "factory run" && release) {
187
+ closeInstallation(ctx, release);
188
+ release = null;
189
+ }
190
+ }
145
191
  switch (args.command) {
146
192
  case "init":
147
- await init(ctx, { agents: args.agents, roles: args.roles, shell: args.shell, keyStdin: args.keyStdin });
193
+ await init(ctx, { agents: args.agents, roles: args.roles, shell: args.shell, keyStdin: args.keyStdin, ...(args.engineConfig === null ? {} : { engineConfig: args.engineConfig }) });
148
194
  return 0;
149
195
  case "doctor":
150
- if (args.engineConfig !== null)
151
- return doctorEngineConfig(ctx, args.engineConfig);
196
+ if (args.engineConfig !== null) {
197
+ const configPath = resolve(ctx.cwd, args.engineConfig);
198
+ return doctorEngineConfig(ctx, args.engineConfig, config => {
199
+ if (config.engine.delivery === "local") {
200
+ checkInputs(inputDirectory(config), configPath);
201
+ ctx.out(INPUTS_OK);
202
+ }
203
+ });
204
+ }
152
205
  if (ctx.env.ROBISIE_KEY) {
153
206
  try {
154
207
  // Match the helper's directory rules without executing its code in doctor.
@@ -199,6 +252,10 @@ export async function run(argv, ctx) {
199
252
  }
200
253
  return 1;
201
254
  }
255
+ finally {
256
+ if (release)
257
+ closeInstallation(ctx, release);
258
+ }
202
259
  }
203
260
  function isEntry() {
204
261
  try {
@@ -8,11 +8,19 @@ export interface InitOptions {
8
8
  /** Read the key from piped stdin — only on request, so an open non-TTY stdin can never hang init. */
9
9
  keyStdin: boolean;
10
10
  rolesDir?: string;
11
+ engineConfig?: string | null;
11
12
  }
12
13
  /** Advice chooses an executable CLI, not merely a leftover configuration directory. */
13
14
  export declare function initRecoveryStep(ctx: Ctx, preferred?: AgentId): string;
14
15
  export declare function recoveryStep(ctx: Ctx, step: string): string;
15
16
  export declare function init(ctx: Ctx, options: InitOptions): Promise<void>;
17
+ export declare const DOCTOR_SUCCESS = "Powy\u017Csze kontrole przesz\u0142y. Uruchom swojego agenta i popro\u015B o rol\u0119 robisie CEO.";
18
+ /** Provider CLI runs are replaceable so tests touch no real CLI or network. Output is never read or printed. */
19
+ export declare const loginIo: {
20
+ run(binary: string, args: readonly string[], env: NodeJS.ProcessEnv, cwd: string): {
21
+ status: number | null;
22
+ };
23
+ };
16
24
  /** Returns the process exit code: 0 = all good, 1 = something needs one action. */
17
25
  export declare function doctor(ctx: Ctx): Promise<number>;
18
26
  export declare function uninstall(ctx: Ctx): number;
package/dist/commands.js CHANGED
@@ -1,15 +1,19 @@
1
- import { lstatSync, readdirSync, rmdirSync, rmSync } from "node:fs";
1
+ import { spawnSync } from "node:child_process";
2
+ import { accessSync, constants, lstatSync, readdirSync, rmdirSync, rmSync, statSync } from "node:fs";
3
+ import { delimiter, join, resolve } from "node:path";
2
4
  import { parse } from "smol-toml";
3
5
  import { AGENT_IDS, AGENT_LABELS, SHELL_EXPORT, agentPaths, agentOnPath, detectAgents, planAgent, removeCodexTables, shellProfile } from "./agents.js";
4
6
  import { HELPER_SERVERS, KEY_ENV, KEY_PATTERN, PACKAGE_NAME, PACKAGE_VERSION } from "./constants.js";
5
7
  import { RobisieError, errorMessage } from "./context.js";
6
8
  import { assertCodexEnvironment } from "./codex-env.js";
9
+ import { loginFiles } from "./device-login.js";
7
10
  import { reportDoctorDisk } from "./disk-guard.js";
8
11
  import { applyOp, assertCodexChange, checkRecovery, preserveFileStep, capture, entryPresent, fingerprint, prepareBlock, refusePrivateSymlink, renderBlock, restore, undoEntry } from "./fsops.js";
9
12
  import { HELPER_TOOLS, probeHelper } from "./helpers.js";
10
- import { clientPaths, ensurePrivateDir, readKey, readManifest, writeKey, writeManifest, roleProviders, ROLE_IDS, ROLE_STEP } from "./manifest.js";
13
+ import { clientPaths, ensurePrivateDir, loginFields, readKey, readManifest, writeKey, writeManifest, roleProviders, ROLE_IDS, ROLE_STEP } from "./manifest.js";
11
14
  import { assertCompatible, checkConnection, fetchContractVersion } from "./mcp.js";
12
15
  import { loadRoles, MANAGED_LINE, rolesDir } from "./roles.js";
16
+ import { checkInputs, createInputs, INPUTS_OK, preflightInputs, selectInputDirectory } from "./engine-inputs.js";
13
17
  const NO_KEY_STEP = "Wygeneruj klucz worker na https://robisie.app/dashboard/connect; w zsh/bash wykonaj `unset ROBISIE_KEY`, potem lokalne `npx robisie init` i wklej klucz w ukrytym pytaniu (poza rozmową).";
14
18
  const KEY_FORMAT_STEP = `Skopiuj klucz jeszcze raz z https://robisie.app/dashboard/connect; ustaw poprawny ROBISIE_KEY w środowisku lokalnego init (poza rozmową i historią poleceń) albo przekaż klucz przez stdin z jawną flagą: \`npx robisie init --key-stdin\` (poza rozmową i historią poleceń). Następnie wczytaj zapisany klucz do bieżącej sesji POSIX z tym samym XDG_CONFIG_HOME: \`${SHELL_EXPORT}\`, potem uruchom \`npx robisie doctor\`.`;
15
19
  const ENV_KEY_FORMAT_STEP = `W zsh/bash wykonaj \`unset ROBISIE_KEY\` — ENV ma pierwszeństwo przed pytaniem, stdin i plikiem. ${KEY_FORMAT_STEP}`;
@@ -90,10 +94,15 @@ async function obtainKey(ctx, keyStdin, prior) {
90
94
  return key;
91
95
  }
92
96
  export async function init(ctx, options) {
97
+ const inputs = selectInputDirectory(ctx, options.engineConfig);
98
+ if (inputs)
99
+ preflightInputs(inputs.directory, inputs.configPath);
93
100
  const paths = clientPaths(agentPaths(ctx).clientDir);
94
101
  const prior = readManifest(paths.manifest);
95
- const detected = options.agents ?? prior?.agents ?? detectAgents(ctx);
96
- const previousMap = prior ? roleProviders(prior) : roleProviders({ agents: detected });
102
+ // A manifest written only by `npx robisie login` records no agent choice yet.
103
+ const chosen = prior?.agents.length ? prior : null;
104
+ const detected = options.agents ?? chosen?.agents ?? detectAgents(ctx);
105
+ const previousMap = chosen ? roleProviders(chosen) : roleProviders({ agents: detected });
97
106
  let map = previousMap;
98
107
  if (options.roles && Object.keys(options.roles).length > 0) {
99
108
  const merged = { ...previousMap, ...options.roles };
@@ -132,12 +141,14 @@ export async function init(ctx, options) {
132
141
  prepareBlock(before.bytes?.toString("utf8") ?? null, op.comment, op.clean, op.body);
133
142
  checkRecovery(op, priorById.get(entryId(op)));
134
143
  }
144
+ if (inputs)
145
+ createInputs(inputs.directory, inputs.configPath);
135
146
  ensurePrivateDir(paths.dir);
136
147
  const done = new Map(priorById);
137
148
  const agents = [...new Set([...(prior?.agents ?? []), ...selected])];
138
149
  let changed = 0;
139
150
  // The record first, then the key and the changes: a disk that fills up cannot leave a key or a change uninstall does not know about.
140
- writeManifest(paths.dir, { agents, roleProviders: map, entries: [...done.values()] });
151
+ writeManifest(paths.dir, { ...loginFields(prior), agents, roleProviders: map, entries: [...done.values()] });
141
152
  writeKey(paths.dir, key);
142
153
  writeKey(paths.dir, reviewKey, "review-key");
143
154
  for (const { owner, op } of planned) {
@@ -148,7 +159,7 @@ export async function init(ctx, options) {
148
159
  done.set(id, { ...applied.entry, owner });
149
160
  try {
150
161
  // Recorded after every change (atomically), so even a killed init leaves uninstall a complete record.
151
- writeManifest(paths.dir, { agents, roleProviders: map, entries: [...done.values()] });
162
+ writeManifest(paths.dir, { ...loginFields(prior), agents, roleProviders: map, entries: [...done.values()] });
152
163
  }
153
164
  catch (error) {
154
165
  // The change is not on record, so uninstall could never undo it: take it back before failing.
@@ -246,6 +257,72 @@ function installedVersions(op, text) {
246
257
  return [];
247
258
  }
248
259
  // ── doctor ───────────────────────────────────────────────────────────────────
260
+ export const DOCTOR_SUCCESS = "Powyższe kontrole przeszły. Uruchom swojego agenta i poproś o rolę robisie CEO.";
261
+ /** Provider CLI runs are replaceable so tests touch no real CLI or network. Output is never read or printed. */
262
+ export const loginIo = {
263
+ run(binary, args, env, cwd) {
264
+ const result = spawnSync(binary, args, { cwd, env, stdio: "ignore", timeout: 20_000, killSignal: "SIGKILL", shell: false });
265
+ return { status: result.error ? null : result.status };
266
+ },
267
+ };
268
+ // The engine's provider env (engine-context/review-job allowlists), never the robisie keys.
269
+ const PAIR_ENV = ["HOME", "PATH", "TMPDIR", "USER", "LOGNAME", "SHELL", "LANG", "LC_ALL", "TERM", "NO_COLOR", "CODEX_HOME", "XDG_CONFIG_HOME"];
270
+ function findProgram(cwd, path, name) {
271
+ for (const dir of path.split(delimiter)) {
272
+ if (!dir)
273
+ continue;
274
+ const candidate = resolve(cwd, dir, name);
275
+ try {
276
+ if (!statSync(candidate).isFile())
277
+ continue;
278
+ accessSync(candidate, constants.X_OK);
279
+ return candidate;
280
+ }
281
+ catch {
282
+ // not here — keep looking
283
+ }
284
+ }
285
+ return null;
286
+ }
287
+ /** Login of the client execution pair (Codex worker, Grok reviewer) as the engine starts them. */
288
+ function pairReadiness(ctx, fail) {
289
+ const home = ctx.env.HOME || ctx.home;
290
+ const env = {};
291
+ for (const name of PAIR_ENV)
292
+ if (ctx.env[name] !== undefined)
293
+ env[name] = ctx.env[name];
294
+ env.HOME = home;
295
+ const grokEnv = { ...env, PATH: `${join(home, ".local/bin")}${delimiter}${env.PATH ?? ""}` };
296
+ const retry = "Potem ponów `npx robisie doctor`.";
297
+ let unchecked = false;
298
+ let failed = false;
299
+ const codex = findProgram(ctx.cwd, env.PATH ?? "", "codex");
300
+ if (!codex) {
301
+ unchecked = true;
302
+ ctx.out("! Codex: brak programu codex w PATH — logowania NIE SPRAWDZONO.");
303
+ }
304
+ else if (loginIo.run(codex, ["login", "status"], env, ctx.cwd).status === 0) {
305
+ ctx.out(`✓ Codex zalogowany (\`codex login status\`, HOME=${home}).`);
306
+ }
307
+ else {
308
+ failed = true;
309
+ fail(`Codex nie jest zalogowany w środowisku silnika (HOME=${home}).`, `Zaloguj Codex: \`codex login --device-auth\`. ${retry}`);
310
+ }
311
+ // Grok CLI has no login-status command; `grok models` lists models without a paid model call.
312
+ const grok = findProgram(ctx.cwd, grokEnv.PATH, "grok");
313
+ if (!grok) {
314
+ unchecked = true;
315
+ ctx.out("! Grok: brak programu grok w PATH — logowania NIE SPRAWDZONO.");
316
+ }
317
+ else if (loginIo.run(grok, ["models"], grokEnv, ctx.cwd).status === 0) {
318
+ ctx.out(`✓ Grok prawdopodobnie zalogowany (\`grok models\` działa; Grok CLI nie ma polecenia statusu logowania; HOME=${home}).`);
319
+ }
320
+ else {
321
+ failed = true;
322
+ fail(`Grok: nie potwierdzono zalogowania w środowisku silnika (HOME=${home}; \`grok models\` zakończył się błędem).`, `Zaloguj Grok: \`grok login --device-auth\`. ${retry}`);
323
+ }
324
+ return failed ? "niegotowa" : unchecked ? "NIE SPRAWDZONO" : "sprawdzona (Grok: prawdopodobnie zalogowany)";
325
+ }
249
326
  /** Returns the process exit code: 0 = all good, 1 = something needs one action. */
250
327
  export async function doctor(ctx) {
251
328
  ctx.out("! Polityka enforced: NIE SPRAWDZONO — klient nie ma API jej odczytu.");
@@ -267,6 +344,13 @@ export async function doctor(ctx) {
267
344
  };
268
345
  ctx.out(`Paczka ${PACKAGE_NAME} ${PACKAGE_VERSION}`);
269
346
  const paths = clientPaths(agentPaths(ctx).clientDir);
347
+ await guard(async () => {
348
+ const inputs = selectInputDirectory(ctx);
349
+ if (inputs) {
350
+ checkInputs(inputs.directory, inputs.configPath);
351
+ ctx.out(INPUTS_OK);
352
+ }
353
+ });
270
354
  // Same 15 HOLD / 18 unblock thresholds as the packaged engine (engine-context disk()).
271
355
  const disk = reportDoctorDisk(ctx.out, ctx.cwd);
272
356
  if (!disk.ok && disk.nextStep)
@@ -418,7 +502,7 @@ export async function doctor(ctx) {
418
502
  tools = await probeHelper(name, ctx.env, ctx.cwd);
419
503
  }
420
504
  catch (error) {
421
- throw new RobisieError(`Pomocnik ${name} nie działa na tym komputerze: ${errorMessage(error)}`, "Sprawdź Node.js (wymagany 20+). Przeinstaluj paczkę z npm w katalogu instalacji: `npm i robisie@latest`, potem lokalne `npx robisie init` i `npx robisie doctor`.");
505
+ throw new RobisieError(`Pomocnik ${name} nie działa na tym komputerze: ${errorMessage(error)}`, "Sprawdź Node.js (wymagany 24+). Przeinstaluj paczkę z npm w katalogu instalacji: `npm i robisie@latest`, potem lokalne `npx robisie init` i `npx robisie doctor`.");
422
506
  }
423
507
  const absent = HELPER_TOOLS[name].filter((tool) => !tools.includes(tool));
424
508
  if (absent.length > 0)
@@ -429,8 +513,9 @@ export async function doctor(ctx) {
429
513
  }
430
514
  if (!envKey)
431
515
  fail(`Zmienna ${KEY_ENV} nie jest ustawiona — role i agenci jej potrzebują.`, `Jeśli init zapisał profil zsh/bash, otwórz nowy terminal z tym samym XDG_CONFIG_HOME. Przy --no-shell/innej powłoce ustaw środowisko agenta bez ujawniania klucza; w powłoce POSIX: ${SHELL_EXPORT}`);
516
+ ctx.out(`Gotowość wykonawców Codex–Grok: ${pairReadiness(ctx, fail)}.`);
432
517
  if (problems.length === 0) {
433
- ctx.out("Wszystko działa. Uruchom swojego agenta i poproś o rolę robisie CEO.");
518
+ ctx.out(DOCTOR_SUCCESS);
434
519
  return 0;
435
520
  }
436
521
  ctx.out(`Następny krok: ${problems[0]}`);
@@ -511,6 +596,8 @@ export function uninstall(ctx) {
511
596
  for (const dir of [paths.codexRoles, paths.roles])
512
597
  if (!removeEmptyDir(dir))
513
598
  leftovers.push(dir);
599
+ for (const path of loginFiles(paths.dir))
600
+ rmSync(path, { force: true });
514
601
  // The ledger lives inside paths.dir, so only the final rmdir requires removing it first.
515
602
  try {
516
603
  rmSync(paths.manifest, { force: true });
@@ -1,6 +1,6 @@
1
1
  /** Package identity and the server contract it speaks. */
2
2
  export declare const PACKAGE_NAME = "robisie";
3
- export declare const PACKAGE_VERSION = "0.2.1";
3
+ export declare const PACKAGE_VERSION = "0.3.0";
4
4
  /**
5
5
  * MAJOR of the agent-API contract this package understands.
6
6
  * PARITY: src/lib/mcp/contract-version.ts (AGENT_API_CONTRACT_VERSION) on the server.
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Package identity and the server contract it speaks. */
2
2
  export const PACKAGE_NAME = "robisie";
3
- export const PACKAGE_VERSION = "0.2.1"; // x-release-please-version
3
+ export const PACKAGE_VERSION = "0.3.0"; // x-release-please-version
4
4
  /**
5
5
  * MAJOR of the agent-API contract this package understands.
6
6
  * PARITY: src/lib/mcp/contract-version.ts (AGENT_API_CONTRACT_VERSION) on the server.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Dostawa lokalna (P4-a): scalenie karty do gałęzi celu bez GitHuba.
3
3
  * Kolejność: prepare (merge-tree --write-tree, bez dotykania drzewa roboczego) → check (komendy wywołującego)
4
- * → deliver (tylko fast-forward, `update-ref` z oczekiwaną starą wartością = CAS) → attachEvidence (notatki git).
4
+ * → deliver (tylko fast-forward: merge w wyewidencjonowanym drzewie, poza nim CAS update-ref) → attachEvidence (notatki git).
5
5
  * Żadna funkcja nie rzuca wyjątku z powodu gita ani komend — każdy wynik jest jawną wartością.
6
6
  * check uruchamia komendy w tymczasowym, odłączonym worktree na `taskSha` (poza repo klienta), sprzątanym zawsze w `finally`;
7
7
  * porażka sprzątania daje `cleanup-failed` (z zachowanymi wynikami komend), nigdy ukryte `ok: true`.
@@ -120,5 +120,5 @@ export declare function readEvidence(repo: string, kind: EvidenceKind, sha: stri
120
120
  reason: "invalid-kind" | "evidence-read-failed" | "error";
121
121
  message: string;
122
122
  };
123
- /** Adapter `local-ff` (domyślny): scalenie lokalne wyłącznie przez fast-forward z CAS. */
123
+ /** Adapter `local-ff` (domyślny): fast-forward w drzewie celu albo CAS niewyewidencjonowanego refa. */
124
124
  export declare function createLocalFfDelivery(repo: string): Delivery;
@@ -1,15 +1,23 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import { mkdtempSync, rmSync } from "node:fs";
3
- import { tmpdir } from "node:os";
3
+ import { devNull, tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { gitCommitOptions } from "./git-commit.js";
5
6
  export const EVIDENCE_KINDS = ["review", "test", "deliver"];
6
7
  export const DEFAULT_DELIVERY_ADAPTER = "local-ff";
7
8
  const SHA_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
8
9
  const OUTPUT_LIMIT = 4000;
9
10
  function runGit(repo, args, input) {
10
- const result = spawnSync("git", args, {
11
+ let options;
12
+ try {
13
+ options = args[0] === "notes" && args.includes("add") ? gitCommitOptions(args, repo) : { args, env: process.env };
14
+ }
15
+ catch (error) {
16
+ return { status: null, stdout: "", stderr: "", error: error instanceof Error ? error : new Error(String(error)) };
17
+ }
18
+ const result = spawnSync("git", options.args, {
11
19
  cwd: repo, encoding: "utf8", input, timeout: 60_000, maxBuffer: 20 * 1024 * 1024, shell: false,
12
- env: { ...process.env, LC_ALL: "C", GIT_TERMINAL_PROMPT: "0" },
20
+ env: { ...options.env, LC_ALL: "C", GIT_TERMINAL_PROMPT: "0" },
13
21
  });
14
22
  return { status: result.status, stdout: result.stdout ?? "", stderr: result.stderr ?? "", error: result.error };
15
23
  }
@@ -198,7 +206,20 @@ function deliver(repo, prepared) {
198
206
  if (typeof worktree === "object")
199
207
  return { ok: false, reason: "error", message: `git worktree list nie powiodło się: ${gitText(worktree)}` };
200
208
  if (worktree !== undefined) {
201
- return { ok: false, reason: "target-checked-out", message: `Odmowa: gałąź ${prepared.target} jest wyewidencjonowana w ${worktree}; przesunięcie refa rozjechałoby jej drzewo robocze.` };
209
+ const before = resolveCommit(repo, ref);
210
+ if (before !== targetSha) {
211
+ return { ok: false, reason: "target-moved", message: `Odmowa: ${prepared.target} przesunął się z ${targetSha} na ${before ?? "(brak)"} po prepare; nic nie zmieniono.` };
212
+ }
213
+ const merge = runGit(worktree, ["-c", `core.hooksPath=${devNull}`, "merge", "--ff-only", "--no-autostash", "--no-overwrite-ignore", taskSha]);
214
+ const after = resolveCommit(repo, ref);
215
+ if (after === taskSha)
216
+ return { ok: true, moved: true, ref, from: targetSha, to: taskSha };
217
+ if (after === targetSha) {
218
+ // Porada gita o commicie przesunęłaby main; zachowujemy błąd i listę plików, bez ogona z poradami.
219
+ const diagnostic = gitText(merge).replace(/\n(?:Please commit\b|Another git process seems to be running in this repository, e\.g\.)[\s\S]*$/, "").trim();
220
+ return { ok: false, reason: "target-checked-out", message: `Odmowa FF w ${worktree}: ${diagnostic}\nOdłóż zmiany (git stash) albo cofnij je i ponów dostawę.` };
221
+ }
222
+ return { ok: false, reason: "target-moved", message: `Odmowa: ${prepared.target} po próbie FF wskazuje ${after ?? "(brak)"} zamiast ${taskSha}; sprawdź stan repozytorium.` };
202
223
  }
203
224
  const update = runGit(repo, ["update-ref", "--no-deref", "-m", `robisie: dostawa local-ff ${taskSha}`, ref, taskSha, targetSha]);
204
225
  if (update.status !== 0) {
@@ -275,7 +296,7 @@ export function readEvidence(repo, kind, sha) {
275
296
  }
276
297
  return { ok: true, entries };
277
298
  }
278
- /** Adapter `local-ff` (domyślny): scalenie lokalne wyłącznie przez fast-forward z CAS. */
299
+ /** Adapter `local-ff` (domyślny): fast-forward w drzewie celu albo CAS niewyewidencjonowanego refa. */
279
300
  export function createLocalFfDelivery(repo) {
280
301
  return {
281
302
  prepare: input => prepare(repo, input),
@@ -0,0 +1,48 @@
1
+ import { type Ctx } from "./context.js";
2
+ export declare const DEFAULT_LOGIN_TIMEOUT_SECONDS = 540;
3
+ export interface LoginIo {
4
+ now: () => number;
5
+ sleep: (ms: number) => Promise<void>;
6
+ hostname: string;
7
+ /** Legacy injection kept for callers; PID liveness never controls the SQLite mutex. */
8
+ processAlive: (pid: number, startedAt: number) => boolean;
9
+ }
10
+ export interface NewPair {
11
+ key: string;
12
+ installationId: string;
13
+ pairId: string;
14
+ }
15
+ /**
16
+ * The other places holding A (J5: `~/.claude.json` header, manifest fields). `capture` must return
17
+ * JSON-serialisable state; `restore` must write it back exactly and throw when it cannot.
18
+ */
19
+ export interface PairCopies {
20
+ capture: () => unknown;
21
+ apply: (pair: NewPair) => void;
22
+ restore: (captured: unknown) => void;
23
+ }
24
+ export interface LoginOptions {
25
+ /** false = `--no-wait`: start (or resume) the pairing, print code and link, exit 2. */
26
+ wait: boolean;
27
+ timeoutSeconds?: number;
28
+ displayName?: string;
29
+ /** Claim only (§5.2): the server decides whether this installation exists for the approving account. */
30
+ installationHint?: string | null;
31
+ copies?: PairCopies;
32
+ io?: Partial<LoginIo>;
33
+ }
34
+ /** Owned login files for uninstall, derived from the same paths used by pairing. */
35
+ export declare function loginFiles(dir: string): string[];
36
+ /**
37
+ * A single persistent SQLite file identifies this installation's mutex. The open transaction owns it
38
+ * until close/process death; the file is never renamed or removed. JSON is only last-owner diagnostics.
39
+ */
40
+ export declare function acquireInstallationLock(dir: string, command: string, io?: Pick<LoginIo, "now" | "hostname" | "processAlive">): () => void;
41
+ /**
42
+ * Finishes (or rolls back) an interrupted pair write. Every command calls it under the installation lock
43
+ * before touching the key files; while it throws, the keys in the files must not be used.
44
+ * Returns true when a journal was found and the pair is now saved and confirmed.
45
+ */
46
+ export declare function resumePairJournal(ctx: Ctx, dir: string, copies?: PairCopies): Promise<boolean>;
47
+ /** Exit codes (F10): 0 = pair saved and confirmed, 2 = still waiting for approval, 1 = failure. */
48
+ export declare function deviceLogin(ctx: Ctx, options: LoginOptions): Promise<0 | 1 | 2>;