You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e4dbb84
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: .agents/architecture-rules.md
+78Lines changed: 78 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,13 +32,91 @@ the system itself; this file governs how new architecture is designed.
32
32
23. Use methods on an owned handle for operations tied to that instance.
33
33
24. Use a Context to select a scoped service; capture it for any lifetime that requires a fixed provider.
34
34
25. Use middleware when per-call interception or transformation is an intended extension point.
35
+
26. Installed plugins, providers, middleware and TypeScript components are trusted application code; XMD does not contain malicious extensions.
36
+
27. Generated evaluation treats its input as untrusted and enforces the host's allowed operations before performing effects.
37
+
28. Documents explicitly selected for execution are trusted programs that run with the access their host and runtime permit.
38
+
29. Validate external data where its owning API interprets it; internal code may rely on the validated contract.
39
+
30. Validate saved history for format, supported version and run/effect consistency; deliberate rewriting of local storage is outside the threat model.
40
+
31. Protect credentials and explicitly identified secrets from accidental disclosure; paths and ordinary error details are not inherently secret.
41
+
32. Justify defensive complexity with an in-scope threat or consequential failure, and use the simplest sufficient implementation and evidence.
42
+
33. Before hooks receive no continuation; returning normally proceeds automatically, while throwing prevents the operation.
43
+
34. After hooks observe outcomes without replacing them; hook failures leave completed effects unchanged and never trigger an automatic retry.
44
+
35. When an operation and its after hook both fail, keep the operation's failure primary and report the hook failure alongside it.
45
+
36. Before hooks run from outer to inner; after hooks run from inner to outer.
46
+
37. Registered after hooks run on unwind, including before-hook rejection; one failing after hook does not prevent the remaining hooks from running.
47
+
38. A call owns its hooks and waits for their cleanup; after hooks observe cancellation explicitly and cancellation remains cancellation.
48
+
39. createHooks uses unchanged createApi and returns the named operation plus independent before/after registration functions.
49
+
40. After hooks receive Effection Result<T>; cancellation carries a dedicated cancellation error while the call continues to unwind as cancelled.
35
50
36
51
Rules 23–25 choose the API by ownership and intended composition. A captured
37
52
service keeps provider selection fixed for its consumer's lifetime; its mutable
38
53
configuration still follows that service's own update contract. A Context
39
54
selects a trusted service, while authorization, durable identity,
40
55
reconciliation and canonical outcomes stay with their owners.
41
56
57
+
Rule 26 sets the [extension trust boundary](../architecture.md#security-model).
58
+
Defending against deliberately malicious installed extension code does not
59
+
justify a security mechanism or an adversarial test. Trusted code can still
60
+
contain bugs; supported API behavior remains part of each feature's contract.
61
+
62
+
Rule 27 applies at generated-evaluation entry points such as `<Evaluate>`.
63
+
A read-only evaluation refuses a generated file write or shell command before
64
+
any effect. The admitted component implementations remain trusted under rule 26.
65
+
66
+
Rule 28 applies to documents a caller chooses to run, such as
67
+
`xmd run document.md`, including their `exec` and `eval` blocks. Choosing a
68
+
document requires trusting its contents. Text passed to generated evaluation
69
+
remains subject to rule 27.
70
+
71
+
Rule 29 covers service responses, file contents and saved records. Security
72
+
tests exercise inputs the boundary can receive: missing fields and invalid
73
+
values in a JSON response, for example. Deliberately malicious JavaScript
74
+
getters require executable code and fall under rule 26.
75
+
76
+
Rule 30 protects continuation from corrupted or mismatched records. XMD makes
77
+
no authenticity guarantee against someone who can rewrite the underlying local
78
+
database and construct a consistent replacement history.
79
+
80
+
Rule 31 allows useful paths and ordinary error details in diagnostics. An
81
+
absolute path is not sensitive merely because it is absolute; a path explicitly
82
+
identified as sensitive still receives protection. Relative-path formats can
83
+
also serve portability and compatibility independently of secrecy.
84
+
85
+
Rule 32 includes reliability requirements such as correct replay, preventing
86
+
duplicate external writes and completing cancellation cleanup. Additional
87
+
adversarial tests cover distinct failure paths that matter under the security
88
+
model or a supported reliability contract.
89
+
90
+
Rule 33 keeps invocation control with the operation's owner. A hook does not
91
+
receive `next` and cannot omit or repeat a delegation. It can refuse execution
92
+
by throwing before the underlying operation begins.
93
+
94
+
Rules 34–35 keep the operation's outcome separate from a hook's failure. An
95
+
after hook receives success or failure and returns no replacement value. If
96
+
the operation succeeded and an after hook fails, the call reports the hook
97
+
failure while the completed effect and its saved result remain unchanged.
98
+
99
+
Rule 36 orders each independently registered set of callbacks around the
100
+
operation, matching middleware's nesting order.
101
+
102
+
Rules 37–38 cover success, failure, cancellation and refusal by any before
103
+
hook. After callbacks observe a before-hook rejection even though the underlying
104
+
operation never starts. A before hook interrupted partway through uses its own
105
+
Effection cleanup for anything it acquired. Independent registrations have no
106
+
matching-pair requirement.
107
+
108
+
Rule 39 gives `createHooks<"expand", TArgs, TResult>(...)` the returned members
109
+
`expand`, `beforeExpand` and `afterExpand`. The registration functions accept
110
+
handlers returning `Operation<void>` and give them neither `next` nor a
111
+
replacement return channel. The adapter keeps its middleware private;
112
+
operations offering continuation control retain their existing `.around(...)`.
113
+
114
+
Rule 40 uses `Ok(value)` for success and `Err(error)` for a before-hook
115
+
rejection or implementation failure. Cancellation uses the same `Err` channel
116
+
with a dedicated error type. This is the after-hook notification; it does not
117
+
turn cancellation into an ordinary returned failure. All after hooks receive
118
+
the outcome selected before they run, independent of other after-hook failures.
119
+
42
120
The Architect applies these rules without another approval when they settle a
43
121
design. A new concept, ambiguous fit, conflict or proposed exception returns to
0 commit comments