fix(config): resolve Python reliably, add command-safety hook, harden CI
- Resolve Python 3.11+ through shared Resolve-Python.ps1/resolve-python.sh, which probe python, python3 and py -3 and skip the Windows Store alias. Build and capability checks fail early with an actionable message; doctor reports missing Python and the skipped hooks. - Fix check-capabilities.sh comparing only the major version. - Register Validate-CommandSafety as a PreToolUse hook for Claude and Codex; shared logic in command-safety.py catches rm -rf variants, git reset --hard, git clean -f, Remove-Item -Recurse, del/rd /s /q and nested shells. - Replace duplicated placeholder chains in both builds with adapters/placeholders.tsv. - Restore shell parity: add test-capabilities.sh, rename credentials.ps1 to with-credential.ps1 and qmd-warm.sh to start-qmd-warm.sh. - CI: build once and pass generated/ as an artifact, lint Python with ruff and JavaScript modules with node --check, require SHA pins for all actions. - Add evals for all own skills and update documentation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e19aa2e27c
commit
79694fbaa2
95 files changed
+1838
-218
No files matched your search
@@ -8,13 +8,17 @@ import tomllib
|
||||
from personal_instructions import CLIENT_FILES, render
|
||||
|
||||
|
||||
# Hook scripts this configuration installs; merges replace these and keep any foreign hooks.
|
||||
OWNED_HOOK_PATTERN = r'(?:flashbang|statusline|record-compact|session-state-pointer|qmd-warm|Start-QmdWarm|completion-?evidence|correction-?prompt|command-?safety)\.(?:ps1|sh)'
|
||||
|
||||
|
||||
def is_flashbang(hook):
|
||||
return any(re.search(r'(?:[/\\\s"\x27]|^)flashbang\.(?:ps1|sh)(?:[\s"\x27]|$)', str(hook.get(key, '')), re.I)
|
||||
for key in ('command', 'command_windows'))
|
||||
|
||||
|
||||
def is_qmd_warm(hook):
|
||||
return any(re.search(r'(?:[/\\\s"\x27]|^)(?:qmd-warm\.sh|Start-QmdWarm\.ps1)(?:[\s"\x27]|$)', str(hook.get(key, '')), re.I)
|
||||
return any(re.search(r'(?:[/\\\s"\x27]|^)(?:(?:start-)?qmd-warm\.sh|Start-QmdWarm\.ps1)(?:[\s"\x27]|$)', str(hook.get(key, '')), re.I)
|
||||
for key in ('command', 'command_windows'))
|
||||
|
||||
|
||||
@@ -108,7 +112,7 @@ def merge_json(current, managed):
|
||||
for key, value in managed.items():
|
||||
if key == 'hooks' and isinstance(value, dict) and isinstance(result.get(key), dict):
|
||||
hooks = dict(result[key])
|
||||
for event in set(value) | {'Stop', 'SessionStart', 'UserPromptSubmit'}:
|
||||
for event in set(value) | {'Stop', 'SessionStart', 'UserPromptSubmit', 'PreToolUse'}:
|
||||
groups = value.get(event, [])
|
||||
old_groups = hooks.get(event, [])
|
||||
if isinstance(groups, list) and isinstance(old_groups, list):
|
||||
@@ -118,7 +122,7 @@ def merge_json(current, managed):
|
||||
retained.append(group)
|
||||
continue
|
||||
foreign = [hook for hook in group['hooks'] if not (isinstance(hook, dict) and re.search(
|
||||
r'(?:flashbang|statusline|record-compact|session-state-pointer|qmd-warm|Start-QmdWarm|completion-?evidence|correction-?prompt)\.(?:ps1|sh)',
|
||||
OWNED_HOOK_PATTERN,
|
||||
str(hook.get('command', '')) + str(hook.get('command_windows', '')), re.I))]
|
||||
if foreign:
|
||||
retained.append(dict(group, hooks=foreign))
|
||||
@@ -167,7 +171,7 @@ def merge_toml(current_text, managed_text, statusline_enabled=True):
|
||||
managed_headers = {header for header, _ in managed_sections}
|
||||
extras = []
|
||||
fields_by_header = {}
|
||||
owned_pattern = r'(?:flashbang|statusline|record-compact|session-state-pointer|qmd-warm|Start-QmdWarm|completion-?evidence|correction-?prompt)\.(?:ps1|sh)'
|
||||
owned_pattern = OWNED_HOOK_PATTERN
|
||||
for index, (header, block) in enumerate(current_sections):
|
||||
plugin_table = re.match(r'^\[(?:plugins|marketplaces)(?:\.|\])', header)
|
||||
array_table = header.startswith('[[')
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck source=../../shared/hooks/scripts/resolve-python.sh
|
||||
. "$(dirname -- "${BASH_SOURCE[0]}")/../../shared/hooks/scripts/resolve-python.sh"
|
||||
resolve_python || true
|
||||
# shellcheck disable=SC2154
|
||||
|
||||
read_install_boolean() {
|
||||
@@ -22,7 +25,7 @@ read_install_options() {
|
||||
semantic_retrieval=false
|
||||
local saved key value
|
||||
if [ -f "$home_path/.my-ai-configuration/selection.json" ]; then
|
||||
if saved=$(python3 "$root/scripts/lib/selection-state.py" read --home "$home_path" --manifest "$root/adapters/plugins.tsv" --format tsv --allow-legacy); then
|
||||
if saved=$(run_python "$root/scripts/lib/selection-state.py" read --home "$home_path" --manifest "$root/adapters/plugins.tsv" --format tsv --allow-legacy); then
|
||||
while IFS=$'\t' read -r key value; do
|
||||
value=${value%$'\r'}
|
||||
case "$key" in flashbang) flashbang=$value ;; statusline) statusline=$value ;; semantic_retrieval) semantic_retrieval=$value ;; esac
|
||||
|
||||
@@ -333,7 +333,8 @@ class Manager:
|
||||
if client == 'claude' and item.get('enabled') is False:
|
||||
self.command([client, 'plugin', 'enable', selector])
|
||||
if record is not None and item.get('version') is not None:
|
||||
record['version'] = item['version']; self.save()
|
||||
record['version'] = item['version']
|
||||
self.save()
|
||||
return
|
||||
if item is not None and client == 'claude':
|
||||
self.command([client, 'plugin', 'marketplace', 'update', selector.rsplit('@', 1)[1]])
|
||||
@@ -343,7 +344,9 @@ class Manager:
|
||||
if record is not None:
|
||||
self.cache.pop(client, None)
|
||||
version = self.installed(client).get(selector, {}).get('version')
|
||||
if version is not None: record['version'] = version; self.save()
|
||||
if version is not None:
|
||||
record['version'] = version
|
||||
self.save()
|
||||
return
|
||||
marketplace = entry[client + '_marketplace']
|
||||
if marketplace not in ('', '-', 'openai-curated-remote'):
|
||||
@@ -363,7 +366,8 @@ class Manager:
|
||||
resolved_version = self.installed(client).get(selector, {}).get('version')
|
||||
if record is None:
|
||||
record = dict(client=client, name=entry['name'], kind='plugin', selector=selector, source=entry.get(client + '_marketplace', '-'))
|
||||
if resolved_version is not None: record['version'] = resolved_version
|
||||
if resolved_version is not None:
|
||||
record['version'] = resolved_version
|
||||
self.state['resources'].append(record)
|
||||
self.save()
|
||||
self.cache[client][selector] = {'scope': 'user'}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
. (Join-Path $PSScriptRoot '../../shared/hooks/scripts/Resolve-Python.ps1')
|
||||
function Get-ManagedManifestPath {
|
||||
param([Parameter(Mandatory=$true)][string]$Destination)
|
||||
return (Join-Path $Destination '.ai-config-manifest.tsv')
|
||||
@@ -117,7 +118,7 @@ function Invoke-InstallOptions {
|
||||
[System.IO.File]::WriteAllBytes($managedPath, $Managed)
|
||||
$Arguments += @('--managed', $managedPath)
|
||||
}
|
||||
& python (Join-Path $PSScriptRoot 'install-options.py') @Arguments --output $outputPath
|
||||
Invoke-Python (Join-Path $PSScriptRoot 'install-options.py') @Arguments --output $outputPath
|
||||
if ($LASTEXITCODE -ne 0) { throw $ErrorMessage }
|
||||
return [System.IO.File]::ReadAllText($outputPath, (New-Object System.Text.UTF8Encoding($false)))
|
||||
} finally {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck source=../../shared/hooks/scripts/resolve-python.sh
|
||||
. "$(dirname -- "${BASH_SOURCE[0]}")/../../shared/hooks/scripts/resolve-python.sh"
|
||||
resolve_python || true
|
||||
# Managed-file manifest: tracks every file this setup previously installed into a
|
||||
# destination so a later run can detect stale files (removed from the source) or
|
||||
# locally modified files (changed on disk since the last install) without ever
|
||||
@@ -146,7 +149,7 @@ run_managed_sync() {
|
||||
local entries entry entry_action entry_path entry_backup entry_hash entry_target
|
||||
local -a journal_lines
|
||||
# One stamp line, then one unit-separated line per file (an empty field must survive read).
|
||||
entries=$(python3 -c '
|
||||
entries=$(run_python -c '
|
||||
import json, sys
|
||||
journal = json.load(open(sys.argv[1], encoding="utf-8-sig"))
|
||||
lines = [str(journal["stamp"])]
|
||||
@@ -211,12 +214,12 @@ sys.stdout.buffer.write(("\n".join(lines) + "\n").encode("utf-8"))
|
||||
content=${content%$'\034'}
|
||||
needs_sub=false
|
||||
if { [ "$flashbang_enabled" = false ] || [ "$statusline_enabled" = false ] || [ "$semantic_retrieval_enabled" = false ]; } && [[ "$relative" = settings.json || "$relative" = config.toml ]]; then
|
||||
content=$(python3 "$(dirname -- "${BASH_SOURCE[0]}")/install-options.py" filter --path "$source_file" --flashbang "$flashbang_enabled" --statusline "$statusline_enabled" --semantic-retrieval "$semantic_retrieval_enabled" && printf '\034') || return
|
||||
content=$(run_python "$(dirname -- "${BASH_SOURCE[0]}")/install-options.py" filter --path "$source_file" --flashbang "$flashbang_enabled" --statusline "$statusline_enabled" --semantic-retrieval "$semantic_retrieval_enabled" && printf '\034') || return
|
||||
content=${content%$'\034'}
|
||||
needs_sub=true
|
||||
fi
|
||||
if [[ "$relative" = CLAUDE.md || "$relative" = AGENTS.md ]] || { [ "$semantic_retrieval_enabled" = false ] && [ "$relative" = rules/general.md ]; }; then
|
||||
content=$(python3 "$(dirname -- "${BASH_SOURCE[0]}")/install-options.py" filter-instructions --path "$source_file" --destination "$destination" --semantic-retrieval "$semantic_retrieval_enabled" && printf '\034') || return
|
||||
content=$(run_python "$(dirname -- "${BASH_SOURCE[0]}")/install-options.py" filter-instructions --path "$source_file" --destination "$destination" --semantic-retrieval "$semantic_retrieval_enabled" && printf '\034') || return
|
||||
content=${content%$'\034'}
|
||||
needs_sub=true
|
||||
fi
|
||||
@@ -234,12 +237,12 @@ sys.stdout.buffer.write(("\n".join(lines) + "\n").encode("utf-8"))
|
||||
new_hash=$(sha256_of_file "$source_file")
|
||||
fi
|
||||
if [ "$relative" = config.toml ] && [ -f "$target" ]; then
|
||||
content=$(printf '%s' "$content" | python3 "$(dirname -- "${BASH_SOURCE[0]}")/install-options.py" merge-toml --current "$target" --statusline "$statusline_enabled") || return
|
||||
content=$(printf '%s' "$content" | run_python "$(dirname -- "${BASH_SOURCE[0]}")/install-options.py" merge-toml --current "$target" --statusline "$statusline_enabled") || return
|
||||
needs_sub=true
|
||||
new_hash=$(sha256_of_string "$content")
|
||||
fi
|
||||
if [ "$relative" = settings.json ] && [ -f "$target" ]; then
|
||||
content=$(printf '%s' "$content" | python3 "$(dirname -- "${BASH_SOURCE[0]}")/install-options.py" merge-json --current "$target") || return
|
||||
content=$(printf '%s' "$content" | run_python "$(dirname -- "${BASH_SOURCE[0]}")/install-options.py" merge-json --current "$target") || return
|
||||
needs_sub=true
|
||||
new_hash=$(sha256_of_string "$content")
|
||||
fi
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
. (Join-Path $PSScriptRoot '../../shared/hooks/scripts/Resolve-Python.ps1')
|
||||
function Invoke-PluginCommand {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$Command,
|
||||
@@ -161,7 +162,7 @@ function Invoke-ManagedExtensions {
|
||||
if ($Update) { $arguments += '--update' }
|
||||
if ($Summary) { $arguments += '--summary' }
|
||||
if ($PSBoundParameters.ContainsKey('Entries')) { $arguments += '--selected'; $arguments += @($Entries | ForEach-Object { $_.name }) }
|
||||
& python @arguments
|
||||
Invoke-Python @arguments
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Managed extension reconciliation failed.' }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck source=../../shared/hooks/scripts/resolve-python.sh
|
||||
. "$(dirname -- "${BASH_SOURCE[0]}")/../../shared/hooks/scripts/resolve-python.sh"
|
||||
resolve_python || true
|
||||
set -euo pipefail
|
||||
|
||||
plugin_installed() {
|
||||
@@ -6,7 +9,7 @@ plugin_installed() {
|
||||
local inventory
|
||||
command -v "$client" >/dev/null 2>&1 || return 1
|
||||
inventory=$("$client" plugin list --json) || return 2
|
||||
printf '%s' "$inventory" | python3 -c '
|
||||
printf '%s' "$inventory" | run_python -c '
|
||||
import json, sys
|
||||
try:
|
||||
client, plugin = sys.argv[1:]
|
||||
@@ -70,7 +73,7 @@ mcporter_server_installed() {
|
||||
local path="$1/.mcporter/mcporter.json" server=$2 url=$3
|
||||
if [ -L "$1/.mcporter" ] || [ -L "$path" ]; then printf 'MCPorter configuration path contains a link.\n' >&2; return 2; fi
|
||||
[ -f "$path" ] || return 1
|
||||
python3 -c '
|
||||
run_python -c '
|
||||
import json, sys
|
||||
try:
|
||||
with open(sys.argv[1], encoding="utf-8-sig") as stream:
|
||||
@@ -193,7 +196,7 @@ managed_extensions() {
|
||||
local -n extension_names_ref=$selected_name
|
||||
arguments+=(--selected "${extension_names_ref[@]}")
|
||||
fi
|
||||
python3 "${arguments[@]}"
|
||||
run_python "${arguments[@]}"
|
||||
}
|
||||
|
||||
sync_configured_plugins() {
|
||||
|
||||
+3
-2
@@ -1,9 +1,10 @@
|
||||
. (Join-Path $PSScriptRoot '../../shared/hooks/scripts/Resolve-Python.ps1')
|
||||
function Sync-Qmd {
|
||||
param([Parameter(Mandatory=$true)][string]$RepositoryRoot,[Parameter(Mandatory=$true)][string]$HomePath,[ValidateSet('Codex','Claude','Both')][Parameter(Mandatory=$true)][string]$Client,[Parameter(Mandatory=$true)][bool]$Enabled,[switch]$DryRun,[switch]$Update,[switch]$Summary)
|
||||
$arguments = @((Join-Path $PSScriptRoot 'qmd.py'), 'sync', '--root', $RepositoryRoot, '--home', $HomePath, '--client', $Client.ToLowerInvariant(), '--enabled', $Enabled.ToString().ToLowerInvariant())
|
||||
if ($DryRun) { $arguments += '--dry-run' }; if ($Update) { $arguments += '--update' }
|
||||
if ($Summary) { $arguments += '--summary' }
|
||||
& python @arguments
|
||||
Invoke-Python @arguments
|
||||
if ($LASTEXITCODE -ne 0) { throw 'QMD local search reconciliation failed.' }
|
||||
}
|
||||
|
||||
@@ -11,7 +12,7 @@ function Test-QmdDevice {
|
||||
param([Parameter(Mandatory=$true)][string]$RepositoryRoot,[Parameter(Mandatory=$true)][string]$HomePath,[switch]$Summary)
|
||||
$arguments = @((Join-Path $PSScriptRoot 'qmd.py'), 'benchmark', '--root', $RepositoryRoot, '--home', $HomePath)
|
||||
if ($Summary) { $arguments += '--summary' }
|
||||
& python @arguments | Write-Host
|
||||
Invoke-Python @arguments | Write-Host
|
||||
if ($LASTEXITCODE -eq 0) { return $true }
|
||||
if ($LASTEXITCODE -eq 2) { return $false }
|
||||
throw 'QMD benchmark failed.'
|
||||
|
||||
+5
-2
@@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck source=../../shared/hooks/scripts/resolve-python.sh
|
||||
. "$(dirname -- "${BASH_SOURCE[0]}")/../../shared/hooks/scripts/resolve-python.sh"
|
||||
resolve_python || true
|
||||
|
||||
sync_qmd() {
|
||||
local root=$1 client=$2 home_path=$3 enabled=$4 dry_run=$5 update=$6 summary=${7:-false}
|
||||
@@ -6,7 +9,7 @@ sync_qmd() {
|
||||
[ "$dry_run" != true ] || arguments+=(--dry-run)
|
||||
[ "$update" != true ] || arguments+=(--update)
|
||||
[ "$summary" != true ] || arguments+=(--summary)
|
||||
python3 "${arguments[@]}"
|
||||
run_python "${arguments[@]}"
|
||||
}
|
||||
|
||||
test_qmd_device() {
|
||||
@@ -14,7 +17,7 @@ test_qmd_device() {
|
||||
local arguments=("$root/scripts/lib/qmd.py" benchmark --root "$root" --home "$home_path")
|
||||
[ "$summary" != true ] || arguments+=(--summary)
|
||||
local status
|
||||
if python3 "${arguments[@]}" >&2; then return 0; else status=$?; fi
|
||||
if run_python "${arguments[@]}" >&2; then return 0; else status=$?; fi
|
||||
[ "$status" -eq 2 ] && return 1
|
||||
return 2
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
. (Join-Path $PSScriptRoot '../../shared/hooks/scripts/Resolve-Python.ps1')
|
||||
function Read-UpdateSelection {
|
||||
param([string]$HomePath, [string]$RepositoryRoot, [switch]$AllowLegacy)
|
||||
$arguments = @((Join-Path $PSScriptRoot 'selection-state.py'), 'read', '--home', $HomePath, '--manifest', (Join-Path $RepositoryRoot 'adapters/plugins.tsv'))
|
||||
if ($AllowLegacy) { $arguments += '--allow-legacy' }
|
||||
$output = & python @arguments
|
||||
$output = Invoke-Python @arguments
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not load the saved selection.' }
|
||||
return ($output | Out-String | ConvertFrom-Json)
|
||||
}
|
||||
@@ -14,6 +15,6 @@ function Save-UpdateSelection {
|
||||
$arguments += @($Plugins.Selected | ForEach-Object { $_.name })
|
||||
$arguments += '--deselected'
|
||||
$arguments += @($Plugins.Deselected | ForEach-Object { $_.name })
|
||||
& python @arguments
|
||||
Invoke-Python @arguments
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not save the selection.' }
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck source=../../shared/hooks/scripts/resolve-python.sh
|
||||
. "$(dirname -- "${BASH_SOURCE[0]}")/../../shared/hooks/scripts/resolve-python.sh"
|
||||
resolve_python || true
|
||||
# shellcheck disable=SC2154
|
||||
|
||||
read_update_selection() {
|
||||
local saved key value
|
||||
saved=$(python3 "$root/scripts/lib/selection-state.py" read --home "$home_path" --manifest "$root/adapters/plugins.tsv" --format tsv) || return
|
||||
saved=$(run_python "$root/scripts/lib/selection-state.py" read --home "$home_path" --manifest "$root/adapters/plugins.tsv" --format tsv) || return
|
||||
selected_plugins=()
|
||||
deselected_plugins=()
|
||||
while IFS=$'\t' read -r key value; do
|
||||
@@ -21,7 +24,7 @@ read_update_selection() {
|
||||
}
|
||||
|
||||
save_update_selection() {
|
||||
python3 "$root/scripts/lib/selection-state.py" write --home "$home_path" --manifest "$root/adapters/plugins.tsv" \
|
||||
run_python "$root/scripts/lib/selection-state.py" write --home "$home_path" --manifest "$root/adapters/plugins.tsv" \
|
||||
--shell "$shell" --client "$client" --flashbang "$flashbang" --statusline "${statusline:-true}" --semantic-retrieval "${semantic_retrieval:-false}" \
|
||||
--selected "${selected_plugins[@]}" --deselected "${deselected_plugins[@]}"
|
||||
}
|
||||
File renamed without changes.
@@ -7,7 +7,7 @@ shift 2
|
||||
[ $# -gt 0 ] || { printf 'Child command is required.\n' >&2; exit 1; }
|
||||
|
||||
case "$client" in codex|Codex) client=Codex ;; claude|Claude) client=Claude ;; *) printf 'Unknown client: %s\n' "$client" >&2; exit 1 ;; esac
|
||||
case "$key" in [A-Za-z_][A-Za-z0-9_]* ) ;; *) printf 'Credential key must be an environment-variable-compatible name.\n' >&2; exit 1 ;; esac
|
||||
[[ "$key" =~ ^[A-Za-z_][A-Za-z0-9_]{0,127}$ ]] || { printf 'Credential key must be an environment-variable-compatible name.\n' >&2; exit 1; }
|
||||
|
||||
powershell_command=$(command -v powershell.exe || command -v powershell || command -v pwsh || true)
|
||||
[ -n "$powershell_command" ] || { printf 'PowerShell is required to read the Windows credential store.\n' >&2; exit 1; }
|
||||
|
||||
Reference in new issue
Block a user