@evref-bl/pharo-mcp 2.3.0 → 3.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.
- package/README.md +20 -5
- package/package.json +1 -1
- package/templates/pharo-references/pharo-coding.md +105 -0
- package/templates/pharo-references/tool-reference.md +78 -158
- package/templates/pharo-skills/pharo-ci-repro/references/pharo-smalltalkci.md +4 -28
- package/templates/pharo-skills/pharo-code-profiling/SKILL.md +19 -38
- package/templates/pharo-skills/pharo-image-sync/SKILL.md +47 -0
- package/templates/pharo-skills/pharo-image-sync/agents/openai.yaml +4 -0
- package/templates/pharo-skills/pharo-mcp-recovery/SKILL.md +1 -1
- package/templates/pharo-skills/pharo-project-load/SKILL.md +2 -1
- package/templates/pharo.AGENTS.md +16 -12
- package/templates/pharo-references/debugging.md +0 -70
- package/templates/pharo-references/getting-started.md +0 -151
- package/templates/pharo-references/pharo-coding-rules.md +0 -147
- package/templates/pharo-references/pharo-coding-style.md +0 -141
- package/templates/pharo-references/safety-and-ecosystem.md +0 -322
- package/templates/pharo-references/source-vs-live-image.md +0 -75
- package/templates/pharo-references/troubleshooting.md +0 -145
- package/templates/pharo-references/using-pharo-mcp.md +0 -172
- package/templates/pharo-skills/pharo-image-git-handoff/SKILL.md +0 -40
- package/templates/pharo-skills/pharo-image-git-handoff/agents/openai.yaml +0 -4
- package/templates/pharo-skills/pharo-version-compat/SKILL.md +0 -54
- package/templates/pharo-skills/pharo-version-compat/agents/openai.yaml +0 -4
|
@@ -37,7 +37,8 @@ For local Tonel, use an absolute `tonel:///.../src` URL.
|
|
|
37
37
|
|
|
38
38
|
- Baseline/package not found: verify branch and source directory.
|
|
39
39
|
- Missing global/class/selector: compare the project API surface with the
|
|
40
|
-
target Pharo version
|
|
40
|
+
target Pharo version. Version-specific code belongs in a package the
|
|
41
|
+
baseline loads only where it applies.
|
|
41
42
|
- Metacello conflict: reproduce the project's documented or CI conflict policy.
|
|
42
43
|
- Native or CI-only failure: reproduce once, then use `pharo-ci-repro`.
|
|
43
44
|
|
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
# Pharo MCP Agent Guide
|
|
2
2
|
|
|
3
3
|
Use the configured `pharo` MCP server whenever a task depends on the running
|
|
4
|
-
image. Preserve unrelated changes and
|
|
5
|
-
|
|
4
|
+
image. Preserve unrelated changes, and say which live check you could not run
|
|
5
|
+
rather than letting source stand in for it.
|
|
6
6
|
|
|
7
7
|
## Read First
|
|
8
8
|
|
|
9
9
|
- Inspect the tools and schemas exposed by the current client; do not rely on
|
|
10
|
-
remembered names.
|
|
10
|
+
remembered names. `tool_search` finds what is not advertised, and `tool_get`
|
|
11
|
+
answers one tool's schema.
|
|
11
12
|
- Prefer the least-mutating dedicated tool. Use `image_evaluate` only when no
|
|
12
13
|
dedicated tool fits.
|
|
13
|
-
- Treat image, Tonel, Iceberg, and Git state as separate.
|
|
14
|
+
- Treat image, Tonel, Iceberg, and Git state as separate. None of them proves
|
|
15
|
+
anything about the others.
|
|
16
|
+
- The image is one workspace. It has no branches and no worktrees, so two
|
|
17
|
+
agents working in it at once share every edit, and one export writes both
|
|
18
|
+
their changes into one diff. One writer at a time.
|
|
14
19
|
- Tools change the running image but never save it; use a safe image boundary.
|
|
15
20
|
|
|
16
21
|
## Context Loading
|
|
17
22
|
|
|
18
23
|
- Before Pharo source changes: read the project's Pharo coding and testing
|
|
19
24
|
guidance. If none exists, use the local
|
|
20
|
-
[coding
|
|
21
|
-
|
|
25
|
+
[Pharo coding](pharo-references/pharo-coding.md) reference.
|
|
26
|
+
- Before reading an answer closely, rewriting methods, or acting on a warning a
|
|
27
|
+
call came back with: read
|
|
28
|
+
[tool reference](pharo-references/tool-reference.md).
|
|
22
29
|
- Before loading a project: use `skills/pharo-project-load/SKILL.md`.
|
|
23
|
-
- Before
|
|
24
|
-
-
|
|
25
|
-
`skills/pharo-image-git-handoff/SKILL.md`.
|
|
30
|
+
- Before moving code between the image and its files: use
|
|
31
|
+
`skills/pharo-image-sync/SKILL.md`.
|
|
26
32
|
- Before reproducing smalltalkCI or GitHub failures: use
|
|
27
33
|
`skills/pharo-ci-repro/SKILL.md`.
|
|
28
34
|
- Before profiling or optimizing Pharo code: use
|
|
29
35
|
`skills/pharo-code-profiling/SKILL.md`.
|
|
30
36
|
- Before recovering a stopped standalone image: use
|
|
31
37
|
`skills/pharo-mcp-recovery/SKILL.md`.
|
|
32
|
-
- Before debugger sessions or repairs: read the local
|
|
33
|
-
[debugging guide](pharo-references/debugging.md).
|
|
34
38
|
|
|
35
39
|
## Workflow
|
|
36
40
|
|
|
@@ -38,7 +42,7 @@ guessing from source.
|
|
|
38
42
|
2. Preview or verify identity before risky mutation.
|
|
39
43
|
3. Make the narrowest image-side change.
|
|
40
44
|
4. Run focused SUnit tests and inspect the result.
|
|
41
|
-
5. Use the
|
|
45
|
+
5. Use the image-sync skill before exporting or committing Tonel changes.
|
|
42
46
|
|
|
43
47
|
For repository work, verify repository identity before mutation and inspect the
|
|
44
48
|
image-side diff before export or commit.
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Debugging Tools
|
|
2
|
-
|
|
3
|
-
Applies when using MCP-Pharo to watch values while code runs, or to see what
|
|
4
|
-
debuggers a person has open.
|
|
5
|
-
|
|
6
|
-
## Goal
|
|
7
|
-
|
|
8
|
-
See what running code is doing without guessing from source and without driving
|
|
9
|
-
the Morphic debugger by hand.
|
|
10
|
-
|
|
11
|
-
Debugger tools are discoverable, not part of the default static surface.
|
|
12
|
-
|
|
13
|
-
## Discovery Flow
|
|
14
|
-
|
|
15
|
-
1. Use `tool_search` with a query such as `watch` or `debugger`.
|
|
16
|
-
2. Use `tool_get` for the exact schema of the tool you plan to call.
|
|
17
|
-
3. If the current client exposes a catalog bridge, use `tool_call` to invoke
|
|
18
|
-
the selected tool by name. Otherwise use the callable form exposed by the
|
|
19
|
-
current client.
|
|
20
|
-
|
|
21
|
-
## Tool Map
|
|
22
|
-
|
|
23
|
-
| Tool | Use |
|
|
24
|
-
| --- | --- |
|
|
25
|
-
| `debug_watch` | Record what variables hold while an expression runs, without stopping it. |
|
|
26
|
-
| `debug_search` | Answer the debuggers open in the image, read-only. |
|
|
27
|
-
|
|
28
|
-
Neither tool keeps anything. No session is started, attached or registered, so
|
|
29
|
-
there is no reference to carry between calls and nothing to clean up.
|
|
30
|
-
|
|
31
|
-
## Watching Values
|
|
32
|
-
|
|
33
|
-
`debug_watch` is print debugging without editing the method. Name the methods to
|
|
34
|
-
probe, the variables to record, and the expression to run. Every assignment to a
|
|
35
|
-
named variable is recorded as it happens, the expression runs to completion, and
|
|
36
|
-
the probes are removed before the call answers.
|
|
37
|
-
|
|
38
|
-
Name no variable and each method's arguments are recorded as it is entered.
|
|
39
|
-
Both `method` and `variable` take one value or a list, and a probe goes on every
|
|
40
|
-
pair that exists, so a variable a method never assigns simply has no series there.
|
|
41
|
-
|
|
42
|
-
Reach for it whenever the question is what a value became, rather than where to
|
|
43
|
-
intervene.
|
|
44
|
-
|
|
45
|
-
## Seeing A Person's Debuggers
|
|
46
|
-
|
|
47
|
-
`debug_search` answers the debuggers open in the image: each one's name, the
|
|
48
|
-
exception it stopped on, and the frames nearest the stop with what those frames
|
|
49
|
-
hold. Pass a `query` to keep only the debuggers whose name or exception matches.
|
|
50
|
-
|
|
51
|
-
It is a query and nothing else. It attaches to nothing, changes nothing, and
|
|
52
|
-
remembers nothing, so the picture it gives is whatever is open at that moment.
|
|
53
|
-
Ask again for a fresh one.
|
|
54
|
-
|
|
55
|
-
Act on what it shows with the ordinary tools: read the method with `method_get`,
|
|
56
|
-
change it with `method_compile`, run something with `image_evaluate`. Stepping,
|
|
57
|
-
resuming and repairing from inside a frame belong to the person at the debugger,
|
|
58
|
-
not to the agent.
|
|
59
|
-
|
|
60
|
-
## To Debug Your Own Code
|
|
61
|
-
|
|
62
|
-
Do not open a debugger for it. Call the tool that runs the code and read the
|
|
63
|
-
failure it reports: it names the frames nearest the error and the values they
|
|
64
|
-
held. When that is not enough, `debug_watch` shows how a value got there.
|
|
65
|
-
|
|
66
|
-
## Do Not
|
|
67
|
-
|
|
68
|
-
- Do not drive debugger windows or mutate contexts through general
|
|
69
|
-
`image_evaluate` code.
|
|
70
|
-
- Do not resume, step or terminate a person's debugger. It is theirs.
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# Getting Started
|
|
2
|
-
|
|
3
|
-
This is the canonical guide for loading MCP, starting its HTTP endpoint, and
|
|
4
|
-
connecting a client.
|
|
5
|
-
|
|
6
|
-
## Requirements
|
|
7
|
-
|
|
8
|
-
- Pharo 12, 13, 14, or 15
|
|
9
|
-
- An MCP client that supports Streamable HTTP directly or through a local bridge
|
|
10
|
-
- Network access from the client to the image host
|
|
11
|
-
|
|
12
|
-
For local use, keep the image and client on the same machine and use
|
|
13
|
-
`127.0.0.1`.
|
|
14
|
-
|
|
15
|
-
## Load MCP
|
|
16
|
-
|
|
17
|
-
Evaluate in a supported image:
|
|
18
|
-
|
|
19
|
-
```smalltalk
|
|
20
|
-
Metacello new
|
|
21
|
-
baseline: 'MCP';
|
|
22
|
-
repository: 'github://Evref-BL/MCP:main/src';
|
|
23
|
-
load.
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
As a project dependency:
|
|
27
|
-
|
|
28
|
-
```smalltalk
|
|
29
|
-
spec
|
|
30
|
-
baseline: 'MCP'
|
|
31
|
-
with: [ spec repository: 'github://Evref-BL/MCP:main/src' ].
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Load Groups
|
|
35
|
-
|
|
36
|
-
The default load includes the server, optional UI, and their tests.
|
|
37
|
-
|
|
38
|
-
| Group | Contents |
|
|
39
|
-
| --- | --- |
|
|
40
|
-
| `default` | `Core`, `UI`, `Tests`, and `UI Tests` |
|
|
41
|
-
| `Core` | The `MCP` server package |
|
|
42
|
-
| `UI` | `MCP-UI` and its required core package |
|
|
43
|
-
| `Tests` | Core server tests and test resources |
|
|
44
|
-
| `UI Tests` | UI tests and their required test dependencies |
|
|
45
|
-
| `OpenTelemetry` | Optional OpenTelemetry backend |
|
|
46
|
-
| `all` | Every package, including the optional OpenTelemetry backend |
|
|
47
|
-
|
|
48
|
-
For a headless image, load only the core server:
|
|
49
|
-
|
|
50
|
-
```smalltalk
|
|
51
|
-
Metacello new
|
|
52
|
-
baseline: 'MCP';
|
|
53
|
-
repository: 'github://Evref-BL/MCP:main/src';
|
|
54
|
-
load: 'Core'.
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Dependencies can select the same group with `loads: #( 'Core' )`.
|
|
58
|
-
|
|
59
|
-
## Start And Stop
|
|
60
|
-
|
|
61
|
-
```smalltalk
|
|
62
|
-
mcp := MCP startOnPort: 4000.
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
That answers the server already on 4000 when the image has one, rather than
|
|
66
|
-
failing on the port it holds. Build one by hand when it needs configuring
|
|
67
|
-
before it starts:
|
|
68
|
-
|
|
69
|
-
```smalltalk
|
|
70
|
-
mcp := MCP new.
|
|
71
|
-
mcp port: 4000.
|
|
72
|
-
mcp start.
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Tool calls return canonical LLM-facing `content` by default. If a client or
|
|
76
|
-
integration needs programmatic payloads, configure the response fields before
|
|
77
|
-
starting:
|
|
78
|
-
|
|
79
|
-
```smalltalk
|
|
80
|
-
mcp useStructuredContentOnlyToolResponses.
|
|
81
|
-
mcp useContentAndStructuredContentToolResponses.
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Inspect or control the server with:
|
|
85
|
-
|
|
86
|
-
```smalltalk
|
|
87
|
-
mcp localUrlString.
|
|
88
|
-
mcp isRunning.
|
|
89
|
-
mcp isListening.
|
|
90
|
-
mcp restart.
|
|
91
|
-
mcp stop.
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
The server lives in the image and stops when the image exits.
|
|
95
|
-
|
|
96
|
-
## Connect A Client
|
|
97
|
-
|
|
98
|
-
The endpoint above is:
|
|
99
|
-
|
|
100
|
-
```text
|
|
101
|
-
http://127.0.0.1:4000
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Client configuration formats differ. Configure a Streamable HTTP MCP server
|
|
105
|
-
using the client documentation rather than copying another client's JSON.
|
|
106
|
-
Loopback addresses work only when the client connects from the local machine;
|
|
107
|
-
cloud-brokered connectors cannot reach `127.0.0.1`.
|
|
108
|
-
|
|
109
|
-
Install the supplied guide, local references, workflow skills, and direct MCP
|
|
110
|
-
configuration into the current agent project:
|
|
111
|
-
|
|
112
|
-
```sh
|
|
113
|
-
npx @evref-bl/pharo-mcp install --host codex
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Use `--host claude` or `--host opencode` for those hosts. The direct MCP
|
|
117
|
-
configuration expects port `4000`; update it when the image uses another port.
|
|
118
|
-
|
|
119
|
-
## First Calls
|
|
120
|
-
|
|
121
|
-
Start with catalog discovery:
|
|
122
|
-
|
|
123
|
-
```text
|
|
124
|
-
tools/list
|
|
125
|
-
tool_search
|
|
126
|
-
tool_get
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Then inspect the image with focused read-only tools such as:
|
|
130
|
-
|
|
131
|
-
```text
|
|
132
|
-
class_search
|
|
133
|
-
class_get
|
|
134
|
-
method_search
|
|
135
|
-
method_source_search
|
|
136
|
-
method_reference_search
|
|
137
|
-
method_get
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
`package_search` and the specialized tools are found with `tool_search`.
|
|
141
|
-
|
|
142
|
-
Before mutation, inspect the target and use a copied or disposable image.
|
|
143
|
-
Prefer dedicated tools such as `class_create`, `method_compile`, refactoring
|
|
144
|
-
tools, and `test_run` over `image_evaluate`.
|
|
145
|
-
|
|
146
|
-
Continue with:
|
|
147
|
-
|
|
148
|
-
- [Using MCP from an agent](using-pharo-mcp.md)
|
|
149
|
-
- [Tool reference](tool-reference.md)
|
|
150
|
-
- [Safety and ecosystem integration](safety-and-ecosystem.md)
|
|
151
|
-
- [Troubleshooting](troubleshooting.md)
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# Pharo Coding Rules For MCP Users
|
|
2
|
-
|
|
3
|
-
Applies when using MCP to inspect, write, review, or refactor Pharo source in
|
|
4
|
-
any project.
|
|
5
|
-
|
|
6
|
-
This file covers object-design and correctness-oriented rules. For
|
|
7
|
-
expression-level readability heuristics, also read
|
|
8
|
-
[Pharo coding style](pharo-coding-style.md).
|
|
9
|
-
|
|
10
|
-
## First Principle
|
|
11
|
-
|
|
12
|
-
Pharo code should communicate through messages and protocols. Prefer normal
|
|
13
|
-
dispatch over representation checks, class checks, reflective lookup, or
|
|
14
|
-
dynamic selector tricks.
|
|
15
|
-
|
|
16
|
-
## Dispatch Over Inspection
|
|
17
|
-
|
|
18
|
-
Do:
|
|
19
|
-
|
|
20
|
-
- send a domain message to the receiver;
|
|
21
|
-
- add or refine a protocol on the object that owns the behavior;
|
|
22
|
-
- use polymorphic collaborators, strategy objects, double dispatch, or visitors
|
|
23
|
-
when behavior varies by object role.
|
|
24
|
-
|
|
25
|
-
Avoid in application behavior:
|
|
26
|
-
|
|
27
|
-
- `class = ...`;
|
|
28
|
-
- `isKindOf:` and `isMemberOf:`;
|
|
29
|
-
- `respondsTo:` as control flow;
|
|
30
|
-
- `perform:` as a disguised switch;
|
|
31
|
-
- method dictionary or instance-variable reflection.
|
|
32
|
-
|
|
33
|
-
Reflection is acceptable for tools, proxies, compatibility shims, and explicit
|
|
34
|
-
framework boundaries. Keep reflective behavior isolated and named as tooling
|
|
35
|
-
or boundary behavior; do not spread it through ordinary domain logic.
|
|
36
|
-
|
|
37
|
-
## Tell, Do Not Ask
|
|
38
|
-
|
|
39
|
-
Do not pull state out of an object, compute externally, then push state back
|
|
40
|
-
when the object can own the behavior.
|
|
41
|
-
|
|
42
|
-
Prefer:
|
|
43
|
-
|
|
44
|
-
- `aCommand executeOn: aModel`;
|
|
45
|
-
- `aDocument writeOn: aStream`;
|
|
46
|
-
- `aPolicy accepts: anObject`.
|
|
47
|
-
|
|
48
|
-
over clients branching on concrete classes or internal fields.
|
|
49
|
-
|
|
50
|
-
## Object APIs, Not Data Bags
|
|
51
|
-
|
|
52
|
-
- Keep domain objects behavior-rich instead of using them only as data bags.
|
|
53
|
-
- Avoid dictionaries or arrays as internal domain models unless the data is
|
|
54
|
-
genuinely unstructured external input.
|
|
55
|
-
- If several clients repeat the same extraction and calculation, move the
|
|
56
|
-
behavior to the object with the knowledge.
|
|
57
|
-
- Avoid long message chains through internals; add a meaningful domain method.
|
|
58
|
-
|
|
59
|
-
## Small Methods And Hooks
|
|
60
|
-
|
|
61
|
-
- Extract meaningful steps into small named methods.
|
|
62
|
-
- Use self-send hooks when subclass or compatibility variation is plausible.
|
|
63
|
-
- Keep block bodies short; move domain logic from blocks into methods.
|
|
64
|
-
- Do not add wrappers that only rename obvious library calls unless the wrapper
|
|
65
|
-
captures a domain concept or extension hook.
|
|
66
|
-
- Trust collaborators first. Prefer direct sends to the documented protocol of
|
|
67
|
-
the object you were given; add adapters or project-specific extensions only
|
|
68
|
-
when the code truly accepts multiple concrete framework shapes or compatibility
|
|
69
|
-
differences.
|
|
70
|
-
- Be especially conservative with extensions on broad system classes such as
|
|
71
|
-
`Object`, `Behavior`, `String`, or `Exception`. They should model a real
|
|
72
|
-
boundary protocol, not hypothetical defense against wrong callers.
|
|
73
|
-
|
|
74
|
-
## Nil And Error Handling
|
|
75
|
-
|
|
76
|
-
- Return empty collections for "no elements".
|
|
77
|
-
- Use a null object when "do nothing" is valid behavior.
|
|
78
|
-
- Signal or return structured domain errors for exceptional cases.
|
|
79
|
-
- Do not use `nil` as a normal status code.
|
|
80
|
-
- Do not swallow broad `Error` silently.
|
|
81
|
-
- Catch the most specific exception class that matches the recovery policy.
|
|
82
|
-
- Use `ensure:` for cleanup.
|
|
83
|
-
|
|
84
|
-
## Initialization
|
|
85
|
-
|
|
86
|
-
- Instance-side `initialize` starts with `super initialize`.
|
|
87
|
-
- Initialize sensible defaults.
|
|
88
|
-
- Methods without an explicit return answer `self`. Do not add a trailing
|
|
89
|
-
`^ self` to initializers or mutators only to return the receiver; keep
|
|
90
|
-
explicit returns for early exits or non-self results.
|
|
91
|
-
- Do not redefine class-side `new` just to call `initialize`.
|
|
92
|
-
- Use class-side creation messages such as `on:`, `with:`, or domain-specific
|
|
93
|
-
constructors when required data exists.
|
|
94
|
-
- Use `basicNew` only when deliberately bypassing initialization.
|
|
95
|
-
|
|
96
|
-
## Names And Selectors
|
|
97
|
-
|
|
98
|
-
- Use domain vocabulary.
|
|
99
|
-
- Getter selector is the variable name; setter selector is `name:`.
|
|
100
|
-
- Do not use `getName` or `setName:`.
|
|
101
|
-
- Predicates should read as predicates: `isReady`, `hasErrors`,
|
|
102
|
-
`canHandle:`.
|
|
103
|
-
- Action selectors should use verbs: `parseRequest:`, `addTool:`,
|
|
104
|
-
`writeResponseOn:`.
|
|
105
|
-
- Conversion selectors should start with `as`.
|
|
106
|
-
|
|
107
|
-
## Collections And Streams
|
|
108
|
-
|
|
109
|
-
- Prefer collection protocol such as `collect:`, `select:`, `reject:`,
|
|
110
|
-
`detect:ifNone:`, `inject:into:`, `anySatisfy:`, and `allSatisfy:`.
|
|
111
|
-
- Do not mutate a collection while iterating it unless iterating a copy is
|
|
112
|
-
intentional.
|
|
113
|
-
- Do not rely on `add:` answering the collection; use a variable or cascade
|
|
114
|
-
with `yourself`.
|
|
115
|
-
- Override `hash` when overriding `=`.
|
|
116
|
-
- Use `String streamContents:` or writer streams for string construction.
|
|
117
|
-
- Do not concatenate strings with `,` in loops or recursive code.
|
|
118
|
-
|
|
119
|
-
## Tests
|
|
120
|
-
|
|
121
|
-
- Add or update SUnit tests for behavior changes.
|
|
122
|
-
- Use `assert:equals:` for comparisons when possible.
|
|
123
|
-
- Use `deny:` for negative assertions.
|
|
124
|
-
- Use `should:raise:` and `shouldnt:raise:` with blocks for exception
|
|
125
|
-
behavior.
|
|
126
|
-
- Prefer focused tests around the public protocol.
|
|
127
|
-
- Use memory filesystems, fakes, or injected collaborators for unit tests when
|
|
128
|
-
possible.
|
|
129
|
-
- Keep live-image and external-state tests separate from source-only checks.
|
|
130
|
-
|
|
131
|
-
## Review Checklist
|
|
132
|
-
|
|
133
|
-
Before finishing a Pharo source change, scan for:
|
|
134
|
-
|
|
135
|
-
- class checks or reflection used as ordinary dispatch;
|
|
136
|
-
- `perform:` selector registries;
|
|
137
|
-
- normal control flow through `nil`;
|
|
138
|
-
- repeated client-side extraction from an object;
|
|
139
|
-
- long methods or blocks hiding named domain steps;
|
|
140
|
-
- project-specific extensions on broad system classes that only defend
|
|
141
|
-
hypothetical collaborators;
|
|
142
|
-
- missing `super initialize`;
|
|
143
|
-
- stream/file cleanup without `ensure:`;
|
|
144
|
-
- string concatenation in loops;
|
|
145
|
-
- overridden `=` without `hash`;
|
|
146
|
-
- broad exception handlers that hide failures;
|
|
147
|
-
- missing tests for changed public behavior.
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
# Pharo Coding Style
|
|
2
|
-
|
|
3
|
-
Applies when writing or reviewing the shape of Pharo source code after loading
|
|
4
|
-
[Pharo coding rules](pharo-coding-rules.md).
|
|
5
|
-
|
|
6
|
-
## Goal
|
|
7
|
-
|
|
8
|
-
Keep Pharo code readable, scannable, and idiomatic. These are readability
|
|
9
|
-
heuristics, not mechanical laws. Prefer the shape that makes dependencies,
|
|
10
|
-
main operations, and exceptional paths easiest to understand.
|
|
11
|
-
|
|
12
|
-
## Main Send
|
|
13
|
-
|
|
14
|
-
- Make the main send easy to see. When both branches of a conditional perform
|
|
15
|
-
the same operation, lift the branch-invariant send out of the branches and
|
|
16
|
-
use the conditional only for the receiver or argument that varies.
|
|
17
|
-
- This applies to return expressions, assigned values, message arguments, and
|
|
18
|
-
nested expressions.
|
|
19
|
-
- Do not over-compress multi-step domain logic into one expression.
|
|
20
|
-
|
|
21
|
-
Prefer:
|
|
22
|
-
|
|
23
|
-
```smalltalk
|
|
24
|
-
result := self transform: (condition ifTrue: [ selectedValue ])
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
over duplicating the same `transform:` send inside both conditional branches.
|
|
28
|
-
|
|
29
|
-
## Guards
|
|
30
|
-
|
|
31
|
-
- Guard before dependent work. If `nil`, invalid bounds, failed lookup, or
|
|
32
|
-
missing capability exits early or returns a fallback, check it before sends,
|
|
33
|
-
computations, or mutations that assume the value is present.
|
|
34
|
-
- Keep the normal path visible. Use early returns for local exceptional or
|
|
35
|
-
fallback cases when they keep the main path low-indentation.
|
|
36
|
-
- Do not mechanically move every condition to the top. Choose the order that
|
|
37
|
-
makes dependencies and intent clearest.
|
|
38
|
-
- Prefer "win fast" when the successful case is tiny, obvious, and safe to
|
|
39
|
-
attempt before fallback work.
|
|
40
|
-
|
|
41
|
-
## Temporaries
|
|
42
|
-
|
|
43
|
-
- Prefer short supporting expressions for simple receiver or argument
|
|
44
|
-
computation.
|
|
45
|
-
- Use a temporary when the value has domain meaning, is reused, names an
|
|
46
|
-
important step, or helps debugging and review.
|
|
47
|
-
- Keep temporaries near their use.
|
|
48
|
-
|
|
49
|
-
## Collections
|
|
50
|
-
|
|
51
|
-
Common collection families, as a protocol reminder rather than a reason to
|
|
52
|
-
branch on concrete collection classes:
|
|
53
|
-
|
|
54
|
-
```text
|
|
55
|
-
Collection
|
|
56
|
-
HashedCollection
|
|
57
|
-
Dictionary
|
|
58
|
-
Set
|
|
59
|
-
OrderedDictionary
|
|
60
|
-
SequenceableCollection
|
|
61
|
-
OrderedCollection
|
|
62
|
-
SortedCollection
|
|
63
|
-
ArrayedCollection
|
|
64
|
-
Array
|
|
65
|
-
String
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
- Build the collection you mean to return. When the result type matters, use
|
|
69
|
-
messages such as `collect:as:`, `select:as:`, or `flatCollect:as:` instead
|
|
70
|
-
of collecting into one species and immediately converting to another.
|
|
71
|
-
- Avoid intermediate collections. Prefer fused messages such as
|
|
72
|
-
`select:thenCollect:` and `reject:thenCollect:` when filtering and
|
|
73
|
-
transforming. When a filtered or transformed collection exists only to feed
|
|
74
|
-
iteration, use `select:thenDo:`, `reject:thenDo:`, or `collect:thenDo:`.
|
|
75
|
-
Use `groupedBy:` for simple grouping.
|
|
76
|
-
- Prefer direct queries over filtered collections. Use `detect:ifNone:` for a
|
|
77
|
-
first match with fallback, and `anySatisfy:`, `allSatisfy:`, or
|
|
78
|
-
`noneSatisfy:` when asking a boolean question.
|
|
79
|
-
- Use streaming constructors such as `Array streamContents:` and
|
|
80
|
-
`String streamContents:` when code conditionally appends values or would
|
|
81
|
-
otherwise need a temporary `OrderedCollection`.
|
|
82
|
-
- Avoid conversion chains that exist only to sort or change species, such as
|
|
83
|
-
`asSortedCollection asArray`. Sort a `SequenceableCollection` in-place with
|
|
84
|
-
`sort`/`sort:`, or make a copy with `sorted`/`sorted:`.
|
|
85
|
-
|
|
86
|
-
## Conditions
|
|
87
|
-
|
|
88
|
-
- Avoid assignment inside boolean conditions. Conditions should decide control
|
|
89
|
-
flow, not also mutate state.
|
|
90
|
-
- Keep questions pure: predicates should answer questions, not mutate state.
|
|
91
|
-
- When the fallback value is `nil`, prefer a one-arm conditional. In Pharo,
|
|
92
|
-
`ifTrue:` answers `nil` when the condition is false, and `ifFalse:` answers
|
|
93
|
-
`nil` when the condition is true.
|
|
94
|
-
- Use `ifNotNil:` for local nil traversal when a boundary API can genuinely
|
|
95
|
-
return `nil` and the next step is asking the non-nil object for a value.
|
|
96
|
-
- Prefer presence-aware lookup messages over lookup-to-nil followed by a nil
|
|
97
|
-
check. Use `ifPresent:` or `ifPresent:ifAbsent:` variants when they keep the
|
|
98
|
-
present case local; add `ifAbsent: [ ]` when absence should be an explicit
|
|
99
|
-
no-op.
|
|
100
|
-
- Keep simple boolean predicates simple. Expressions such as
|
|
101
|
-
`value notNil and: [ value isReady ]` are idiomatic when the result is a
|
|
102
|
-
boolean. Do not rewrite them into `ifNil:/ifNotNil:` only to return a
|
|
103
|
-
boolean literal from one branch.
|
|
104
|
-
- Remove nil-only branches from nil traversal. Both `receiver ifNil: [ nil ]
|
|
105
|
-
ifNotNil: [ ... ]` and `receiver ifNotNil: [ ... ] ifNil: [ nil ]` should
|
|
106
|
-
normally become `receiver ifNotNil: [ ... ]`.
|
|
107
|
-
- Avoid defensive type or protocol checks in private helpers unless the helper
|
|
108
|
-
is an explicit boundary. Let incorrect callers fail or validate at the
|
|
109
|
-
boundary with a named policy.
|
|
110
|
-
- Prefer a direct send to a known collaborator over a defensive wrapper. Add a
|
|
111
|
-
wrapper or extension after concrete variation appears, not before.
|
|
112
|
-
|
|
113
|
-
## Review Smells
|
|
114
|
-
|
|
115
|
-
Scan for:
|
|
116
|
-
|
|
117
|
-
- duplicated sends in both conditional branches when only one receiver or
|
|
118
|
-
argument changes;
|
|
119
|
-
- dependent work performed before a guard proves the value is present or valid;
|
|
120
|
-
- assignment embedded inside boolean conditions;
|
|
121
|
-
- repeated `isNotNil` checks where `ifNotNil:` would express local nil
|
|
122
|
-
traversal;
|
|
123
|
-
- lookup with `ifAbsent: [ nil ]` followed by a nil check where an
|
|
124
|
-
`ifPresent:` variant can express the positive path directly;
|
|
125
|
-
- `ifNil:/ifNotNil:` expressions that return only `true` or `false` from one
|
|
126
|
-
branch and would read more directly as a boolean condition;
|
|
127
|
-
- `ifNil: [ nil ] ifNotNil: [...]` or `ifNotNil: [...] ifNil: [ nil ]`
|
|
128
|
-
branches where plain `ifNotNil:` communicates the same behavior;
|
|
129
|
-
- collection pipelines that allocate intermediate collections only to
|
|
130
|
-
immediately convert, sort, query emptiness, take a first match, or group
|
|
131
|
-
values manually;
|
|
132
|
-
- `select:`, `reject:`, or `collect:` immediately followed by `do:` when a
|
|
133
|
-
`thenDo:` variant would avoid the intermediate collection;
|
|
134
|
-
- sorting through conversion chains instead of sorting a result array directly;
|
|
135
|
-
- defensive type checks in private helpers that hide caller bugs;
|
|
136
|
-
- cascaded stream writes, where `stream << a; << b` says what `stream << a << b`
|
|
137
|
-
says with more punctuation, since `<<` answers the stream;
|
|
138
|
-
- wrapper methods or extensions that exist only because a collaborator might be
|
|
139
|
-
wrong someday;
|
|
140
|
-
- dense nested expressions that would be clearer with a temporary or extracted
|
|
141
|
-
method.
|