pi-python-helper 0.4.1 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ does not guarantee a stable public tool schema.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.2] - 2026-09-21
11
+
12
+ ### Removed
13
+
14
+ - `src/core/safety.ts` is gone. The tools gate state changes with an explicit `execute: true`, so the Python risk classifier had no production caller and was maintained dead code. The expected classification of Python commands is kept as an executable spec in `test/core.test.ts`, exercised against `pi-helper-core`'s classifier.
15
+
10
16
  ## [0.4.1] - 2026-09-21
11
17
 
12
18
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-python-helper",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Python (uv) development tools for the pi coding agent",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -1,109 +0,0 @@
1
- /**
2
- * Python's risk rules for the shared classifier.
3
- *
4
- * Python has no equivalent of a `cmd_vel` topic that deterministically signals
5
- * actuation, so risk is read from the command text. Segment splitting, safe
6
- * override precedence, and the compound-command merge live in
7
- * `pi-helper-core`; this module supplies only the package-manager, environment,
8
- * and migration rules that are specific to Python. The universal rules (git
9
- * history, file deletion, destructive SQL, containers, pipe-to-shell) are
10
- * applied by the core and must not be repeated here.
11
- */
12
- import {
13
- classifyCommand as coreClassifyCommand,
14
- isMutatingCommand as coreIsMutatingCommand,
15
- riskOf as coreRiskOf,
16
- type CommandRisk,
17
- type RiskRule,
18
- type SafetyRules,
19
- } from 'pi-helper-core';
20
-
21
- export { splitCommandSegments } from 'pi-helper-core';
22
- export type { CommandClassification, CommandRisk } from 'pi-helper-core';
23
-
24
- /**
25
- * Safe overrides are matched before risk patterns so a read-only form does not
26
- * inherit the risk of the command it qualifies. Only the Python-specific
27
- * read-only forms live here; `--check`, `--dry-run`, and `--collect-only` are
28
- * already universal overrides in the core.
29
- */
30
- const PYTHON_SAFE_OVERRIDES: RegExp[] = [
31
- /\buv\s+(?:tree|export|version|help)\b/,
32
- /\buv\s+pip\s+(?:list|freeze|check)\b/,
33
- /\bruff\s+(?:check|format)\b[^&|;]*(?:--diff|--check|--no-cache)\b/,
34
- /\bmypy\b[^&|;]*--no-incremental\b/,
35
- ];
36
-
37
- const PYTHON_RISK_PATTERNS: RiskRule[] = [
38
- // Irreversible: cannot be undone by a local revert.
39
- {
40
- risk: 'irreversible',
41
- pattern: /\b(?:uv|poetry|flit|hatch)\s+publish\b|\btwine\s+upload\b/,
42
- reason: 'Publishing to a package index is public and cannot be retracted.',
43
- },
44
- {
45
- risk: 'irreversible',
46
- pattern: /\b(?:conda|mamba)\s+env\s+remove\b|\bconda\s+remove\b[^&|;]*--all\b/,
47
- reason: 'Removing an environment destroys installed state.',
48
- },
49
- {
50
- risk: 'irreversible',
51
- pattern: /\b(?:alembic|manage\.py)\b[^&|;]*(?:downgrade|\bzero\b)/,
52
- reason: 'Reversing a database migration can drop data.',
53
- },
54
-
55
- // Mutating: changes project, environment, or remote state but is recoverable.
56
- {
57
- risk: 'mutating',
58
- pattern: /\b(?:uv|pdm|poetry)\s+(?:add|remove|sync|lock|update|venv)\b/,
59
- reason: 'Modifies the environment or the lockfile.',
60
- },
61
- {
62
- risk: 'mutating',
63
- pattern: /\buv\s+pip\s+(?:install|uninstall|sync)\b/,
64
- reason: 'Changes installed packages in the active environment.',
65
- },
66
- {
67
- risk: 'mutating',
68
- pattern: /\b(?:pip|pip3)\s+(?:install|uninstall)\b/,
69
- reason: 'Changes installed packages in the active environment.',
70
- },
71
- {
72
- risk: 'mutating',
73
- pattern: /\b(?:conda|mamba)\s+(?:install|create|update|remove)\b/,
74
- reason: 'Changes conda environment state.',
75
- },
76
- {
77
- risk: 'mutating',
78
- pattern: /\b(?:alembic|manage\.py)\b[^&|;]*\b(?:upgrade|migrate|makemigrations)\b/,
79
- reason: 'Applies a schema change to a database.',
80
- },
81
- {
82
- risk: 'mutating',
83
- pattern: /\bpre-commit\s+(?:install|autoupdate|run|clean)\b/,
84
- reason: 'Rewrites hook configuration or working tree files.',
85
- },
86
- ];
87
-
88
- const PYTHON_RULES: Partial<SafetyRules> = {
89
- safeOverrides: PYTHON_SAFE_OVERRIDES,
90
- patterns: PYTHON_RISK_PATTERNS,
91
- };
92
-
93
- /**
94
- * Classify a shell command by the highest risk of its segments. Used to warn
95
- * before a tool runs something that cannot be undone, and to gate this
96
- * package's own environment-modifying commands behind explicit opt-in.
97
- */
98
- export function classifyCommand(command: string): import('pi-helper-core').CommandClassification {
99
- return coreClassifyCommand(command, PYTHON_RULES);
100
- }
101
-
102
- export function isMutatingCommand(command: string): boolean {
103
- return coreIsMutatingCommand(command, PYTHON_RULES);
104
- }
105
-
106
- /** Commands that this package runs itself always carry a known risk class. */
107
- export function riskOf(args: string[]): CommandRisk {
108
- return coreRiskOf(args, PYTHON_RULES);
109
- }