ph-stabilize
The rows that keep a long session stable: a plan, offloading in both directions, compaction, limits, a human in the loop, and path rules. Each one is a row on a seam that already exists.
A row is an entry in a pH profile that mounts one plugin. The stabilization
features of Deep Agents are algorithms plus prompts, not runtime, so none of
them becomes a parameter on the agent loop. Todo planning is a tool plus a
prompt section. Offloading is a tools/post-execute listener. Summarization is
agent/pre-step. The driver does not know that any of them is there. That is
the integration thesis (D12). It is also the reason why a deployment that wants
the plain harness gets the plain harness.
phern --profile rlm-stable --provider llama --model <model> --mode tui
The package registers the stabilize bundle
(src/ph_stabilize/bundle.yaml). A bundle is a named list of rows that a
profile can layer. phern composes this bundle through the ph.bundles
entry-point group, and its module ph_app does not import this package.
Every profile that phern offers layers this bundle, base included. Each
profile layers it as an optional bundle: an install without this distribution
composes the same profiles and never compacts. Compaction is the row that
justifies this, because a session that grows until the provider refuses it is a
defect in any posture. The other rows come with it because a bundle is the unit
that a profile can name, and they are inert until they are configured.
phern doctor reports which rows activated.
The rows
| Row | What it does | Shipped |
|---|---|---|
tool-todo |
Adds write_todos, the todo/write event, the prompt section, and the rule of one call in each assistant message |
Off |
skill-steps |
Makes a SKILL.md that declares steps: into work that the turn must finish |
Off |
tool-result-offload |
Sends a result over the threshold to the spill store. The model gets a head-and-tail preview and the path | On |
input-offload |
Does the same in the other direction, for a pasted build log or a dumped table | On |
compaction-summarize |
Replaces the conversation with a summary when it no longer fits | On |
command-compact |
Adds /compact, the command that a user gives for the same thing |
On |
limits |
Sets ceilings on model calls, tool calls and children, plus a consecutive-failure breaker | On, every ceiling unset |
hitl |
Puts a person between the model and what it cannot take back | On, asks only about a destructive command |
permissions-fs |
Applies path rules over ctx.fs |
On, with one default write rule |
"On" mostly means "inert". Layering this bundle must not, by itself, change what a deployment does:
limitsmounts with every ceiling unset.hitlmounts with an emptyinterruptOnand one curated rule for the tools that declare themselves irreversible.permissions-fsmounts with rules that allow everything inside the workspace.
A harness that starts to ask on the first run teaches its user to approve without reading. A limit that nobody chose fires on the longest legitimate turn of some user.
The two rows that ship off are off for a different reason. They give the
model a tool or keep a turn going, and that is a posture that a profile chooses
and does not inherit. rlm-stable chooses the first: it turns tool-todo on.
That is why the bundle can reach every profile and not give every deployment a
todo tool. No shipped profile turns skill-steps on. A profile or a --patch
that wants skill-steps turns on both rows.
Three things are not inert on arrival:
permissions-fsships a rule that sends writes outside the workspace of the agent tointerrupt. That is the intended default of E6 and not an oversight. But it is a behavior change, and a deployment should know that it inherited the change.phern config --row permissions-fsprints the rules that are in force.hitlships itsdeclaredrule as thedestructivepreset. A tool that declares itself irreversible (bash, a code cell) asks when the parsed classifier finds something that it cannot take back (rm -rf,DROP TABLE,shutil.rmtree,curl | sh). Otherwise the tool runs without an ask. With no approval answerer mounted, an ask is a refusal.limitsships its breaker on, although every ceiling is unset. The breaker trips after five consecutive failures of one tool. Setbreaker.consecutiveFailurestonullto turn it off.
The tool, and the command
write_todos(rowtool-todo) replaces the whole list. The list is in the log and nowhere else. The TUI sidebar and the view of the model are therefore one projection, and not two that can disagree. The list also survives a resume and a fork with no extra work. The tool differs from upstream in two deliberate ways:requiresdeclares what a step waits on. Upstream works around the gap in prose, which is a dependency graph that nothing can read or check.- A completed entry carries
worked: the number of tools that the harness saw run while the entry was being finished. It is the one field that the model does not write, because a receipt that the claimant issues is not a receipt.
/compact(rowcommand-compact) replaces older history with a summary. You can tell it what you are about to work on. It is a command, not a turn: it dispatches directly and recordscommand/runandcommand/done. It requires the agent to be idle first. A compaction that landed in the middle of a turn would move the surface underneath a request that the loop had already derived.
Every failure is a sentence and not a traceback. CompactionError.code is a
closed set so that a front end can phrase each one.
Including it, and adjusting it
rlm-stable is rlm plus this bundle plus the rows that it turns on. Without a
profile that names the bundle, insert the rows that you want by name. They are
ordinary plugin entry points, so this works against any profile:
phern --patch '{insert: [{id: tool-result-offload, name: tool-result-offload}]}' \
--profile llama -p "…"
# $PH_HOME/profiles/rlm-stable.yaml: ceilings, and a narrower file rule
- id: limits
config:
modelCalls: {turnLimit: 40, sessionLimit: 400, exit: end}
toolCalls: {turnLimit: 100, perTool: {bash: {turnLimit: 20}}, exit: continue}
breaker: {consecutiveFailures: 5}
- id: permissions-fs
config:
rules:
- operations: [read]
paths: ["**/.env", "**/*.pem"]
mode: deny
- operations: [write]
paths: ["**"]
scope: outside-workspace
mode: interrupt
| Row | Config | Default |
|---|---|---|
tool-result-offload |
tokenLimit, maxInlineBytes, excludedTools |
20000; None disables offloading |
input-offload |
tokenLimit |
50000 |
compaction-summarize |
auto, triggerFraction, keepFraction, triggerTokens, keepMessages, maxTokens, summaryInputTokens, truncateArgs, overflowClipTokens |
0.85 / 0.10 of a known window. 170000 tokens / 6 messages when the window is not known. These are the numbers of upstream |
limits |
modelCalls (exit: end | error), toolCalls (plus perTool, exit: continue | end | error), children (exit: continue | end | error), breaker.consecutiveFailures. Each budget takes turnLimit and sessionLimit |
All ceilings unset; breaker 5 |
hitl |
mode (manual | auto | yolo), declared, interruptOn |
auto. declared is {preset: destructive}, so bash and a code cell ask when the classifier finds a destructive command, and run without an ask otherwise. interruptOn is empty |
permissions-fs |
rules. Each rule has operations, paths, scope (anywhere | outside-workspace), mode (default deny), and description |
One rule: write anywhere outside-workspace → interrupt |
skill-steps |
maxNudges, decision (provider, model, holdAt, timeoutMs) |
3. No decision model, so every unfinished procedure is nudged. With a decision model, a turn that ends to wait for a person is allowed to end, and a route that times out rests for a minute. See docs/skills |
tool-todo, command-compact |
None | No configuration |
Writing a hitl rule
Keys are tool names. Each key takes a preset, a when: list of regexes, a
description, and a set of allowed decisions. The rules of rlm-stable itself
are the worked example:
- id: hitl
config:
interruptOn:
bash:
preset: destructive
when: ["\\b(npm|pnpm|yarn|uv|pip)\\s+publish\\b", "\\bsudo\\b"]
description: >-
This command changes something a worktree cannot undo.
run_code:
preset: destructive
when: ["\\bsubprocess\\b"]
allowedDecisions: [approve, reject]
That rule says three things:
- Name the preset and do not retype it.
destructiveis the set that this package ships and tests. The first draft ofrlm-stable.yamlretyped a subset. It had already widenedgit pushfrom force-only to every push, against a shipped test that holds an ordinary push to be ordinary. One security judgment is better than two that disagree. - Key Code Mode on the reserved name. The registry renames the transport
to the name that the presentation gives it (
python, in therlmbundle), andhitlresolves that name. A key on the presented name would not turn the gate off: the tool declaresis_irreversible, sodeclaredstill catches it. But thewhen:additions are keyed by name, and they would stop applying with no error. - Four decisions, not two.
approveandrejectwere always reachable. This row addsedit(run the call with these arguments instead) andrespond(do not run the call, and tell the model this). To stop a turn to say "wrong path" or "you don't need that, the answer is X" costs a round trip, and an answer in place does not.allowedDecisionsnarrows the set. A program is not something to patch by hand in a modal, sorun_codeabove dropsedit.
The classifier parses. It does not match patterns. preset: destructive
runs ph_stabilize.destructive. That module reads each string argument in its
own dialect (shell through shlex, SQL as statements, Python through ast) and
judges the structure. The twelve regexes that it replaced ran over the
arguments of the call rendered as JSON. A real newline therefore became the two
characters \ and n, and every pattern anchored with \b stopped matching on
a second line. rm -rf, DROP TABLE, shutil.rmtree and curl | sh were all
ungated inside a multi-line cell, which is every run_code cell. Nothing
failed. The gate did not fire. A when: list is still regex, as the escape
hatch of the deployment, but it is matched against the decoded strings.
Limitations, and things that are deliberate
permissions-fsbounds only the access that goes through the seam (E9, N1). The rules attach to the intent waterfalls ofctx.fs. Any tool that goes through the seam is therefore covered, and this module does not need to know a tool name. A model-authoredopen(path, "w")inside a code cell, or asubprocessthat runs a shell command, never fires an intent, and these rules do not touch it. The rung below bounds those:code-runtime-pythonconfines the kernel itself. The row states its reach at mount and keeps the sentence onctx.fs_permissions.reach. The statement therefore changes with the sandbox. A paragraph in a README would be wrong half the time.- Offloading never deletes, and each direction keeps the original in its own
way. A paste is a surface
replace. The log keeps theuser/messageas it was sent,derive_messages()yields the preview, andtranscript()still shows the user what they sent. The alternative was to rewrite a message before it is logged, and that is refused: the log would then attribute text that the harness wrote to the human. A tool result is already written by the harness, so it is swapped before it is logged.tool/resultcarries the preview that the model saw, the full text is in the spill store, andoffload/spilledrecords where the text went. - Offloading fails open. If the spill write fails, the row keeps the original result. An offload that cannot store the content must not be the reason that the model loses it.
- Self-limiting tools are left alone, and they declare it themselves. A tool
that limits its own output and offers a way to page (
readwith an offset,grepwith a match cap) setsToolDefinition.self_limits. Upstream matches a hardcoded list of its tool names. pH asks the tool, because a deployment renames tools and an MCP server adds its own.excludedToolsis the escape hatch for a third-party tool whose author has not declared. - Compaction can decline. The cut is moved back to the nearest balanced
boundary, so a call is never split from its result. If the only balanced cut
is the start of the conversation, nothing is compacted. The automatic path
records nothing, and
/compactsays that there is no compactable history yet. To send an orphanedtool-resultto a provider that rejects it is not a repair. Two cheaper remedies run first: the row elides over-long call arguments in retained history, and then spills the trailing tool-result batch. - Limits are a fold over the log, not a counter in memory. A limit that is
kept in a field is lost on a resume. The thread and run of upstream map to
the session and turn of pH. The row renames them one time, so that a
diff against
model_call_limit.pystays readable. skill-stepsholds the model to the plan that it accepted, not to reality. When the model marks a step done, that is still only the word of the model. The row asserts only that work remains which can begin, and it never claims to know which step is running. The gates that check the world arectx.goalsandctx.approval. The row also needstool-todobeside it, and nothing checks thattool-todois there. The list thatskill-stepsseeds belongs totool-todo. Withoutwrite_todos, the steps are still seeded and the turn is still nudged, but the model cannot mark a step done. The row then spends its nudges and stands down. A profile that turnsskill-stepson turns on both rows.- Nothing shipped changes the mode of
hitlduring a session. The mode in force is the lastapproval/moderecord, or else themodeof the row.set_modewrites that record, but no command or key calls it. Today the mode is the one that the row of the profile sets. - A decision model is asked, never relied on.
skill-stepsasks a decision model whether a turn is ending to wait for a person (ctx.llm.decide). When it is, the row holds its nudge. Sometimes a route cannot be asked: it is unregistered, down, slow, or it answers in another shape. The row then sends the nudge that it always sent, with a warning and allm/decision-failedrecord. The row has noinjectonllm, on purpose.
Tests
tests/ has nine modules: one for each feature, plus one for the classifier.
The destructive-command tables are a starting point and are meant to grow. None
of them claims to be complete. The correct posture is for the gate to report
what it found, in the words of the parser. A person is then told what the
harness saw, and an auditor can tune the gate.
Metadata
Release files for ph-stabilize 0.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ph_stabilize-0.13.0.tar.gz | 197.9 kB | Without provenance | Details for ph_stabilize-0.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ph_stabilize-0.13.0-py3-none-any.whl | Python 3 | none | any | Details for ph_stabilize-0.13.0-py3-none-any.whl |
Total release size: 316.8 kB
Release files / ph_stabilize-0.13.0.tar.gz
| Download URL | ph_stabilize-0.13.0.tar.gz |
|---|---|
| Size | 197.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2b3387736f22d1df8369ee85b66a98af7101b4ad86e482771117ffe5cd42ff5
|
|
BLAKE2b-256 checksum How to use checksums |
8d3a42dc203e51d699033a5e77e1715667ce7f8db8d1ab605022605bf5113e36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / ph_stabilize-0.13.0-py3-none-any.whl
| Download URL | ph_stabilize-0.13.0-py3-none-any.whl |
|---|---|
| Size | 119.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64c806fb77f60c0054465cf5eed9a06e7e3bdaef3d885f7cb0db326a88d6003f
|
|
BLAKE2b-256 checksum How to use checksums |
72689d0f209d607b17c4cea0269522007d632089d8e3ebac23c2eabcebc52696
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for ph-stabilize 0.13.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.