loki-mode 7.78.0 → 7.79.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/autonomy/loki CHANGED
@@ -125,6 +125,16 @@ if [ -f "$_LOKI_SCRIPT_DIR/lib/git-pr-advisory.sh" ]; then
125
125
  source "$_LOKI_SCRIPT_DIR/lib/git-pr-advisory.sh"
126
126
  fi
127
127
 
128
+ # Unified config-file support (#691). Canonical LOKI_CONFIG_MAP + the config-file
129
+ # loader (loki_maybe_apply_config_file / loki_apply_config_file) and the
130
+ # example/schema/validate generators. Side-effect-free on source: defines the
131
+ # array + functions, exports nothing. The main() pre-pass and run.sh's YAML
132
+ # parsers both call into this single lib so the mapping cannot drift.
133
+ if [ -f "$_LOKI_SCRIPT_DIR/lib/config-map.sh" ]; then
134
+ # shellcheck source=autonomy/lib/config-map.sh
135
+ source "$_LOKI_SCRIPT_DIR/lib/config-map.sh"
136
+ fi
137
+
128
138
  # Resolve the script's real path (handles symlinks)
129
139
  resolve_script_path() {
130
140
  local script="$1"
@@ -1473,6 +1483,24 @@ cmd_start() {
1473
1483
  issue_mode_args+=("--detach")
1474
1484
  shift
1475
1485
  ;;
1486
+ # #691: unified config-file aliases. Already applied by the main()
1487
+ # pre-pass (loki_maybe_apply_config_file); these arms only consume
1488
+ # the flag+path so the loop does not misread the path as the PRD
1489
+ # positional, and do NOT forward it to the run.sh exec target.
1490
+ --config|--vars|--env-file)
1491
+ # Guard the shift 2: a dangling flag (path omitted, flag is the
1492
+ # last arg) would underflow shift 2 and, under set -euo pipefail,
1493
+ # abort the command SILENTLY. Give an honest actionable error.
1494
+ if [ "$#" -ge 2 ]; then
1495
+ shift 2
1496
+ else
1497
+ echo "loki: $1 requires a file path (e.g. --config .loki/config.yaml)" >&2
1498
+ exit 1
1499
+ fi
1500
+ ;;
1501
+ --config=*|--vars=*|--env-file=*)
1502
+ shift
1503
+ ;;
1476
1504
  -*)
1477
1505
  echo -e "${RED}Unknown option: $1${NC}"
1478
1506
  exit 1
@@ -6701,6 +6729,21 @@ cmd_run() {
6701
6729
  run_detached=true
6702
6730
  shift
6703
6731
  ;;
6732
+ # #691: unified config-file aliases. Applied by the main() pre-pass;
6733
+ # consume here so the path is not misread as the issue-ref positional
6734
+ # and is not forwarded to cmd_start.
6735
+ --config|--vars|--env-file)
6736
+ # Guard shift 2 against a dangling flag (silent set -e abort).
6737
+ if [ "$#" -ge 2 ]; then
6738
+ shift 2
6739
+ else
6740
+ echo "loki: $1 requires a file path (e.g. --config .loki/config.yaml)" >&2
6741
+ exit 1
6742
+ fi
6743
+ ;;
6744
+ --config=*|--vars=*|--env-file=*)
6745
+ shift
6746
+ ;;
6704
6747
  -*)
6705
6748
  echo -e "${RED}Unknown option: $1${NC}"
6706
6749
  echo "Run 'loki run --help' for usage."
@@ -8109,15 +8152,27 @@ cmd_config() {
8109
8152
  get)
8110
8153
  cmd_config_get "$@"
8111
8154
  ;;
8155
+ example)
8156
+ cmd_config_example "$@"
8157
+ ;;
8158
+ schema)
8159
+ cmd_config_schema "$@"
8160
+ ;;
8161
+ validate)
8162
+ cmd_config_validate "$@"
8163
+ ;;
8112
8164
  *)
8113
- echo -e "${YELLOW}Usage: loki config [show|init|edit|path|set|get]${NC}"
8114
- echo ""
8115
- echo " show Show current configuration (default)"
8116
- echo " init Create a config file from template"
8117
- echo " edit Open config file in editor"
8118
- echo " path Show config file paths"
8119
- echo " set KEY VALUE Set a configuration value"
8120
- echo " get KEY Get a configuration value"
8165
+ echo -e "${YELLOW}Usage: loki config [show|init|edit|path|set|get|example|schema|validate]${NC}"
8166
+ echo ""
8167
+ echo " show Show current configuration (default)"
8168
+ echo " init Create a config file from template"
8169
+ echo " edit Open config file in editor"
8170
+ echo " path Show config file paths"
8171
+ echo " set KEY VALUE Set a configuration value"
8172
+ echo " get KEY Get a configuration value"
8173
+ echo " example Print an annotated config template (for --config)"
8174
+ echo " schema Print the key -> env-var mapping table"
8175
+ echo " validate FILE Validate a config file (--config) without applying it"
8121
8176
  echo ""
8122
8177
  echo "Settable keys (v6.0.0):"
8123
8178
  echo " maxTier Cost ceiling: opus, sonnet, haiku (default: opus)"
