robisie 0.7.1 → 0.9.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.
@@ -86,6 +86,7 @@ export async function runInstallationUpdate(ctx, options, overrides = {}) {
86
86
  let board, serialRelease, tickRelease;
87
87
  let sharedRelease, rollback;
88
88
  let notifyFailure, afterCleanup, modeRestored;
89
+ let lastStderr, refusalMessage;
89
90
  let mode;
90
91
  const digest = (bytes) => createHash('sha256').update(bytes).digest('hex');
91
92
  let result = 2;
@@ -245,6 +246,7 @@ export async function runInstallationUpdate(ctx, options, overrides = {}) {
245
246
  }
246
247
  };
247
248
  try {
249
+ let deferReadFailure;
248
250
  result = await (async () => {
249
251
  const selected = options.engineConfig ?? ctx.env.ROBISIE_ENGINE_CONFIG;
250
252
  if (selected !== undefined && selected !== null && !selected.trim())
@@ -444,7 +446,19 @@ export async function runInstallationUpdate(ctx, options, overrides = {}) {
444
446
  audit(delivered ? 'alarm-delivered' : 'alarm-undelivered');
445
447
  skline(`CTO ESKALACJA HOST-AUTO ${text}`);
446
448
  };
447
- notifyFailure = host ? () => alarm('Aktualizacja nieudana; sprawdź prywatny audyt i potwierdzenie powrotu.') : undefined;
449
+ if (host) {
450
+ const writeStderr = ctx.err.bind(ctx);
451
+ ctx = { ...ctx, err: message => { lastStderr = message; writeStderr(message); } };
452
+ notifyFailure = () => {
453
+ try {
454
+ audit('refused', { message: refusalMessage ?? lastStderr });
455
+ }
456
+ catch {
457
+ writeStderr('Alarm: błąd audytu odmowy aktualizacji.');
458
+ }
459
+ alarm('Aktualizacja nieudana; sprawdź prywatny audyt i potwierdzenie powrotu.');
460
+ };
461
+ }
448
462
  const legacyState = env.HU_STATE || join(hostHome, 'auto-update.state');
449
463
  let legacyAttempt;
450
464
  const defer = (reason) => {
@@ -483,8 +497,7 @@ export async function runInstallationUpdate(ctx, options, overrides = {}) {
483
497
  ctx.err(`Alarm: ${message}`);
484
498
  alarm(message);
485
499
  }
486
- if (reason.startsWith('claim '))
487
- audit('deferred', { reason });
500
+ audit('deferred', { reason });
488
501
  ctx.out(`Aktualizacja odroczona: ${reason}.`);
489
502
  return 0;
490
503
  };
@@ -664,22 +677,44 @@ export async function runInstallationUpdate(ctx, options, overrides = {}) {
664
677
  let processes;
665
678
  const scan = () => processes ??= processBusy();
666
679
  let busy = null, qualified = null;
667
- for (const [family, lock, ...companions] of [
668
- ['tester', '.tester-job.lock', '.tester-job.input.json', '.tester-job.result.json'],
669
- ['receiver', 'receiver-jobs/local/claim.json',
670
- ...['started', 'wynik.json', 'stop.json', 'ack.json'].map(name => `receiver-jobs/local/${name}`)],
680
+ const testerResult = '.tester-job.result.json';
681
+ const receiverResults = ['receiver-jobs/local/wynik.json', 'receiver-jobs/local/stop.json'];
682
+ for (const [family, lock, results, ...companions] of [
683
+ ['tester', '.tester-job.lock', [testerResult], '.tester-job.input.json', testerResult],
684
+ ['receiver', 'receiver-jobs/local/claim.json', receiverResults,
685
+ 'receiver-jobs/local/started', ...receiverResults, 'receiver-jobs/local/ack.json'],
671
686
  ]) {
672
- const confirmed = new Map();
687
+ const companionLocks = new Map();
673
688
  for (const [suffix, file] of readClaimPair(lock, true)) {
674
689
  const name = lock + suffix;
675
690
  if (!file)
676
691
  continue;
677
692
  if (file.livePid !== null && scan().jobs[family].has(file.livePid)) {
678
- confirmed.set(suffix, file.mtimeMs);
693
+ companionLocks.set(suffix, file.mtimeMs);
679
694
  qualified ??= `claim ${name}`;
680
695
  }
681
- else if (!(runtime.now() - file.mtimeMs <= 600_000))
682
- unsettledClaim(name);
696
+ else {
697
+ let latestMtime = file.mtimeMs;
698
+ const now = runtime.now();
699
+ if (file.livePid === null) {
700
+ let matchingMtime = -Infinity, alternateMtime = -Infinity;
701
+ for (const result of results)
702
+ for (const [resultSuffix, resultFile] of readClaimPair(result, false)) {
703
+ if (!resultFile)
704
+ continue;
705
+ if (resultSuffix === suffix)
706
+ matchingMtime = Math.max(matchingMtime, resultFile.mtimeMs);
707
+ else
708
+ alternateMtime = Math.max(alternateMtime, resultFile.mtimeMs);
709
+ }
710
+ const resultMtime = matchingMtime === -Infinity ? alternateMtime : matchingMtime;
711
+ latestMtime = Math.max(latestMtime, resultMtime);
712
+ if (now - resultMtime <= 600_000)
713
+ companionLocks.set(suffix, file.mtimeMs);
714
+ }
715
+ if (!(now - latestMtime <= 600_000))
716
+ unsettledClaim(name);
717
+ }
683
718
  busy ??= file.livePid !== null ? `claim ${name}` : `claim ${name} czeka na rozliczenie przez takt`;
684
719
  }
685
720
  for (const companion of companions)
@@ -687,7 +722,7 @@ export async function runInstallationUpdate(ctx, options, overrides = {}) {
687
722
  const name = companion + suffix;
688
723
  if (!file)
689
724
  continue;
690
- const lockMtime = confirmed.get(suffix) ?? confirmed.get(suffix === '' ? '.pending' : '');
725
+ const lockMtime = companionLocks.get(suffix) ?? companionLocks.get(suffix === '' ? '.pending' : '');
691
726
  const minMtime = lockMtime === undefined ? runtime.now() - 600_000 : lockMtime - 60_000;
692
727
  if (!(file.mtimeMs >= minMtime))
693
728
  unsettledClaim(name);
@@ -748,8 +783,10 @@ export async function runInstallationUpdate(ctx, options, overrides = {}) {
748
783
  return { busy, own };
749
784
  };
750
785
  const initial = await preflight();
751
- if (initial.busy)
752
- return defer(initial.busy);
786
+ const busy = initial.busy;
787
+ // Only a failed release read may fall back to the initial deferral.
788
+ if (busy)
789
+ deferReadFailure = () => defer(busy);
753
790
  readHostService();
754
791
  const pointer = join(update, 'current');
755
792
  if (stat(pointer) && !stat(pointer)?.isSymbolicLink())
@@ -796,10 +833,15 @@ export async function runInstallationUpdate(ctx, options, overrides = {}) {
796
833
  repairUnits = lastRepair !== undefined && json(Buffer.from(lastRepair)).confirmed === false;
797
834
  }
798
835
  }
836
+ deferReadFailure = undefined;
799
837
  if (!hasNewerRelease && !repairUnits && (latest !== oldPackage.version || pointerSnapshot.target)) {
838
+ if (stat(join(update, 'deferred.json')))
839
+ io.unlinkSync(join(update, 'deferred.json'));
800
840
  ctx.out('Zainstalowana wersja robisie jest aktualna; brak downgrade.');
801
841
  return 0;
802
842
  }
843
+ if (busy)
844
+ return defer(busy);
803
845
  if (host && stat(legacyState)) {
804
846
  const lines = regular(legacyState).toString('utf8').split('\n').filter(Boolean);
805
847
  if (lines.some(line => !/^\d+\.\d+\.\d+ \S+ .+$/.test(line)))
@@ -1347,7 +1389,11 @@ try {
1347
1389
  result = 1;
1348
1390
  }
1349
1391
  return result;
1350
- })();
1392
+ })().catch(error => {
1393
+ if (deferReadFailure)
1394
+ return deferReadFailure();
1395
+ throw error;
1396
+ });
1351
1397
  }
1352
1398
  catch (error) {
1353
1399
  if (rollback) {
@@ -1361,6 +1407,7 @@ try {
1361
1407
  }
1362
1408
  }
1363
1409
  ctx.err(error instanceof RobisieError ? error.message : 'Odmowa aktualizacji: błąd IO, konfiguracji, transportu lub audytu; nie ponawiaj niepewnego zapisu.');
1410
+ refusalMessage = lastStderr;
1364
1411
  result = 2;
1365
1412
  }
1366
1413
  finally {
@@ -1373,6 +1420,7 @@ try {
1373
1420
  catch {
1374
1421
  result = 2;
1375
1422
  ctx.err('Alarm: błąd potwierdzenia lub audytu hosta po cleanup.');
1423
+ refusalMessage = lastStderr;
1376
1424
  if (rollback) {
1377
1425
  const restore = rollback;
1378
1426
  rollback = undefined;
package/dist/roles.d.ts CHANGED
@@ -17,7 +17,7 @@ export interface Role {
17
17
  export declare function rolesDir(): string;
18
18
  export declare function parseRole(file: Role["file"], text: string): Role;
19
19
  export declare function loadRoles(dir?: string): Role[];
20
- export declare const MANAGED_LINE = "<!-- robisie:managed 0.7.1 \u2014 plik zarz\u0105dzany przez `npx robisie`; `npx robisie uninstall` go usunie -->";
20
+ export declare const MANAGED_LINE = "<!-- robisie:managed 0.9.0 \u2014 plik zarz\u0105dzany przez `npx robisie`; `npx robisie uninstall` go usunie -->";
21
21
  export type AgentFlavor = "claude" | "codex" | "opencode";
22
22
  /** How the operator starts the Builder for one card in its own session (the card id is not a secret). */
23
23
  export declare function builderStartCommand(flavor: AgentFlavor, codexRolePath?: string): string;
package/docs/README.en.md CHANGED
@@ -1,4 +1,4 @@
1
- # robisie — from account to accepted card (package 0.7.1) <!-- x-release-please-version -->
1
+ # robisie — from account to accepted card (package 0.9.0) <!-- x-release-please-version -->
2
2
 
3
3
  In the project directory with its engine configuration, run `npx robisie init`, then `npx robisie doctor`: init prepares the project goal and tester protection list, and doctor checks both inputs.
4
4
 
package/docs/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # robisie — od konta do odebranej karty (paczka 0.7.1) <!-- x-release-please-version -->
1
+ # robisie — od konta do odebranej karty (paczka 0.9.0) <!-- x-release-please-version -->
2
2
 
3
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
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "robisie",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
4
4
  "description": "Instalator klienta robisie: łączy agenta (Claude Code, Codex CLI, OpenCode) z tablicą robisie i instaluje role klienta.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",