pi-herdsman 0.1.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.
@@ -0,0 +1,133 @@
1
+ # `ask_owner` API
2
+
3
+ [Documentation index](../README.md)
4
+
5
+ `ask_owner` is mandatory managed-worker infrastructure for one direct-owner
6
+ decision required to continue the current assignment.
7
+
8
+ It is not a generic messaging channel.
9
+
10
+ ## Availability
11
+
12
+ Every valid managed worker receives the `ask_owner` tool at launch.
13
+
14
+ Normal definition `tools`, `excludeTools`, and `noTools` policy cannot remove
15
+ this infrastructure capability.
16
+
17
+ ## Request
18
+
19
+ ```json
20
+ {
21
+ "question": "Should I use option A or option B?",
22
+ "files": [".pi-herdsman/options.md", "diagram.png"]
23
+ }
24
+ ```
25
+
26
+ `question` must contain non-whitespace text.
27
+ `files` supplies supporting evidence using the same rules as `worker`: complete
28
+ strict UTF-8 text may be embedded, while other files are canonical local
29
+ references and are not copied or snapshotted. Relative paths use the worker's
30
+ working directory. This does not weaken the sole-final-tool-call rule.
31
+
32
+ ## Turn rule
33
+
34
+ `ask_owner` must be:
35
+
36
+ - the worker's only tool call in the turn;
37
+ - the final tool call of the turn.
38
+
39
+ The worker then stops and waits.
40
+
41
+ A call made alongside another tool call is rejected.
42
+
43
+ ## Eligibility
44
+
45
+ A worker can ask only while it has a valid active assignment and:
46
+
47
+ - has no outstanding ask;
48
+ - has no completed/final result pending;
49
+ - has no pending state transition;
50
+ - has no unacknowledged owner request;
51
+ - has no ordinary unresolved direct-worker work.
52
+
53
+ A delegation-enabled worker may ask its own owner when its unresolved direct
54
+ workers are themselves validly blocked on owner questions. Ordinary active
55
+ workers and pending worker results still block escalation.
56
+
57
+ ## Durable effect
58
+
59
+ On acceptance, Pi Herdsman creates one correlated ask record and sets
60
+ `pendingAskId` while preserving the original active assignment request ID.
61
+
62
+ The tool result tells the worker that the assignment is blocked and returns
63
+ details containing:
64
+
65
+ ```text
66
+ askId
67
+ assignmentRequestId
68
+ ```
69
+
70
+ The worker public state projects as `blocked` after the turn settles.
71
+
72
+ Final assignment settlement is disabled while the ask remains pending.
73
+
74
+ ## Owner delivery
75
+
76
+ The exact direct owner receives the question through the existing owner-session
77
+ delivery path.
78
+
79
+ The system does not automatically forward a worker question through an ownership
80
+ chain.
81
+
82
+ If a delegating worker needs a lead decision, it independently calls `ask_owner`
83
+ on its own direct ownership edge.
84
+
85
+ ## Reply
86
+
87
+ The direct owner answers through the `worker` tool:
88
+
89
+ ```json
90
+ {
91
+ "action": "reply",
92
+ "worker": "<exact worker>",
93
+ "message": "Use option B."
94
+ }
95
+ ```
96
+
97
+ The reply is correlated to:
98
+
99
+ - ask ID;
100
+ - original assignment request ID;
101
+ - run ID;
102
+ - owner session;
103
+ - workspace;
104
+ - worker label;
105
+ - pane;
106
+ - Pi session.
107
+
108
+ A mismatched or stale reply fails closed.
109
+
110
+ The worker clears the pending ask, acknowledges the reply request, and resumes
111
+ the same assignment with the owner answer.
112
+
113
+ ## One outstanding question
114
+
115
+ Only one `ask_owner` question may be outstanding per assignment at a time.
116
+
117
+ There is no ask timeout.
118
+
119
+ The worker must not guess the owner answer and complete while blocked.
120
+
121
+ Rejected calls identify the known eligibility reason, such as no active
122
+ assignment, an existing owner question, settling state, a pending control
123
+ request, or active direct-worker work.
124
+
125
+ ## Close
126
+
127
+ Closing the worker abandons the pending question as part of worker teardown.
128
+
129
+ ## See also
130
+
131
+ - [`worker` `reply`](worker.md#reply)
132
+ - [Lifecycle](../concepts/lifecycle.md)
133
+ - [Delegation](../concepts/delegation.md)
@@ -0,0 +1,121 @@
1
+ # `/workers` commands
2
+
3
+ [Documentation index](../README.md)
4
+
5
+ `/workers` is the human-facing worker-management command namespace.
6
+
7
+ It is separate from the structured model-facing `worker` API.
8
+
9
+ Commands require a lead Pi session with UI.
10
+
11
+ ## Usage
12
+
13
+ ```text
14
+ /workers
15
+ /workers agents
16
+ /workers placement [tab|split]
17
+ /workers stop
18
+ ```
19
+
20
+ The plain command opens a native Pi selection menu with `Running`,
21
+ `Definitions`, `Layout`, `Message limits`, and `Stop all…` destinations. The
22
+ Message limits view edits the independent inline attachment and mailbox
23
+ payload limits at global or trusted-project scope. It is available only to a
24
+ lead Pi session with UI.
25
+
26
+ ## `/workers agents`
27
+
28
+ Opens the native Definitions menu for the effective bundled, project, and
29
+ global roster. Project definitions are included only when the trusted project
30
+ setting `piHerdsman.projectAgents` is `true`. Project participation is marked
31
+ `[project]`; a global override adds `*` (so `[project] *` means both layers
32
+ contribute). Edits write global overrides only.
33
+
34
+ The details view can show:
35
+
36
+ - name and description;
37
+ - configured model and thinking;
38
+ - declared tool policy represented by definition metadata (not a complete
39
+ runtime capability probe);
40
+ - named skills;
41
+ - declared direct delegation;
42
+ - overridden/custom state;
43
+ - override/custom source path when relevant.
44
+
45
+ Bundled implementation paths are intentionally hidden from the human overview.
46
+
47
+ Structured `worker list` keeps exact deterministic metadata, including exact
48
+ source and skill paths when available.
49
+
50
+ `/workers agents` does not probe runtime tool availability.
51
+
52
+ Selecting a definition opens:
53
+
54
+ ```text
55
+ Model
56
+ Thinking
57
+ Enabled
58
+ Details…
59
+ Back
60
+ ```
61
+
62
+ Model selection refreshes Pi's registry and stores the canonical provider/model
63
+ token. `Use default` removes the selected field. Thinking uses Pi's supported
64
+ levels when the selected model is known.
65
+
66
+ When Pi provides an explicit scoped-model list, that scope is used. Otherwise
67
+ available models are offered.
68
+
69
+ Thinking options use the effective model's supported levels when resolvable,
70
+ or Pi Herdsman's validated vocabulary when not.
71
+
72
+ The command edits only the selected top-level `model`, `thinking`, or `enabled`
73
+ line in the global Markdown override. It preserves unrelated frontmatter and
74
+ the complete body.
75
+
76
+ Changes apply to future definition delegations and session continuations, not
77
+ already-running workers or the lead Pi session.
78
+
79
+ Standalone global definitions are editable too. Removing a field from one uses
80
+ Pi's normal default; removing a field from a bundled override restores the
81
+ bundled value.
82
+
83
+ ## `/workers` Running
84
+
85
+ Select a live managed agent from the shared status projection to focus its pane.
86
+ Pi Herdsman refreshes and verifies the exact label, pane, and session identity
87
+ before issuing herdr's focus command. If the worker changed, no focus command
88
+ is sent.
89
+
90
+ ## `/workers placement`
91
+
92
+ Selecting Layout opens a native selector showing the effective setting.
93
+ Explicit values continue to set directly:
94
+
95
+ ```text
96
+ /workers placement tab
97
+ /workers placement split
98
+ ```
99
+
100
+ See [Configuration](configuration.md).
101
+
102
+ ## `/workers stop`
103
+
104
+ Destructive lead-only emergency control.
105
+
106
+ It aborts the current lead turn and attempts to close the exactly proven owned
107
+ worker tree.
108
+
109
+ It reports discarded active work or durable pending results when present.
110
+
111
+ Cleanup uses existing exact ownership proofs and proceeds conservatively across
112
+ independent failures.
113
+
114
+ Use ordinary `worker close` for normal targeted model-driven control.
115
+
116
+ ## See also
117
+
118
+ - [`/chief` and chief mode](supervision.md)
119
+ - [`worker` API](worker.md)
120
+ - [Configuration](configuration.md)
121
+ - [Status widget](status-widget.md)
@@ -0,0 +1,130 @@
1
+ # Configuration
2
+
3
+ [Documentation index](../README.md)
4
+
5
+ Pi Herdsman intentionally has very little settings state.
6
+
7
+ Agent behavior lives in Markdown definitions. The extension settings currently
8
+ own worker placement.
9
+
10
+ ## Worker placement
11
+
12
+ Settings shape:
13
+
14
+ ```json
15
+ {
16
+ "piHerdsman": {
17
+ "spawnPlacement": "tab"
18
+ }
19
+ }
20
+ ```
21
+
22
+ Supported values:
23
+
24
+ ```text
25
+ tab
26
+ split
27
+ ```
28
+
29
+ Default:
30
+
31
+ ```text
32
+ tab
33
+ ```
34
+
35
+ `tab` places future workers in the managed worker-tab workflow.
36
+
37
+ `split` places future workers by splitting from the caller's tab/pane placement
38
+ boundary.
39
+
40
+ This affects future starts, not existing workers.
41
+
42
+ ## Message limits
43
+
44
+ Pi Herdsman uses two independent byte settings:
45
+
46
+ ```json
47
+ {
48
+ "piHerdsman": {
49
+ "inlineAttachmentLimitBytes": 131072,
50
+ "mailboxPayloadLimitBytes": 131072
51
+ }
52
+ }
53
+ ```
54
+
55
+ Each accepts an integer from 1024 bytes (1 KiB) through 1048576 bytes (1 MiB)
56
+ and defaults to 131072 bytes (128 KiB). The inline limit applies per file;
57
+ eligible complete strict UTF-8 files are embedded in caller order only when
58
+ the exact serialized mailbox record fits. Other files remain canonical
59
+ references. The mailbox limit is the exact serialized `RequestRecord` or
60
+ `AskRecord` admission size.
61
+
62
+ Valid trusted project values override valid global values. Invalid values are
63
+ ignored rather than clamped. Configure these values through `/workers` →
64
+ `Message limits`; the fixed 1 MiB protocol safety ceiling remains in force for
65
+ reading existing mailbox records.
66
+
67
+ ## Settings scope
68
+
69
+ Pi Herdsman reads Pi settings through Pi's settings manager.
70
+
71
+ Global settings are stored in the Pi agent directory's `settings.json`
72
+ (default `~/.pi/agent/settings.json`).
73
+
74
+ Project settings are stored in:
75
+
76
+ ```text
77
+ <project>/.pi/settings.json
78
+ ```
79
+
80
+ A project placement value is effective only when:
81
+
82
+ - the project is trusted by Pi; and
83
+ - the project setting is `tab` or `split`.
84
+
85
+ If no valid trusted project placement is active, the global value is used.
86
+
87
+ `/workers placement` opens a native selector showing the effective value and
88
+ offering `tab` or `split`. Selecting a value writes to the current effective
89
+ scope and verifies the value after writing; the confirmation reports whether
90
+ that scope is `project` or `global`.
91
+
92
+ ## Agent definitions are not extension settings
93
+
94
+ Do not put per-agent model, thinking, tool, skill, extension, body, or
95
+ delegation policy in `piHerdsman`.
96
+
97
+ Those belong in Markdown agent definitions.
98
+
99
+ Trusted project-local definitions can be enabled with this project-only
100
+ discovery gate in `<cwd>/.pi/settings.json`:
101
+
102
+ ```json
103
+ { "piHerdsman": { "projectAgents": true } }
104
+ ```
105
+
106
+ The default is disabled, and a global `projectAgents` value has no effect.
107
+ This setting enables discovery only; agent models, tools, bodies, extensions,
108
+ and delegation remain in Markdown definitions.
109
+
110
+ See:
111
+
112
+ - [Agent definitions](../guides/agent-definitions.md)
113
+ - [Agent-definition schema](agent-definition-schema.md)
114
+
115
+ ## herdr integration
116
+
117
+ The required Pi integration is installed separately:
118
+
119
+ ```sh
120
+ herdr integration install pi
121
+ herdr integration status
122
+ ```
123
+
124
+ Pi Herdsman requires integration version `2` or newer for supported native session
125
+ identity/restore behavior.
126
+
127
+ ## See also
128
+
129
+ - [`/workers` commands](commands.md)
130
+ - [Getting started](../getting-started.md)
@@ -0,0 +1,87 @@
1
+ # Errors
2
+
3
+ [Documentation index](../README.md)
4
+
5
+ Normal public `worker` failures use structured error details.
6
+
7
+ ## Shape
8
+
9
+ A structured error contains:
10
+
11
+ ```text
12
+ category
13
+ message
14
+ operation
15
+ rollbackOccurred
16
+ retryAttempted
17
+ ```
18
+
19
+ and may include:
20
+
21
+ ```text
22
+ ids
23
+ nextAction
24
+ primary
25
+ cleanup
26
+ details
27
+ ```
28
+
29
+ Do not discard `primary` when `cleanup` also failed.
30
+
31
+ `retryAttempted` is true only after a retry or recovery attempt is scheduled or
32
+ entered. It is preserved when a structured error is wrapped. Cleanup that is
33
+ still pending remains represented by cleanup evidence and retry wording; it
34
+ must not be presented as exhausted cleanup.
35
+
36
+ ## Categories
37
+
38
+ | Category | Meaning |
39
+ | -------------------------- | ----------------------------------------------------------------------------------- |
40
+ | `not_running_inside_herdr` | Required herdr environment is missing. |
41
+ | `worker_label_exists` | Requested/generated live label conflicts with an existing worker. |
42
+ | `pane_not_ready` | Worker pane/startup did not reach the required readiness boundary. |
43
+ | `target_not_found` | Exact requested identity or ownership evidence was not found. |
44
+ | `target_ambiguous` | More than one live candidate matched an identity that must be exact. |
45
+ | `rollback_failure` | Primary operation failed and cleanup did not fully converge. |
46
+ | `worker_busy` | Worker state does not allow the requested control action. |
47
+ | `invalid_request` | Request fields, values, definition input, file input, or preconditions are invalid. |
48
+ | `internal_failure` | An invariant or underlying operation failed outside a narrower public category. |
49
+
50
+ ## Identity failures
51
+
52
+ `target_not_found` can intentionally mean "could not prove this exact target",
53
+ not necessarily "nothing exists physically".
54
+
55
+ `target_ambiguous` means Pi Herdsman refuses to choose among multiple candidates.
56
+
57
+ Both are fail-closed behavior.
58
+
59
+ ## Rollback
60
+
61
+ When a worker launch fails, exact resources created by that attempt are cleaned
62
+ only when ownership is proved.
63
+
64
+ A `rollback_failure` can preserve:
65
+
66
+ - primary startup/control error;
67
+ - cleanup error;
68
+ - known label/pane/tab/session evidence;
69
+ - stage;
70
+ - next action.
71
+
72
+ Inspect these fields before another destructive attempt.
73
+
74
+ Model-facing error text surfaces available identity, stage, primary cause,
75
+ cleanup cause, and next action without discarding the structured details.
76
+
77
+ ## Model-visible truncation
78
+
79
+ Very large tool output can be bounded for model delivery. When full output is
80
+ persisted, tool details may include a `full_output_path`.
81
+
82
+ This is output presentation behavior, not an error category.
83
+
84
+ ## See also
85
+
86
+ - [Recovery](../guides/recovery.md)
87
+ - [`worker` API](worker.md)
@@ -0,0 +1,148 @@
1
+ # Status widget
2
+
3
+ [Documentation index](../README.md)
4
+
5
+ The TUI status widget is a local, display-only projection of exact managed
6
+ workers plus controller-local transient starting assignments.
7
+
8
+ It does not replace mailbox assignment/result authority.
9
+
10
+ An active chief receives a separate leads-only widget. It shows the
11
+ supervision projection, not managed worker rows. Its complete
12
+ overview, peek, and focus behavior is documented in the
13
+ [supervision reference](supervision.md). The two widgets are never combined.
14
+
15
+ The ambient supervision rows use `├─` for non-final visible leads and `└─` for the
16
+ final visible lead. Lead state glyphs remain separate (`◐` needs you, `●`
17
+ working, and `○` ordinary/idle). Workspace labels are presentation text inside
18
+ each lead row, not additional hierarchy nodes. The widget always retains
19
+ attention leads, caps ordinary leads, and shows omitted leads in a final
20
+ `└─ … N more · /chief` row.
21
+
22
+ ## Installation
23
+
24
+ The widget is installed only when the current session has a valid supported
25
+ herdr/Pi identity and Pi is in TUI mode.
26
+
27
+ A lead Pi session gets its exact owned subtree view.
28
+
29
+ A valid managed leaf can receive an identity-only header.
30
+
31
+ A delegation-enabled worker can receive its direct-worker counts and rows.
32
+
33
+ Unmanaged or invalid worker environments do not receive the managed widget.
34
+
35
+ ## Refresh
36
+
37
+ The widget refreshes managed herdr data plus mailbox state every two seconds.
38
+
39
+ Refresh performs a bounded herdr pane-list lookup to validate the lead
40
+ boundary. It does not add a socket transport or another worker-control protocol.
41
+
42
+ A refresh failure never mutates mailbox/control eligibility.
43
+
44
+ ## Breadcrumb
45
+
46
+ Example:
47
+
48
+ ```text
49
+ ● herd → implementer → scout
50
+ ```
51
+
52
+ The breadcrumb uses validated definition/worker ancestry.
53
+
54
+ Delegating-worker and leaf panes append their current Pi active tool names as
55
+ muted bracketed metadata after the current identity, preserving Pi's exact
56
+ order. Lead Pi sessions do not show this metadata. It is local to the current
57
+ pane, is never copied to worker rows or authoritative worker state, and is
58
+ truncated or omitted before breadcrumb identity is shortened when width is
59
+ limited.
60
+
61
+ If an ancestor cannot be proved, it is shown explicitly as `?` rather than
62
+ guessed:
63
+
64
+ ```text
65
+ ● ? → scout
66
+ ```
67
+
68
+ ## Header counts
69
+
70
+ Example:
71
+
72
+ ```text
73
+ ● herd 2 working · 1 blocked · 1 settling
74
+ ```
75
+
76
+ The header reports exact non-zero lifecycle states in the order `working`,
77
+ `blocked`, `settling`, `starting`, and `unknown`. `starting` is a
78
+ presentation-only count for assignments whose final label and mailbox claim
79
+ are known but whose authoritative worker startup has not completed. It is not
80
+ mailbox state, control authority, or Running inventory.
81
+
82
+ Before the first successful refresh, the header says `unavailable`.
83
+
84
+ After a later refresh failure, the widget retains the last valid snapshot and
85
+ marks the header `stale`.
86
+
87
+ Header refresh staleness is not worker inactivity.
88
+
89
+ ## Worker rows
90
+
91
+ Every visible worker is rendered in a stable tree. Siblings are sorted by
92
+ logical label and use Pi's `├─`, `└─`, and `│` connectors.
93
+ The row shows the agent definition and its exact logical worker label
94
+ separately. Recovery-only ancestry evidence is retained by structured status
95
+ paths but is not included in this human projection.
96
+
97
+ Rows share globally aligned columns for state, elapsed time, compact model,
98
+ thinking, context percentage, and optional inactivity. Context is shown as a
99
+ percentage without a `ctx` prefix. Responsive layouts drop the task first,
100
+ then elapsed time, then context percentage; the same column choice is used for
101
+ every row. The task is the rightmost elastic field and is kept only when it has
102
+ useful room before it is truncated.
103
+
104
+ Working rows use `● working`, blocked rows use `◐ blocked`, settling rows use
105
+ `◌ settling`, starting rows use `◌ starting`, and unknown rows use `? unknown`.
106
+ Working, settling, and starting animate; blocked and unknown rows are static. A
107
+ starting row is reconciled away
108
+ when authoritative worker evidence replaces it, and is removed on startup
109
+ failure, rollback, repeated session start, or shutdown.
110
+
111
+ `Running` inspection shows every authoritative worker row and excludes
112
+ presentation-only starting rows. A terminal result is followed by cleanup; the
113
+ widget does not retain an idle completed worker.
114
+
115
+ ## Optional metadata
116
+
117
+ Rows can include best-effort:
118
+
119
+ - task;
120
+ - elapsed time;
121
+ - compact model;
122
+ - thinking;
123
+ - context percentage;
124
+ - worker type/display metadata.
125
+
126
+ These fields are not control authority.
127
+
128
+ The renderer preserves identity/state information before truncating task text
129
+ and bounds every output line by visible Unicode width.
130
+
131
+ The current widget does **not** claim to display the full effective tool list.
132
+ That remains separate from the definition overview.
133
+
134
+ ## Worker inactivity
135
+
136
+ A `working` worker can expose an advisory inactivity marker based on durable
137
+ Pi-observed activity.
138
+
139
+ This is distinct from header `stale`, which means the widget failed to refresh
140
+ its latest snapshot.
141
+
142
+ Neither changes worker control state.
143
+
144
+ ## See also
145
+
146
+ - [Worker states](worker-states.md)
147
+ - [`/workers agents`](commands.md#workers-agents)
148
+ - [Recovery](../guides/recovery.md)