@jaromil/gestalt 0.16.1 → 0.17.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.
@@ -3,7 +3,7 @@
3
3
  set -Eeuo pipefail
4
4
  IFS=$'\n\t'
5
5
 
6
- readonly GESTALT_CLI_VERSION='0.16.1'
6
+ readonly GESTALT_CLI_VERSION='0.17.0'
7
7
  readonly DEFAULT_INSTALL_BASE_URL='https://dyne.github.io/gestalt'
8
8
  readonly DEFAULT_MARKETPLACE='dyne/gestalt-agents'
9
9
  readonly DEFAULT_MARKETPLACE_NAME='dyne-gestalt-agents'
@@ -3546,37 +3546,122 @@ renameSync(temporary, destination);
3546
3546
  NODE
3547
3547
  }
3548
3548
 
3549
+ agents_setup_uses_node() {
3550
+ [[ -f $marketplace_setup && -f ${marketplace_setup%.sh}.mjs && -f ${marketplace_setup%/*}/scripts/setup-agents.mjs ]]
3551
+ }
3552
+
3553
+ prepare_agents_homes() {
3554
+ local native_owner=false
3555
+ if agents_setup_uses_node; then native_owner=true; fi
3556
+ node - "$codex_home" "$gestalt_home" "$native_owner" <<'NODE'
3557
+ const { accessSync, constants, mkdirSync, realpathSync, statSync } = require('node:fs');
3558
+ const { basename, dirname, isAbsolute, join, relative, sep } = require('node:path');
3559
+ function canonical(path) {
3560
+ try { return realpathSync(path); }
3561
+ catch (error) {
3562
+ if (error.code !== 'ENOENT' || dirname(path) === path) throw error;
3563
+ return join(canonical(dirname(path)), basename(path));
3564
+ }
3565
+ }
3566
+ function read(path) {
3567
+ try { return statSync(path); }
3568
+ catch (error) { if (error.code === 'ENOENT') return null; throw error; }
3569
+ }
3570
+ try {
3571
+ const [selectedCodex, selectedGestalt, nativeOwner] = process.argv.slice(2);
3572
+ const [codex, gestalt] = [selectedCodex, selectedGestalt].map(canonical);
3573
+ const within = (root, path) => {
3574
+ const rest = relative(root, path);
3575
+ return !isAbsolute(rest) && rest !== '..' && !rest.startsWith('..' + sep);
3576
+ };
3577
+ const home = realpathSync(process.env.HOME);
3578
+ if (within(codex, gestalt) || within(gestalt, codex) || [codex, gestalt].some(path => within(path, home)))
3579
+ throw new Error('CODEX_HOME and GESTALT_HOME must be separate managed directories outside HOME itself');
3580
+ const missing = [];
3581
+ for (const path of [codex, gestalt]) {
3582
+ const info = read(path);
3583
+ if (!info) { missing.push(path); continue; }
3584
+ try {
3585
+ if (!info.isDirectory()) throw new Error('expected a directory');
3586
+ accessSync(path, constants.W_OK | constants.X_OK);
3587
+ } catch { throw new Error('managed directory is not writable: ' + path); }
3588
+ if (nativeOwner === 'true' && (info.uid !== process.getuid() || (info.mode & 0o077) !== 0))
3589
+ throw new Error('native Agents setup requires a directory private to its owner: ' + path + '; select private managed homes before retrying');
3590
+ }
3591
+ for (const path of missing) mkdirSync(path, { recursive: true, mode: 0o700 });
3592
+ } catch (error) { console.error('gestalt: ' + error.message); process.exitCode = 1; }
3593
+ NODE
3594
+ }
3595
+
3549
3596
  run_marketplace_setup() {
3550
3597
  local -r mode=$1
3551
3598
  local -r include_extra_skills=$2
3552
3599
  local marketplace_action
3553
- agents_setup_stage=''
3554
- local -a setup_args=()
3600
+ # Bash can unwind this function before running the shell's EXIT trap.
3601
+ agents_setup_stage='' agents_setup_handoff=false agents_setup_snapshot_ready=false
3602
+ agents_codex_gate=false agents_gestalt_gate=false
3603
+ agents_operation_lock=$codex_home/.gestalt-manager-setup.lock
3604
+ agents_codex_gate_path=$codex_home/.gestalt-setup.lock
3605
+ agents_gestalt_gate_path=$gestalt_home/.gestalt-setup.lock
3555
3606
 
3556
3607
  check_node_version
3557
3608
  require_command npm
3558
3609
  require_command codex
3559
- mkdir -p -- "$codex_home" "$gestalt_home"
3560
- agents_setup_lock=$codex_home/.gestalt-setup.lock
3561
- mkdir -- "$agents_setup_lock" 2>/dev/null ||
3562
- die 'Agents setup is already running or Codex home is not writable; verify the previous installer exited before removing .gestalt-setup.lock'
3563
- # Serialize setup and roll back manager-owned config edits on failure. Package
3564
- # installation and its own profile transaction remain the delegated owner's job.
3610
+ prepare_agents_homes
3611
+ mkdir -m 700 -- "$agents_operation_lock" 2>/dev/null ||
3612
+ die "Agents setup is already running or ownership is unknown: $agents_operation_lock"
3613
+ setup_acquire_gates() {
3614
+ if ! "$agents_codex_gate"; then
3615
+ mkdir -m 700 -- "$agents_codex_gate_path" 2>/dev/null || return 1
3616
+ agents_codex_gate=true
3617
+ fi
3618
+ if ! "$agents_gestalt_gate"; then
3619
+ mkdir -m 700 -- "$agents_gestalt_gate_path" 2>/dev/null || return 1
3620
+ agents_gestalt_gate=true
3621
+ fi
3622
+ }
3623
+ setup_release_gates() {
3624
+ local status=0
3625
+ if "$agents_gestalt_gate"; then
3626
+ if rmdir -- "$agents_gestalt_gate_path"; then agents_gestalt_gate=false; else status=1; fi
3627
+ fi
3628
+ if "$agents_codex_gate"; then
3629
+ if rmdir -- "$agents_codex_gate_path"; then agents_codex_gate=false; else status=1; fi
3630
+ fi
3631
+ return "$status"
3632
+ }
3633
+ # Keep the Manager operation lock while the Node delegate owns its setup
3634
+ # gates. Only restore a delegated snapshot with both gates and known bytes.
3565
3635
  setup_cleanup() {
3566
3636
  local status=$?
3637
+ local retain=false
3567
3638
  trap - EXIT HUP INT TERM ERR
3568
- # Cleanup must not replace the triggering status or prevent the manager's
3569
- # preexisting EXIT cleanup (including the update/restart worker lock).
3639
+ # Successful setup restores the regular EXIT trap before returning. Bash
3640
+ # can enter this trap with status 0 even when setup did not finish.
3570
3641
  set +e
3571
- if (( status != 0 )) && [[ -n $agents_setup_stage ]]; then
3572
- if [[ -f $agents_setup_stage/config.toml ]]; then
3573
- mv -f -- "$agents_setup_stage/config.toml" "$codex_home/config.toml"
3642
+ if (( status == 0 )); then
3643
+ status=1
3644
+ log 'error: Agents setup exited before completing'
3645
+ fi
3646
+ if "$agents_setup_snapshot_ready" && [[ -n $agents_setup_stage ]]; then
3647
+ if ! setup_acquire_gates; then
3648
+ retain=true
3649
+ elif "$agents_setup_handoff" && { [[ -L $codex_home/config.toml ]] ||
3650
+ ! cmp -s -- "$agents_setup_stage/config-delegated" "$codex_home/config.toml"; }; then
3651
+ retain=true
3652
+ elif [[ -f $agents_setup_stage/config.toml ]]; then
3653
+ mv -f -- "$agents_setup_stage/config.toml" "$codex_home/config.toml" || retain=true
3574
3654
  elif [[ -f $agents_setup_stage/config-absent ]]; then
3575
- rm -f -- "$codex_home/config.toml"
3655
+ rm -f -- "$codex_home/config.toml" || retain=true
3576
3656
  fi
3577
3657
  fi
3578
- [[ -z $agents_setup_stage ]] || rm -rf -- "$agents_setup_stage"
3579
- rmdir -- "$agents_setup_lock" 2>/dev/null || true
3658
+ setup_release_gates || retain=true
3659
+ if "$retain"; then
3660
+ log "Agents setup ownership or rollback is unconfirmed; preserved lock $agents_operation_lock and snapshot ${agents_setup_stage:-unavailable}"
3661
+ else
3662
+ [[ -z $agents_setup_stage ]] || rm -rf -- "$agents_setup_stage"
3663
+ rmdir -- "$agents_operation_lock" 2>/dev/null || true
3664
+ fi
3580
3665
  cleanup
3581
3666
  exit "$status"
3582
3667
  }
@@ -3584,6 +3669,7 @@ run_marketplace_setup() {
3584
3669
  trap 'exit 129' HUP
3585
3670
  trap 'exit 130' INT
3586
3671
  trap 'exit 143' TERM
3672
+ setup_acquire_gates || die 'Agents setup is already running or its setup lock ownership is unknown'
3587
3673
  [[ ! -L $codex_home/config.toml &&
3588
3674
  (! -e $codex_home/config.toml || -f $codex_home/config.toml) ]] ||
3589
3675
  die 'Codex config must be a regular file for setup'
@@ -3593,11 +3679,7 @@ run_marketplace_setup() {
3593
3679
  else
3594
3680
  touch "$agents_setup_stage/config-absent"
3595
3681
  fi
3596
- configure_codex_permissions
3597
- # Establish app defaults before the owner appends its managed MCP section,
3598
- # keeping first-install ordering identical to later reconciliation.
3599
- configure_codex_tool_approvals
3600
-
3682
+ agents_setup_snapshot_ready=true
3601
3683
  marketplace_action=upgrade
3602
3684
  if [[ $mode == install && ! -f $marketplace_setup ]]; then
3603
3685
  marketplace_action=add
@@ -3619,13 +3701,28 @@ run_marketplace_setup() {
3619
3701
  [[ -f $marketplace_setup ]] ||
3620
3702
  die "marketplace setup script is missing after ${marketplace_action}: $marketplace_setup"
3621
3703
 
3622
- if [[ $include_extra_skills == true ]]; then
3623
- setup_args+=(--extra-skills)
3624
- fi
3704
+ # Refresh can replace the legacy owner. Check the selected owner before
3705
+ # editing the profile, while the original snapshot is still available.
3706
+ if agents_setup_uses_node; then prepare_agents_homes; fi
3707
+ configure_codex_permissions
3708
+ # Establish app defaults before the owner appends its managed MCP section.
3709
+ configure_codex_tool_approvals
3625
3710
 
3626
3711
  log 'preparing context mode, plugins, and agent profiles'
3627
- CODEX_HOME=$codex_home GESTALT_HOME=$gestalt_home \
3628
- bash "$marketplace_setup" "${setup_args[@]}"
3712
+ if agents_setup_uses_node; then
3713
+ cp -p -- "$codex_home/config.toml" "$agents_setup_stage/config-delegated"
3714
+ agents_setup_handoff=true
3715
+ setup_release_gates
3716
+ fi
3717
+ # Bash 3.2 with nounset rejects expanding an empty array.
3718
+ if [[ $include_extra_skills == true ]]; then
3719
+ CODEX_HOME=$codex_home GESTALT_HOME=$gestalt_home bash "$marketplace_setup" --extra-skills
3720
+ else
3721
+ CODEX_HOME=$codex_home GESTALT_HOME=$gestalt_home bash "$marketplace_setup"
3722
+ fi
3723
+ setup_acquire_gates || die 'Agents setup lock ownership is unknown after delegation'
3724
+ # Across the portable handoff another setup may have completed. If later
3725
+ # work fails, retain a changed configuration and the original snapshot.
3629
3726
  verify_context_mode_installation
3630
3727
  configure_codex_tool_approvals
3631
3728
  # Normalize our block after delegated sections/defaults are reconciled so the
@@ -3634,7 +3731,8 @@ run_marketplace_setup() {
3634
3731
  record_setup_provenance
3635
3732
  rm -rf -- "$agents_setup_stage"
3636
3733
  agents_setup_stage=''
3637
- rmdir -- "$agents_setup_lock"
3734
+ setup_release_gates
3735
+ rmdir -- "$agents_operation_lock"
3638
3736
  trap cleanup EXIT
3639
3737
  trap - HUP INT TERM
3640
3738
  }
@@ -3773,6 +3871,7 @@ NODE
3773
3871
 
3774
3872
  command_install() {
3775
3873
  parse_setup_options "$@"
3874
+ prepare_agents_homes
3776
3875
  command_skills install
3777
3876
  run_marketplace_setup install "$include_extra_skills"
3778
3877
  install_mobile
@@ -3784,6 +3883,7 @@ command_update() {
3784
3883
  case $update_component in
3785
3884
  all | gestalt)
3786
3885
  update_manager
3886
+ prepare_agents_homes
3787
3887
  retire_managed_xerj
3788
3888
  command_skills update
3789
3889
  run_marketplace_setup upgrade "$include_extra_skills"
@@ -3944,7 +4044,7 @@ command_update_restart_worker() {
3944
4044
  local -r restart_log=${4:-}
3945
4045
  local -r restart_lock=${5:-}
3946
4046
  local -r worker_component=${6:-all}
3947
- local restart_cwd restart_field manager_target
4047
+ local restart_cwd restart_field restart_index manager_target
3948
4048
  local -a restart_record restart_args migrated_restart_args update_args=()
3949
4049
 
3950
4050
  [[ -n $restart_log ]] || die 'the update-restart worker log path is missing'
@@ -3963,11 +4063,18 @@ command_update_restart_worker() {
3963
4063
  while IFS= read -r -d '' restart_field; do
3964
4064
  restart_record+=("$restart_field")
3965
4065
  done < "$restart_state"
3966
- ((${#restart_record[@]} >= 1)) || die 'the Gestalt Mobile restart descriptor is empty'
4066
+ [[ ${restart_record[0]+present} ]] || die 'the Gestalt Mobile restart descriptor is empty'
3967
4067
  restart_cwd=${restart_record[0]}
3968
- restart_args=("${restart_record[@]:1}")
3969
- retire_mobile_restart_arguments "${restart_args[@]}"
3970
- restart_args=("${migrated_restart_args[@]}")
4068
+ # Bash 3.2 can join a quoted array slice into one argument. Copy each field
4069
+ # explicitly, preserving empty fields and literal separators from the record.
4070
+ restart_args=()
4071
+ for ((restart_index = 1; restart_index < ${#restart_record[@]}; restart_index += 1)); do
4072
+ restart_args+=("${restart_record[restart_index]}")
4073
+ done
4074
+ # Empty arrays are unset under Bash 3.2 nounset; conditional expansion emits
4075
+ # zero arguments for them and retains each argument of a nonempty array.
4076
+ retire_mobile_restart_arguments ${restart_args[@]+"${restart_args[@]}"}
4077
+ restart_args=(${migrated_restart_args[@]+"${migrated_restart_args[@]}"})
3971
4078
  [[ $restart_cwd == /* && -d $restart_cwd ]] ||
3972
4079
  die "the Gestalt Mobile restart directory is invalid: $restart_cwd"
3973
4080
  [[ $worker_extra_skills == false || $worker_extra_skills == true ]] ||
@@ -3976,7 +4083,7 @@ command_update_restart_worker() {
3976
4083
  update_args+=(--extra-skills)
3977
4084
  fi
3978
4085
 
3979
- command_update "$worker_component" "${update_args[@]}"
4086
+ command_update "$worker_component" ${update_args[@]+"${update_args[@]}"}
3980
4087
  validate_mobile_restart_context "$relay_pid" "$restart_state"
3981
4088
  log "update succeeded; gracefully stopping Gestalt Mobile process $relay_pid"
3982
4089
  kill -TERM "$relay_pid"
@@ -3995,7 +4102,7 @@ command_update_restart_worker() {
3995
4102
  resolve_manager_target
3996
4103
  cd -- "$restart_cwd"
3997
4104
  log 'restarting Gestalt Mobile with its previous options'
3998
- exec "$manager_target" mobile -- "${restart_args[@]}"
4105
+ exec "$manager_target" mobile -- ${restart_args[@]+"${restart_args[@]}"}
3999
4106
  }
4000
4107
 
4001
4108
  strip_separator() {
@@ -0,0 +1,17 @@
1
+ /* Original Gestalt implementation. SPDX-License-Identifier: MIT
2
+ * Copyright (c) 2026 Dyne.org contributors.
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to deal
5
+ * in the Software without restriction, including without limitation the rights
6
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ * of the Software, and to permit persons to whom the Software is furnished to do
8
+ * so, subject to the following conditions: The above copyright notice and this
9
+ * permission notice shall be included in all copies or substantial portions of
10
+ * the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
13
+ * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
14
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
16
+ * DEALINGS IN THE SOFTWARE.
17
+ */
@@ -0,0 +1,44 @@
1
+ {
2
+ "source": "src/cli/platform/native/owned-process.c",
3
+ "license": "MIT (full license in source)",
4
+ "sourceSha256": "8b8499245e4213e3e842497f815d4b0d19685bcd806b461fdacb66119500ad58",
5
+ "artifactSha256": "48f6559ad2157a7dfa8bf30f2418773ca6f3ae0ae1769e3700e40ce718e6be94",
6
+ "platform": "win32",
7
+ "architecture": "x64",
8
+ "node": "v24.22.3",
9
+ "compiler": "cl.exe",
10
+ "compilerVersion": "usage: cl [ option... ] filename... [ /link linkoption... ]\r\nMicrosoft (R) C/C++ Optimizing Compiler Version 19.52.37029 for x64\r\nCopyright (C) Microsoft Corporation. All rights reserved.",
11
+ "argv": [
12
+ "/nologo",
13
+ "/W3",
14
+ "/WX",
15
+ "/std:c11",
16
+ "/O2",
17
+ "/D_CRT_SECURE_NO_WARNINGS",
18
+ "D:\\a\\gestalt\\gestalt\\src\\cli\\platform\\native\\owned-process.c",
19
+ "D:\\a\\gestalt\\gestalt\\src\\cli\\platform\\native\\windows-storage-check.c",
20
+ "/Fe:D:\\a\\gestalt\\gestalt\\dist\\cli\\native\\gestalt-owned-process.exe",
21
+ "/Fo:D:\\a\\gestalt\\gestalt\\dist\\cli\\native\\",
22
+ "user32.lib",
23
+ "advapi32.lib",
24
+ "netapi32.lib"
25
+ ],
26
+ "observedAt": "2026-11-19T19:59:39.620Z",
27
+ "sourceInputs": [
28
+ {
29
+ "path": "src/cli/platform/native/owned-process.c",
30
+ "bytes": 45328,
31
+ "sha256": "8b8499245e4213e3e842497f815d4b0d19685bcd806b461fdacb66119500ad58"
32
+ },
33
+ {
34
+ "path": "src/cli/platform/native/windows-storage-check.c",
35
+ "bytes": 11137,
36
+ "sha256": "c4bc745ebab6352394ac4358b1bd9e630540ec51bf90f0e70f659682a7e96376"
37
+ },
38
+ {
39
+ "path": "src/cli/platform/native/windows-storage-check.h",
40
+ "bytes": 237,
41
+ "sha256": "cae6c68ae671e6c0fcb73ce01e7fc8252928ed5a1c7f65102b329569e7b18019"
42
+ }
43
+ ]
44
+ }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@jaromil/gestalt",
3
- "version": "0.16.1",
3
+ "type": "module",
4
+ "version": "0.17.0",
4
5
  "description": "Manage Gestalt's isolated Codex profile, agent skills and Mobile installation",
5
6
  "license": "AGPL-3.0-or-later",
6
7
  "author": "Dyne.org foundation",
@@ -23,7 +24,7 @@
23
24
  },
24
25
  "files": [
25
26
  "bin/gestalt",
26
- "lib/gestalt",
27
+ "lib/",
27
28
  "postinstall.mjs",
28
29
  "README.md",
29
30
  "LICENSE"
@@ -36,11 +37,12 @@
36
37
  },
37
38
  "os": [
38
39
  "linux",
39
- "darwin"
40
+ "darwin",
41
+ "win32"
40
42
  ],
41
43
  "publishConfig": {
42
44
  "access": "public",
43
45
  "registry": "https://registry.npmjs.org/"
44
46
  },
45
- "gitHead": "cdfd254efa475f1e959a7bb64b49777e4ae5d8ce"
47
+ "gitHead": "8ab9cc5e34195522a8c1ce1d045937d7fefb46e7"
46
48
  }
package/postinstall.mjs CHANGED
@@ -11,12 +11,12 @@ if ((process.env.npm_config_global ?? process.env.NPM_CONFIG_GLOBAL) === 'true')
11
11
  delete environment[key];
12
12
  }
13
13
  environment.npm_config_global = 'false';
14
- const result = spawnSync('bash', [fileURLToPath(new URL('./bin/gestalt', import.meta.url)), 'agents', 'install'], {
14
+ const result = spawnSync(process.execPath, [fileURLToPath(new URL('./bin/gestalt', import.meta.url)), 'agents', 'install'], {
15
15
  env: environment,
16
16
  stdio: 'inherit',
17
17
  });
18
18
  if (result.error || result.status !== 0) {
19
- console.error('gestalt: Agents setup failed. Ensure Codex, Bash and Node.js 24+ are installed, then retry npm install -g @jaromil/gestalt. Existing installations can run: gestalt agents install');
19
+ console.error('gestalt: Agents setup failed. Ensure Codex and Node.js 24+ are installed (Unix also requires Bash), then retry npm install -g @jaromil/gestalt. Existing installations can run: gestalt agents install');
20
20
  process.exitCode = result.status || 1;
21
21
  }
22
22
  }