@@ -8295,6 +8350,41 @@ SET_CONFIG
8295
8350
  esac
8296
8351
  }
8297
8352
 
8353
+ # #691: print an annotated config template generated from LOKI_CONFIG_MAP, so it
8354
+ # can never drift from the parsers. Suitable for `loki start --config <path>`.
8355
+ cmd_config_example() {
8356
+ if ! declare -f loki_config_generate_example >/dev/null 2>&1; then
8357
+ echo -e "${RED}config example: config-map.sh helper not loaded${NC}" >&2
8358
+ return 1
8359
+ fi
8360
+ loki_config_generate_example
8361
+ }
8362
+
8363
+ # #691: print the machine-readable key -> LOKI_ENV_VAR mapping table.
8364
+ cmd_config_schema() {
8365
+ if ! declare -f loki_config_generate_schema >/dev/null 2>&1; then
8366
+ echo -e "${RED}config schema: config-map.sh helper not loaded${NC}" >&2
8367
+ return 1
8368
+ fi
8369
+ loki_config_generate_schema
8370
+ }
8371
+
8372
+ # #691: validate a config file (--config) WITHOUT applying it. Reports
8373
+ # unresolved ${VAR} refs, raw-secret literals (error), and per-value validation
8374
+ # failures. Non-zero exit on any failure.
8375
+ cmd_config_validate() {
8376
+ local file="${1:-}"
8377
+ if [ -z "$file" ]; then
8378
+ echo -e "${RED}Usage: loki config validate <file>${NC}" >&2
8379
+ return 2
8380
+ fi
8381
+ if ! declare -f loki_config_validate_file >/dev/null 2>&1; then
8382
+ echo -e "${RED}config validate: config-map.sh helper not loaded${NC}" >&2
8383
+ return 1
8384
+ fi
8385
+ loki_config_validate_file "$file"
8386
+ }
8387
+
8298
8388
  # v6.0.0: Get a configuration value
8299
8389
  cmd_config_get() {
8300
8390
  local key="${1:-}"
@@ -10820,6 +10910,25 @@ cmd_quick() {
10820
10910
  fi
10821
10911
  fi
10822
10912
 
10913
+ # #691: drop the unified config-file aliases from the task description. The
10914
+ # main() pre-pass already applied the file; without this, a trailing
10915
+ # `--config f.env` would be swept into task_desc (cmd_quick has no arg loop).
10916
+ local _quick_args=()
10917
+ local _skip_next=false
10918
+ local _qa
10919
+ for _qa in "$@"; do
10920
+ if [ "$_skip_next" = "true" ]; then
10921
+ _skip_next=false
10922
+ continue
10923
+ fi
10924
+ case "$_qa" in
10925
+ --config|--vars|--env-file) _skip_next=true; continue ;;
10926
+ --config=*|--vars=*|--env-file=*) continue ;;
10927
+ esac
10928
+ _quick_args+=("$_qa")
10929
+ done
10930
+ set -- "${_quick_args[@]+"${_quick_args[@]}"}"
10931
+
10823
10932
  local task_desc="$*"
10824
10933
  local version=$(get_version)
10825
10934
  local max_iter="${LOKI_MAX_ITERATIONS:-3}"
@@ -15306,6 +15415,32 @@ main() {
15306
15415
  # runs for the 8 ported commands). Marker file: ~/.loki-first-run.
15307
15416
  loki_telemetry "cli_command" "command=$command" 2>/dev/null || true
15308
15417
 
15418
+ # Unified config-file pre-pass (#691). For session commands ONLY, honor
15419
+ # LOKI_CONFIG_FILE / --config|--vars|--env-file and load the file BEFORE the
15420
+ # per-command arg loop runs. Running here means: config exports survive the
15421
+ # exec into run.sh, and the subsequent CLI arg loop still overrides them
15422
+ # (CLI > config). The pre-pass SCANS without consuming; the per-command
15423
+ # loops carry consume-and-ignore arms for the three aliases. Gated to
15424
+ # start/run/quick so status/config/stop never trigger a config load.
15425
+ case "$command" in
15426
+ start|run|quick)
15427
+ if declare -f loki_maybe_apply_config_file >/dev/null 2>&1; then
15428
+ loki_maybe_apply_config_file "$@"
15429
+ fi
15430
+ # #691: documented observation hook. When LOKI_CONFIG_DUMP=1, print
15431
+ # the resolved LOKI_* environment (after the config pre-pass AND any
15432
+ # ambient env) and exit 0 WITHOUT running a build. Lets operators and
15433
+ # tests verify exactly which values a --config file resolves to,
15434
+ # without spend. The per-command CLI arg loops do not run on this
15435
+ # path, so CLI-flag overrides are NOT reflected by the dump; it shows
15436
+ # the config+env resolution only.
15437
+ if [ "${LOKI_CONFIG_DUMP:-}" = "1" ]; then
15438
+ env | grep -E '^LOKI_' | LC_ALL=C sort
15439
+ exit 0
15440
+ fi
15441
+ ;;
15442
+ esac
15443
+
15309
15444
  case "$command" in
15310
15445
  run)
15311
15446
  cmd_run "$@"