superpowers-manager 0.1.4 → 0.1.6

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.
@@ -0,0 +1,391 @@
1
+ #!/bin/sh
2
+ # Sourced module; callers own set -eu.
3
+
4
+ SPW_PLUGIN_ID="superpowers@superpowers-manager"
5
+ SPW_MARKETPLACE_NAME="superpowers-manager"
6
+ SPW_LEGACY_PLUGIN_ID="superpowers@superpowers-wrapper"
7
+ SPW_LEGACY_MARKETPLACE_NAME="superpowers-wrapper"
8
+
9
+ # Given a JSON document as the FIRST ARGUMENT (a string), print "present" if any
10
+ # element of the top-level array <array_key> is an object whose <field> equals
11
+ # <value>, else print "absent" (exit 0). On unparseable JSON or invalid schema,
12
+ # print nothing and exit 2 so callers can fail closed rather than treat an
13
+ # unreadable listing as "absent". Every item in the inspected array must be an
14
+ # object with a non-empty string <field>; otherwise ownership is unprovable and
15
+ # the helper exits 2 instead of treating the malformed entry as unrelated.
16
+ # The JSON is passed as an argument (exactly as spw_json_get takes a file path),
17
+ # NOT on stdin: the here-doc below is Python's stdin (its program source), so a
18
+ # json.load(sys.stdin) here would read the program, not the caller's JSON.
19
+ spw_json_array_has() {
20
+ json="$1"
21
+ array_key="$2"
22
+ field="$3"
23
+ value="$4"
24
+ python3 - "$json" "$array_key" "$field" "$value" <<'PY'
25
+ import json, sys
26
+ raw, array_key, field, value = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
27
+ try:
28
+ data = json.loads(raw)
29
+ except (json.JSONDecodeError, RecursionError):
30
+ sys.exit(2)
31
+ if not isinstance(data, dict):
32
+ sys.exit(2)
33
+ items = data.get(array_key)
34
+ if not isinstance(items, list):
35
+ sys.exit(2)
36
+ for item in items:
37
+ if not isinstance(item, dict):
38
+ sys.exit(2)
39
+ field_value = item.get(field)
40
+ if not isinstance(field_value, str) or not field_value:
41
+ sys.exit(2)
42
+ found = any(item[field] == value for item in items)
43
+ print("present" if found else "absent")
44
+ PY
45
+ }
46
+
47
+ # Print the registered root of <marketplace_name> from a marketplace-list JSON
48
+ # document (as a string argument, like spw_json_array_has), or nothing if the
49
+ # marketplace is absent. Exit 2 on unparseable JSON, a non-object item, or an
50
+ # item without a non-empty string name: such an item cannot be proven unrelated
51
+ # and must not be mistaken for an absent manager marketplace. Validate root only
52
+ # on the matching item; unrelated marketplace roots are never read. A matching
53
+ # item without a non-empty string root also exits 2. Empty output is unambiguous:
54
+ # a valid registered root is always a non-empty path.
55
+ spw_marketplace_root_from_json() {
56
+ json="$1"
57
+ marketplace_name="$2"
58
+ python3 - "$json" "$marketplace_name" <<'PY'
59
+ import json, sys
60
+ raw, name = sys.argv[1], sys.argv[2]
61
+ try:
62
+ data = json.loads(raw)
63
+ except (json.JSONDecodeError, RecursionError):
64
+ sys.exit(2)
65
+ if not isinstance(data, dict):
66
+ sys.exit(2)
67
+ items = data.get("marketplaces")
68
+ if not isinstance(items, list):
69
+ sys.exit(2)
70
+ for item in items:
71
+ if not isinstance(item, dict):
72
+ sys.exit(2)
73
+ item_name = item.get("name")
74
+ if not isinstance(item_name, str) or not item_name:
75
+ sys.exit(2)
76
+ for item in items:
77
+ if item["name"] == name:
78
+ item_root = item.get("root")
79
+ if not isinstance(item_root, str) or not item_root:
80
+ sys.exit(2)
81
+ print(item_root)
82
+ sys.exit(0)
83
+ PY
84
+ }
85
+
86
+ # Print "same" if the two paths refer to the same physical location, else
87
+ # "different". Physical-path normalization via os.path.realpath on both
88
+ # sides (handles /var vs /private/var and other symlinked roots); if
89
+ # realpath fails, fall back to comparing the original strings.
90
+ spw_paths_equal() {
91
+ python3 - "$1" "$2" <<'PY'
92
+ import os, sys
93
+ a, b = sys.argv[1], sys.argv[2]
94
+ try:
95
+ na, nb = os.path.realpath(a), os.path.realpath(b)
96
+ except OSError:
97
+ na, nb = a, b
98
+ print("same" if na == nb else "different")
99
+ PY
100
+ }
101
+
102
+ spw_find_installed_metadata() {
103
+ search_root="${SUPERPOWERS_INSTALLED_SEARCH_ROOT:-$HOME/.codex}"
104
+ find "$search_root" \
105
+ \( -path "*/$SPW_MARKETPLACE_NAME/superpowers/.superpowers-upstream.json" \
106
+ -o -path "*/$SPW_MARKETPLACE_NAME/superpowers/*/.superpowers-upstream.json" \) \
107
+ -type f 2>/dev/null | head -n 1
108
+ }
109
+
110
+ spw_find_installed_manifest() {
111
+ search_root="${SUPERPOWERS_INSTALLED_SEARCH_ROOT:-$HOME/.codex}"
112
+ find "$search_root" \
113
+ \( -path "*/$SPW_MARKETPLACE_NAME/superpowers/.codex-plugin/plugin.json" \
114
+ -o -path "*/$SPW_MARKETPLACE_NAME/superpowers/*/.codex-plugin/plugin.json" \) \
115
+ -type f 2>/dev/null | head -n 1
116
+ }
117
+
118
+ spw_codex_json_get_or_empty() {
119
+ file="$1"
120
+ key="$2"
121
+ [ -f "$file" ] || return 1
122
+ python3 - "$file" "$key" <<'PY'
123
+ import json
124
+ import sys
125
+
126
+ path, dotted_key = sys.argv[1:]
127
+ MAX_JSON_NESTING = 256
128
+
129
+ def reject_constant(constant):
130
+ raise ValueError(f"non-standard numeric constant: {constant}")
131
+
132
+ def nesting_exceeds_limit(value):
133
+ stack = [(value, 0)]
134
+ while stack:
135
+ current, depth = stack.pop()
136
+ if isinstance(current, dict):
137
+ next_depth = depth + 1
138
+ if next_depth > MAX_JSON_NESTING:
139
+ return True
140
+ stack.extend((child, next_depth) for child in current.values())
141
+ elif isinstance(current, list):
142
+ next_depth = depth + 1
143
+ if next_depth > MAX_JSON_NESTING:
144
+ return True
145
+ stack.extend((child, next_depth) for child in current)
146
+ return False
147
+
148
+ try:
149
+ with open(path, "r", encoding="utf-8") as handle:
150
+ data = json.load(handle, parse_constant=reject_constant)
151
+ except (OSError, UnicodeError, json.JSONDecodeError, RecursionError, ValueError):
152
+ sys.exit(1)
153
+
154
+ if nesting_exceeds_limit(data) or not isinstance(data, dict):
155
+ sys.exit(1)
156
+
157
+ value = data
158
+ for part in dotted_key.split("."):
159
+ if not isinstance(value, dict):
160
+ value = ""
161
+ break
162
+ value = value.get(part, "")
163
+
164
+ if value is None:
165
+ value = ""
166
+ if not isinstance(value, str):
167
+ sys.exit(1)
168
+ print(value)
169
+ PY
170
+ }
171
+
172
+ spw_codex_metadata_commit_or_empty() {
173
+ file="$1"
174
+ if ! commit=$(spw_codex_json_get_or_empty "$file" "commit"); then
175
+ return 1
176
+ fi
177
+ case "$commit" in
178
+ ""|*[!0-9a-fA-F]*) return 1 ;;
179
+ esac
180
+ case "${#commit}" in
181
+ 7|40) printf '%s\n' "$commit" ;;
182
+ *) return 1 ;;
183
+ esac
184
+ }
185
+
186
+ spw_apply_manifest_overlay() {
187
+ manifest="$1"
188
+ version="$2"
189
+ python3 - "$manifest" "$version" <<'PY'
190
+ import json
191
+ import sys
192
+
193
+ path, version = sys.argv[1:]
194
+ MAX_JSON_NESTING = 256
195
+
196
+ def reject_constant(constant):
197
+ raise ValueError(f"non-standard numeric constant: {constant}")
198
+
199
+ def nesting_exceeds_limit(value):
200
+ stack = [(value, 0)]
201
+ while stack:
202
+ current, depth = stack.pop()
203
+ if isinstance(current, dict):
204
+ next_depth = depth + 1
205
+ if next_depth > MAX_JSON_NESTING:
206
+ return True
207
+ stack.extend((child, next_depth) for child in current.values())
208
+ elif isinstance(current, list):
209
+ next_depth = depth + 1
210
+ if next_depth > MAX_JSON_NESTING:
211
+ return True
212
+ stack.extend((child, next_depth) for child in current)
213
+ return False
214
+
215
+ try:
216
+ with open(path, "r", encoding="utf-8") as f:
217
+ data = json.load(f, parse_constant=reject_constant)
218
+ except RecursionError:
219
+ sys.exit(f"JSON nesting exceeds limit in {path}")
220
+ except json.JSONDecodeError as exc:
221
+ sys.exit(
222
+ f"invalid manifest JSON in {path}: "
223
+ f"line {exc.lineno} column {exc.colno}: {exc.msg}"
224
+ )
225
+ except (OSError, UnicodeError) as exc:
226
+ sys.exit(f"cannot read manifest JSON in {path}: {exc}")
227
+ except ValueError as exc:
228
+ sys.exit(f"invalid manifest JSON in {path}: {exc}")
229
+
230
+ if nesting_exceeds_limit(data):
231
+ sys.exit(f"JSON nesting exceeds limit in {path}")
232
+
233
+ if not isinstance(data, dict):
234
+ sys.exit(f"manifest must be a JSON object: {path}")
235
+
236
+ data["version"] = version
237
+ data["skills"] = "./skills/"
238
+ data.pop("hooks", None)
239
+
240
+ try:
241
+ with open(path, "w", encoding="utf-8") as f:
242
+ json.dump(data, f, indent=2, allow_nan=False)
243
+ f.write("\n")
244
+ except RecursionError as exc:
245
+ sys.exit(f"manifest JSON nesting exceeds limit while writing {path}: {exc}")
246
+ except (OSError, UnicodeError, ValueError) as exc:
247
+ sys.exit(f"cannot write manifest JSON in {path}: {exc}")
248
+ PY
249
+ }
250
+
251
+ spw_manifest_short_sha_or_empty() {
252
+ file="$1"
253
+ if ! version=$(spw_codex_json_get_or_empty "$file" "version"); then
254
+ return 1
255
+ fi
256
+ case "$version" in
257
+ *+manager.*)
258
+ short="${version##*.}"
259
+ case "$short" in
260
+ [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])
261
+ printf '%s\n' "$short"
262
+ ;;
263
+ esac
264
+ ;;
265
+ esac
266
+ }
267
+
268
+ spw_installed_commit_or_empty() {
269
+ installed_metadata=$(spw_find_installed_metadata || true)
270
+ installed_manifest=$(spw_find_installed_manifest || true)
271
+ installed_commit=""
272
+ if [ -n "$installed_metadata" ]; then
273
+ installed_commit=$(spw_codex_metadata_commit_or_empty "$installed_metadata" || true)
274
+ fi
275
+ if [ -z "$installed_commit" ] && [ -n "$installed_manifest" ]; then
276
+ installed_commit=$(spw_manifest_short_sha_or_empty "$installed_manifest" || true)
277
+ fi
278
+ printf '%s\n' "$installed_commit"
279
+ }
280
+
281
+ spw_codex_emit() {
282
+ operation="$1"
283
+ ok="$2"
284
+ result_json="$3"
285
+ code="$4"
286
+ error_message="$5"
287
+ hints_file="$6"
288
+ messages_file="$7"
289
+ python3 - "$operation" "$ok" "$result_json" "$code" "$error_message" "$hints_file" "$messages_file" <<'PY'
290
+ import json
291
+ import sys
292
+
293
+ operation, ok_text, result_text, code, error_message, hints_path, messages_path = sys.argv[1:]
294
+
295
+ def has_terminal_control(value):
296
+ return any(
297
+ ord(char) < 0x20
298
+ or 0x7f <= ord(char) <= 0x9f
299
+ or 0xd800 <= ord(char) <= 0xdfff
300
+ for char in value
301
+ )
302
+
303
+ if any(has_terminal_control(value) for value in (operation, code, error_message)):
304
+ raise SystemExit("protocol strings must not contain terminal control characters")
305
+
306
+ messages = []
307
+ if messages_path:
308
+ with open(messages_path, encoding="utf-8") as handle:
309
+ for number, raw in enumerate(handle, 1):
310
+ line = raw.rstrip("\n")
311
+ if "\t" not in line:
312
+ raise SystemExit(f"invalid message record at line {number}")
313
+ channel, text = line.split("\t", 1)
314
+ if (
315
+ channel not in {"stdout", "stderr"}
316
+ or not text
317
+ or "\t" in text
318
+ or "\r" in text
319
+ or has_terminal_control(text)
320
+ ):
321
+ raise SystemExit(f"invalid message record at line {number}")
322
+ messages.append({"channel": channel, "text": text})
323
+
324
+ ok = ok_text == "true"
325
+ if ok:
326
+ envelope = {
327
+ "protocol": 1,
328
+ "operation": operation,
329
+ "ok": True,
330
+ "messages": messages,
331
+ "result": json.loads(result_text),
332
+ "error": None,
333
+ }
334
+ else:
335
+ hints = []
336
+ if hints_path:
337
+ with open(hints_path, encoding="utf-8") as handle:
338
+ hints = [line.rstrip("\n") for line in handle if line.rstrip("\n")]
339
+ if any(has_terminal_control(hint) for hint in hints):
340
+ raise SystemExit("protocol hints must not contain terminal control characters")
341
+ envelope = {
342
+ "protocol": 1,
343
+ "operation": operation,
344
+ "ok": False,
345
+ "messages": messages,
346
+ "result": None,
347
+ "error": {"code": code, "message": error_message, "hints": hints},
348
+ }
349
+ json.dump(envelope, sys.stdout, allow_nan=False, separators=(",", ":"))
350
+ sys.stdout.write("\n")
351
+ PY
352
+ }
353
+
354
+ spw_codex_success() {
355
+ spw_codex_emit "$1" true "$2" "" "" "" "$3"
356
+ }
357
+
358
+ spw_codex_failure() {
359
+ spw_codex_emit "$1" false '{}' "$2" "$3" "$4" "$5"
360
+ exit 1
361
+ }
362
+
363
+ # Append command output as structured message records while keeping the
364
+ # tab-delimited spool format unambiguous. Each physical command-output line is
365
+ # escaped with Python's unicode_escape codec so literal backslashes remain
366
+ # distinguishable from rendered control characters like \t and \r.
367
+ spw_codex_append_messages() {
368
+ messages_file="$1"
369
+ channel="$2"
370
+ input_file="$3"
371
+ [ -f "$input_file" ] || return 0
372
+ python3 - "$messages_file" "$channel" "$input_file" <<'PY'
373
+ from pathlib import Path
374
+ import sys
375
+
376
+ messages_path = Path(sys.argv[1])
377
+ channel = sys.argv[2]
378
+ input_path = Path(sys.argv[3])
379
+
380
+ chunks = input_path.read_bytes().split(b"\n")
381
+ with messages_path.open("a", encoding="utf-8") as handle:
382
+ for chunk in chunks:
383
+ if not chunk:
384
+ continue
385
+ text = chunk.decode("utf-8", errors="backslashreplace")
386
+ escaped = text.encode("unicode_escape").decode("ascii")
387
+ if not escaped:
388
+ continue
389
+ handle.write(f"{channel}\t{escaped}\n")
390
+ PY
391
+ }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env python3
2
- """Validate the wrapper-owned generated Superpowers plugin contract."""
2
+ """Validate the manager-owned generated Superpowers plugin contract."""
3
3
 
