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
Adds a 'Code comments' subsection under Code Conventions that codifies WHY-focused commenting expectations for this repo's Node.js scripts and hooks. Covers documenting non-obvious reasoning, showing raw formats when parsing CLI/OData output, linking external standards (Dataverse status codes, OData error shapes), explaining privacy/telemetry behavior, and keeping workaround comments with tracking links. Examples are grounded in real repo patterns (pac auth banner parse, asyncoperations polling, telemetry scrubber).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: AGENTS.md
+99Lines changed: 99 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,6 +77,105 @@ Current adopters: `power-pages`. Others adopt on demand.
77
77
78
78
**DRY (Don't Repeat Yourself):** Never duplicate logic across files. Each plugin has shared utilities (e.g., `scripts/lib/`) and shared reference docs (e.g., `references/`). Always check for and reuse existing helpers before writing new code. When adding shared logic, put it in the plugin's shared modules — not in individual skill directories.
79
79
80
+
### Code comments
81
+
82
+
Most code in this repo is Node.js scripts and hooks that shell out to `pac`/`az`, call the Dataverse and Power Platform APIs, and parse loosely structured CLI output. The reasoning behind a line is rarely obvious from the line alone, so comments matter.
83
+
84
+
* Err on the side of over-commenting code when the reasoning is not obvious. Comments should explain **WHY** code is written a particular way; the **WHY** is the most important part.
85
+
* Do comment non-obvious implementation details: concurrency hazards, lifecycle constraints, compatibility requirements, platform quirks, upstream PAC CLI / Dataverse workarounds, and intentional deviations from the obvious helper or API.
86
+
* When parsing strings, logs, CLI output, OData payloads, or other loosely structured data, include a comment with an example of the raw format being parsed. Show edge cases, escaping rules, delimiters, optional fields, or malformed-but-observed inputs when they affect the parser.
87
+
* When code follows an external standard, protocol, or Power Platform convention (Dataverse status codes, OData error shapes, telemetry field contracts), include valid links to the relevant Microsoft Learn or specification source so future readers can verify the rule and understand why the code follows it.
88
+
* When code touches telemetry, auth tokens, or anything privacy/security-sensitive, explain the scope, the opt-in/fail-closed behavior, and **why** — not just what it does.
89
+
* Do not add comments that simply narrate clear code, such as "set the interval" immediately before assigning an interval.
90
+
* Keep workaround comments close to the workaround. Include an issue link when the workaround is tied to an upstream bug, and describe the condition for removing it when that is known.
91
+
92
+
Good comments explain the constraint or tradeoff:
93
+
94
+
```javascript
95
+
// `pac auth who` cold-starts the .NET runtime (~4s on Windows), so cache the parsed
96
+
// result per process — repeated hook invocations must only fork the CLI once.
97
+
let cachedAuth;
98
+
```
99
+
100
+
```javascript
101
+
// Refresh the bearer token roughly every 60s instead of on every poll. A long solution
102
+
// export outlives the token's lifetime, but refreshing each 5s cycle would hammer the
// but some PAC surfaces capitalize the envelope as "Error", so check both before
163
+
// falling back to plain-text pattern matching.
164
+
constodataError=parsed.error||parsed.Error;
165
+
```
166
+
167
+
Avoid comments that restate the code:
168
+
169
+
```javascript
170
+
// Set the interval to five seconds.
171
+
constintervalMs=5000;
172
+
173
+
// Loop over the findings.
174
+
for (constfindingof findings) {
175
+
report(finding);
176
+
}
177
+
```
178
+
80
179
## Maintaining This File
81
180
82
181
When you add new plugins or change the repository-level structure, update this file. For plugin-specific changes, update the plugin's own `AGENTS.md` (e.g., `plugins/power-pages/AGENTS.md`).
0 commit comments