forge-planner 0.1.0a1__py3-none-any.whl

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,13 @@
1
+ """forge_planner — the reference planner for Forge.
2
+
3
+ Implements the Planner Protocol (SPEC §9): goal in, proposal out. This
4
+ package is the architectural proof behind the SDK boundary: it is a
5
+ separate, installable distribution that consumes ONLY the public
6
+ ``forge.*`` surface (ForgeClient, validate_proposal, slugify,
7
+ PLANNER_OPS) — no kernel internals.
8
+ """
9
+
10
+ from .planner import ALLOWED_OPS, ProposalError, ReferencePlanner, validate_proposal
11
+
12
+ __all__ = ["ReferencePlanner", "ProposalError", "validate_proposal",
13
+ "ALLOWED_OPS"]
forge_planner/cli.py ADDED
@@ -0,0 +1,41 @@
1
+ """CLI registration for forge-planner (the `plan` command).
2
+
3
+ The forge CLI discovers commands through the ``forge.commands``
4
+ entry-point group. This module is that entry point: it adds the `plan`
5
+ subparser (owning its argument shape) and returns the command handler.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import json
12
+
13
+ from forge import ForgeClient
14
+
15
+ from .planner import ReferencePlanner
16
+
17
+
18
+ def register(subparsers: argparse._SubParsersAction) -> dict:
19
+ """Entry point for ``forge.commands``: add `plan` and return its handler."""
20
+ c = subparsers.add_parser(
21
+ "plan", help="reference planner: GOAL -> proposal (SPEC §9); commit is opt-in")
22
+ c.add_argument("goal")
23
+ c.add_argument("--priority", choices=["low", "medium", "high"], default="medium")
24
+ c.add_argument("--confidence", type=float, default=0.9)
25
+ c.add_argument("--commit", action="store_true",
26
+ help="commit the proposal through the kernel (atomic: whole or nothing)")
27
+ return {"plan": cmd_plan}
28
+
29
+
30
+ def cmd_plan(args, k=None) -> int:
31
+ client = ForgeClient(args.dir) # the CLI speaks the SDK too
32
+ proposal = ReferencePlanner(client).plan(
33
+ args.goal, priority=args.priority, confidence=args.confidence)
34
+ if args.commit:
35
+ result = client.propose(proposal) # envelope + kernel verdict
36
+ print(f"committed {result['committed']} events from {result['proposal_id']} "
37
+ f"(confidence {result['confidence']}) -> project now has "
38
+ f"{result['tasks']} tasks")
39
+ else:
40
+ print(json.dumps(proposal, ensure_ascii=False, indent=2))
41
+ return 0
@@ -0,0 +1,138 @@
1
+ """ReferencePlanner — M2B, the first untrusted client of Forge.
2
+
3
+ Implements the Planner Protocol (SPEC §9): goal in, proposal out.
4
+ The planner never owns the graph. It consumes ONLY the public SDK
5
+ (`forge.ForgeClient`, `forge.validate_proposal`, `forge.slugify`) —
6
+ no kernel internals. That is the architectural proof: if a plugin can
7
+ operate entirely through the public interfaces, the kernel boundary
8
+ is real.
9
+
10
+ {
11
+ "proposal_id": "prop_...",
12
+ "reason": "...",
13
+ "confidence": 0.9,
14
+ "events": [ ... ] # no seq — the kernel stamps it (§9.4)
15
+ }
16
+
17
+ This is a REFERENCE planner: deterministic, stdlib-only, no AI. It
18
+ exists to prove the boundary and exercise the commit path. Any LLM
19
+ planner is a drop-in replacement behind the same protocol — same
20
+ shape, same commit path, same rules.
21
+
22
+ Planner constraints enforced here (§9.6):
23
+ - only task_created / task_expanded / task_updated / dependency_added
24
+ - no event carries a seq (the kernel assigns sequence numbers)
25
+ - every referenced task id is created by this proposal (predicted
26
+ with the kernel's own slugify/next_id derivation, so dependency
27
+ events land on the ids the kernel will actually generate)
28
+ """
29
+ from __future__ import annotations
30
+
31
+ import uuid
32
+
33
+ from forge import ForgeClient, PLANNER_OPS, ProposalError, slugify, validate_proposal
34
+
35
+ # Backward-compatible alias (pre-M2D name): the ops allowlist is the SDK's
36
+ # PLANNER_OPS, one definition, no duplication.
37
+ ALLOWED_OPS = PLANNER_OPS
38
+
39
+ # Re-exported for compatibility: the protocol now lives in the SDK
40
+ # (forge.validate_proposal) — one definition, no duplication.
41
+ __all__ = ["ReferencePlanner", "ProposalError", "validate_proposal",
42
+ "ALLOWED_OPS"]
43
+
44
+ _DEFAULT_MILESTONES = ("Foundation", "Core", "Acceptance")
45
+
46
+
47
+ class ReferencePlanner:
48
+ """Deterministic, stdlib-only planner. Goal in, proposal out.
49
+
50
+ Takes an optional ForgeClient for the commit path (client.propose).
51
+ Planning itself needs no client — the proposal is a pure function
52
+ of the goal — which is why plan() works without one. commit() is
53
+ the only method that touches Forge, and it goes through the SDK.
54
+
55
+ Decomposes a goal into a root task with three milestone children
56
+ (Foundation -> Core -> Acceptance) joined by a dependency chain.
57
+ The decomposition is a skeleton: it is structurally correct by
58
+ construction, and domain intelligence belongs to a smarter planner
59
+ behind the same protocol.
60
+ """
61
+
62
+ def __init__(self, client: ForgeClient | None = None) -> None:
63
+ self.client = client
64
+
65
+ def plan(self, goal: str, children=None, priority: str = "medium",
66
+ confidence: float = 0.9, reason: str | None = None) -> dict:
67
+ goal = (goal or "").strip()
68
+ if not goal:
69
+ raise ProposalError("goal must be a non-empty string")
70
+ if priority not in ("low", "medium", "high"):
71
+ raise ProposalError(f"priority must be low/medium/high, got {priority!r}")
72
+ if isinstance(confidence, bool) or not isinstance(confidence, (int, float)) \
73
+ or not 0.0 <= confidence <= 1.0:
74
+ raise ProposalError("confidence must be a number in [0, 1]")
75
+
76
+ root_id = slugify(goal)
77
+ if children is None:
78
+ children = [
79
+ {"title": f"{goal} — {m}", "priority": priority}
80
+ for m in _DEFAULT_MILESTONES
81
+ ]
82
+
83
+ # Predict the ids the kernel will derive (model.py expand:
84
+ # next_id over existing tasks + reserved, in order).
85
+ existing = {root_id}
86
+ child_ids: list[str] = []
87
+ for c in children:
88
+ base = slugify(c["title"])
89
+ cand, n = base, 2
90
+ while cand in existing:
91
+ cand = f"{base}-{n}"
92
+ n += 1
93
+ existing.add(cand)
94
+ child_ids.append(cand)
95
+
96
+ events = [{
97
+ "op": "task_created", "id": root_id, "title": goal,
98
+ "description": "", "acceptance": [], "files": [], "notes": [],
99
+ "priority": priority,
100
+ }]
101
+ events.append({
102
+ "op": "task_expanded", "task": root_id,
103
+ "children": [
104
+ {
105
+ "id": cid,
106
+ "title": c["title"],
107
+ "description": c.get("description", ""),
108
+ "acceptance": list(c.get("acceptance", [])),
109
+ "files": list(c.get("files", [])),
110
+ "priority": c.get("priority", priority),
111
+ }
112
+ for cid, c in zip(child_ids, children)
113
+ ],
114
+ })
115
+ for i in range(1, len(child_ids)):
116
+ events.append({
117
+ "op": "dependency_added",
118
+ "task": child_ids[i],
119
+ "depends_on": child_ids[i - 1],
120
+ })
121
+
122
+ proposal = {
123
+ "proposal_id": f"prop_{root_id[:20]}_{uuid.uuid4().hex[:8]}",
124
+ "reason": reason or (
125
+ f"Decompose '{goal}' into {', '.join(_DEFAULT_MILESTONES).lower()} "
126
+ f"milestones with a dependency chain"),
127
+ "confidence": confidence,
128
+ "events": events,
129
+ }
130
+ validate_proposal(proposal) # self-check before returning
131
+ return proposal
132
+
133
+ def commit(self, proposal: dict) -> dict:
134
+ """Commit through the SDK — atomic, whole or nothing. The
135
+ planner never touches the kernel directly; ForgeClient does."""
136
+ if self.client is None:
137
+ raise ProposalError("no client: construct ReferencePlanner(client) to commit")
138
+ return self.client.propose(proposal)
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: forge-planner
3
+ Version: 0.1.0a1
4
+ Summary: Forge reference planner: goal in, proposal out (SPEC §9). The first untrusted SDK client, published as its own package.
5
+ Author-email: Sanjay Davis <psanjuknl@gmail.com>
6
+ License-Expression: MIT
7
+ Keywords: forge,planner,sdk,autonomous-software
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: forge-foundation
16
+ Dynamic: license-file
17
+
18
+ # forge-planner
19
+
20
+ The reference planner for [Forge](https://github.com/SanjayDavis/Forge) —
21
+ a deterministic, stdlib-only client of the public SDK. Goal in, proposal
22
+ out (SPEC §9); the kernel commits or rejects the proposal whole.
23
+
24
+ This package is the architectural proof behind the SDK boundary: it is a
25
+ *separate, installable package* that consumes only the public
26
+ `forge.*` surface — no kernel internals.
27
+
28
+ ## Install
29
+
30
+ ```sh
31
+ pip install forge-foundation forge-planner
32
+ ```
33
+
34
+ ## Use
35
+
36
+ ```sh
37
+ forge init demo
38
+ forge plan "Build a calculator" # print the proposal (no commit)
39
+ forge plan "Build a calculator" --commit # commit atomically through the kernel
40
+ ```
41
+
42
+ `forge plan` is registered as a `forge.commands` entry point: the CLI
43
+ discovers the command from this package at runtime.
44
+
45
+ ## The planner
46
+
47
+ - Deterministic: `ReferencePlanner.plan(goal)` is a pure function of the goal.
48
+ - Stdlib-only: no AI, no network.
49
+ - Constrained (SPEC §9.6): only task ops, no seq on events, every
50
+ referenced id predicted with the kernel's own slugify/next_id derivation.
51
+ - Any LLM planner is a drop-in replacement behind the same protocol.
52
+
53
+ ## License
54
+
55
+ MIT
@@ -0,0 +1,9 @@
1
+ forge_planner/__init__.py,sha256=GODMEIrlLRw8f8bZZiEFbTIWHm4Kzy9gaIIXrOdr_B8,546
2
+ forge_planner/cli.py,sha256=ruPl4Rw11ombD_N-PpIbyJPGhoRYIrpndLHUUxY-1d8,1619
3
+ forge_planner/planner.py,sha256=heerNZ2vu8mDxuuEZgP1mWFrRUpjZ_BY_uMXoeDjLHw,5597
4
+ forge_planner-0.1.0a1.dist-info/licenses/LICENSE,sha256=qMmKrp_9KZ8MpBesmaUrJOSM3XTw0mWLaVjJaEbRNPU,1069
5
+ forge_planner-0.1.0a1.dist-info/METADATA,sha256=UGZULodq2i6bIlNmdA9BfYI_ss0bWFd9Ww_AkUWYZpY,1836
6
+ forge_planner-0.1.0a1.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
7
+ forge_planner-0.1.0a1.dist-info/entry_points.txt,sha256=gD2lgWXB17dXG5atMq7QMeeGNSL80_av8o9uUeXx9zI,51
8
+ forge_planner-0.1.0a1.dist-info/top_level.txt,sha256=JynfTB2gtQXyqAhvdmqyzNx0IEOR5RJTCXnbKNYX8RI,14
9
+ forge_planner-0.1.0a1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [forge.commands]
2
+ plan = forge_planner.cli:register
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sanjay Davis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ forge_planner