4
4
  from __future__ import annotations
5
5
 
@@ -53,7 +53,7 @@ def json_nesting_exceeds_limit(value: Any) -> bool:
53
53
 
54
54
  def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
55
55
  parser = argparse.ArgumentParser(
56
- description="Validate a generated Superpowers wrapper candidate."
56
+ description="Validate a generated Superpowers manager candidate."
57
57
  )
58
58
  parser.add_argument("--plugin-root", required=True)
59
59
  parser.add_argument("--source", required=True)
@@ -270,7 +270,7 @@ def validate_provenance(args: argparse.Namespace, plugin_root: Path, errors: lis
270
270
  if provenance is None:
271
271
  return
272
272
  if set(provenance) != PROVENANCE_KEYS:
273
- errors.append("provenance keys do not match the wrapper-owned contract")
273
+ errors.append("provenance keys do not match the manager-owned contract")
274
274
  expected = {
275
275
  "source": args.source,
276
276
  "requested_ref": args.requested_ref,
@@ -0,0 +1,92 @@
1
+ #!/bin/sh
2
+ # Sourced module; callers own set -eu.
3
+
4
+ spw_adapter_package_root() {
5
+ if [ -n "${SPW_PACKAGE_ROOT:-}" ]; then
6
+ printf '%s\n' "$SPW_PACKAGE_ROOT"
7
+ elif [ -n "${root:-}" ]; then
8
+ printf '%s\n' "$root"
9
+ else
10
+ spw_root
11
+ fi
12
+ }
13
+
14
+ SPW_ADAPTER_ROOT=$(spw_adapter_package_root)
15
+ SPW_ADAPTER="${SPW_ADAPTER:-$SPW_ADAPTER_ROOT/scripts/adapters/codex/adapter}"
16
+ SPW_ADAPTER_RESPONSE_VALIDATOR="${SPW_ADAPTER_RESPONSE_VALIDATOR:-$SPW_ADAPTER_ROOT/scripts/core/validate-adapter-response.py}"
17
+
18
+ spw_invoke_adapter() {
19
+ operation="$1"
20
+ result_file="$2"
21
+ inspect_view="$3"
22
+ shift 3
23
+ [ "${1:-}" = "--" ] || spw_die "internal adapter invocation missing --"
24
+ shift
25
+
26
+ response_file="${result_file}.response"
27
+ adapter_exit=0
28
+ "$SPW_ADAPTER" "$operation" "$@" > "$response_file" || adapter_exit=$?
29
+
30
+ args=""
31
+ if [ -n "$inspect_view" ]; then
32
+ args="$inspect_view"
33
+ fi
34
+ if [ -n "$args" ]; then
35
+ python3 -S "$SPW_ADAPTER_RESPONSE_VALIDATOR" \
36
+ --operation "$operation" --adapter-exit "$adapter_exit" \
37
+ --response "$response_file" --result "$result_file" \
38
+ --inspect-view "$inspect_view"
39
+ else
40
+ python3 -S "$SPW_ADAPTER_RESPONSE_VALIDATOR" \
41
+ --operation "$operation" --adapter-exit "$adapter_exit" \
42
+ --response "$response_file" --result "$result_file"
43
+ fi
44
+ }
45
+
46
+ spw_adapter_result_get() {
47
+ result_file="$1"
48
+ dotted_key="$2"
49
+ spw_json_get "$result_file" "$dotted_key"
50
+ }
51
+
52
+ spw_adapter_result_boolean() {
53
+ result_file="$1"
54
+ dotted_key="$2"
55
+ value=$(spw_adapter_result_get "$result_file" "$dotted_key")
56
+ case "$value" in
57
+ true|True)
58
+ printf 'true\n'
59
+ ;;
60
+ false|False)
61
+ printf 'false\n'
62
+ ;;
63
+ *)
64
+ spw_die "expected Boolean adapter result at $dotted_key in $result_file"
65
+ ;;
66
+ esac
67
+ }
68
+
69
+ spw_inspect_fingerprint() {
70
+ result_file="$1"
71
+ spw_invoke_adapter inspect "$result_file" fingerprint -- --view fingerprint
72
+ }
73
+
74
+ spw_inspect_ownership() {
75
+ result_file="$1"
76
+ spw_invoke_adapter inspect "$result_file" ownership -- --view ownership
77
+ }
78
+
79
+ spw_adapter_install() {
80
+ result_file="$1"
81
+ package_root="$2"
82
+ spw_invoke_adapter install "$result_file" "" -- --package-root "$package_root"
83
+ }
84
+
85
+ spw_adapter_uninstall() {
86
+ result_file="$1"
87
+ plugin_present="$2"
88
+ marketplace_present="$3"
89
+ spw_invoke_adapter uninstall "$result_file" "" -- \
90
+ --plugin-present "$plugin_present" \
91
+ --marketplace-present "$marketplace_present"
92
+ }
@@ -0,0 +1,35 @@
1
+ #!/bin/sh
2
+ # Sourced module; callers own set -eu.
3
+
4
+ spw_die() {
5
+ echo "error: $*" >&2
6
+ exit 1
7
+ }
8
+
9
+ spw_require_command() {
10
+ command_name="$1"
11
+ if ! command -v "$command_name" >/dev/null 2>&1; then
12
+ spw_die "required command not found: $command_name"
13
+ fi
14
+ }
15
+
16
+ spw_root() {
17
+ CDPATH= cd -- "$(dirname "$0")/.." && pwd
18
+ }
19
+
20
+ spw_copy_path_if_present() {
21
+ src="$1"
22
+ dst="$2"
23
+ if [ -e "$src" ]; then
24
+ rm -rf "$dst"
25
+ cp -R "$src" "$dst"
26
+ fi
27
+ }
28
+
29
+ spw_require_upstream_path() {
30
+ path="$1"
31
+ label="$2"
32
+ if [ ! -e "$path" ]; then
33
+ spw_die "required upstream path missing: $label"
34
+ fi
35
+ }
@@ -0,0 +1,127 @@
1
+ #!/bin/sh
2
+ # Sourced module; callers own set -eu.
3
+
4
+ # Replace the live tree with a single atomic rename, keeping a backup so a
5
+ # failed swap restores the previous working generated tree. candidate and
6
+ # live_root must be same-filesystem siblings for atomic renames.
7
+ spw_replace_generated_tree() {
8
+ candidate="$1"
9
+ live_root="$2"
10
+ parent=$(dirname "$live_root")
11
+ backup="$parent/.superpowers.bak.$$"
12
+
13
+ rm -rf "$backup"
14
+ if [ -e "$live_root" ]; then
15
+ mv "$live_root" "$backup"
16
+ fi
17
+ if mv "$candidate" "$live_root"; then
18
+ rm -rf "$backup"
19
+ else
20
+ if [ -e "$backup" ]; then
21
+ mv "$backup" "$live_root"
22
+ fi
23
+ rm -rf "$candidate"
24
+ spw_die "failed to install generated tree into $live_root; previous tree restored"
25
+ fi
26
+ }
27
+
28
+ spw_generated_metadata_path() (
29
+ generated_root="$1"
30
+ printf '%s\n' "$generated_root/plugins/superpowers/.superpowers-upstream.json"
31
+ )
32
+
33
+ spw_generated_commit_or_empty() (
34
+ generated_root="$1"
35
+ generated_metadata=$(spw_generated_metadata_path "$generated_root")
36
+ spw_metadata_commit_lenient_or_empty "$generated_metadata"
37
+ )
38
+
39
+ spw_require_no_legacy_state() {
40
+ identity_state="$1"
41
+ case "$identity_state" in
42
+ neither|manager)
43
+ return 0
44
+ ;;
45
+ legacy|both)
46
+ printf '%s\n' \
47
+ 'Legacy superpowers-wrapper Codex state is installed.' \
48
+ 'Run: npx superpowers-wrapper@0.1.1 uninstall' \
49
+ 'Then run: npx superpowers-manager install' >&2
50
+ return 1
51
+ ;;
52
+ *)
53
+ spw_die "unknown adapter identity state: $identity_state"
54
+ ;;
55
+ esac
56
+ }
57
+
58
+ spw_report_legacy_state() {
59
+ case "$1" in
60
+ legacy|both)
61
+ printf '%s\n' \
62
+ 'Legacy superpowers-wrapper Codex state remains installed.' \
63
+ 'Run: npx superpowers-wrapper@0.1.1 uninstall'
64
+ ;;
65
+ neither|manager)
66
+ ;;
67
+ *)
68
+ spw_die "unknown adapter identity state: $1"
69
+ ;;
70
+ esac
71
+ }
72
+
73
+ spw_verify_installed_fingerprint() {
74
+ desired_commit="$1"
75
+ install_result="$2"
76
+ inspect_result="$3"
77
+ if ! spw_inspect_fingerprint "$inspect_result"; then
78
+ echo "error: installed manager fingerprint inspection failed after install." >&2
79
+ return 1
80
+ fi
81
+ if ! installed_commit=$(spw_adapter_result_get "$inspect_result" "fingerprint"); then
82
+ echo "error: cannot parse installed manager fingerprint inspection result after install." >&2
83
+ return 1
84
+ fi
85
+ printf 'desired_commit=%s\n' "$desired_commit"
86
+ printf 'installed_commit=%s\n' "$installed_commit"
87
+ if [ -n "$installed_commit" ] && spw_commit_matches "$desired_commit" "$installed_commit"; then
88
+ echo "manager updated"
89
+ return 0
90
+ fi
91
+
92
+ hint=""
93
+ if [ -f "$install_result" ]; then
94
+ if [ -n "$installed_commit" ]; then
95
+ hint=$(spw_adapter_result_get "$install_result" "verification_hints.mismatch" || true)
96
+ else
97
+ hint=$(spw_adapter_result_get "$install_result" "verification_hints.missing" || true)
98
+ fi
99
+ fi
100
+
101
+ if [ -n "$installed_commit" ]; then
102
+ echo "error: installed manager fingerprint does not match the prepared plugin after install." >&2
103
+ else
104
+ echo "error: installed manager fingerprint is not detectable after install." >&2
105
+ fi
106
+ if [ -n "$hint" ]; then
107
+ echo "hint: $hint" >&2
108
+ fi
109
+ return 1
110
+ }
111
+
112
+ spw_verify_uninstalled_resources() {
113
+ inspect_result="$1"
114
+
115
+ if ! plugin_present=$(spw_adapter_result_boolean "$inspect_result" "resources.plugin"); then
116
+ return 1
117
+ fi
118
+ if ! marketplace_present=$(spw_adapter_result_boolean "$inspect_result" "resources.marketplace"); then
119
+ return 1
120
+ fi
121
+ if [ "$plugin_present" = true ]; then
122
+ spw_die "owned plugin resource is still installed after removal"
123
+ fi
124
+ if [ "$marketplace_present" = true ]; then
125
+ spw_die "owned marketplace resource is still registered after removal"
126
+ fi
127
+ }