-
Notifications
You must be signed in to change notification settings - Fork 0
WL-0MMNCOIYF18YPLFB: add structured audit writes and doctor JSON migration apply #973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SorraTheOrc
merged 4 commits into
main
from
feature/WL-0MMNCOIYF18YPLFB-audit-text-write-path
Mar 21, 2026
+576
−557
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c0e14f
WL-0MMZIV38S1V7XRL3: apply doctor migrations in JSON confirm mode
SorraTheOrc 94c30df
WL-0MMNCOIYF18YPLFB: add structured audit-text write path
SorraTheOrc f072a87
Update src/commands/doctor.ts
SorraTheOrc 9868ea7
WL-0MMNCOIYF18YPLFB: address PR review on API audit gate and migrations
SorraTheOrc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,114 +1,22 @@ | ||
| /** | ||
| * Audit entry utilities for Worklog. | ||
| * | ||
| * Provides helpers for building structured AuditEntry objects from | ||
| * freeform audit text, including conservative status derivation. | ||
| * | ||
| * Status derivation is intentionally conservative: | ||
| * - If the work item description lacks explicit success criteria, status | ||
| * is set to 'Missing Criteria' rather than inferring from audit text. | ||
| * - Keyword matching uses conservative thresholds to prefer 'Partial' or | ||
| * 'Not Started' over 'Complete' when uncertain. | ||
| */ | ||
| import os from 'node:os'; | ||
| import type { WorkItemAudit } from './types.js'; | ||
|
|
||
| import * as os from 'os'; | ||
| import type { AuditEntry, AuditStatus } from './types.js'; | ||
|
|
||
| /** | ||
| * Patterns that indicate explicit success criteria in a work item description. | ||
| * At least one must match for the description to be considered criteria-bearing. | ||
| */ | ||
| const CRITERIA_PATTERNS = [ | ||
| /success criteria/i, | ||
| /acceptance criteria/i, | ||
| /\bAC\s*\d+/, | ||
| /\bdone when\b/i, | ||
| /\bcomplete when\b/i, | ||
| /\bshould\b.*\bcan\b/i, | ||
| /\bmust\b.*\bwhen\b/i, | ||
| /- \[[ xX]\]/, // checkbox list items often indicate criteria | ||
| ]; | ||
|
|
||
| /** | ||
| * Returns true if the description appears to contain explicit success criteria. | ||
| */ | ||
| export function hasExplicitCriteria(description: string): boolean { | ||
| if (!description || description.trim() === '') return false; | ||
| return CRITERIA_PATTERNS.some(p => p.test(description)); | ||
| } | ||
|
|
||
| /** | ||
| * Conservatively derive an AuditStatus from audit text and item description. | ||
| * | ||
| * Rules (applied in order): | ||
| * 1. If description lacks explicit success criteria → 'Missing Criteria' | ||
| * 2. If audit text contains strong completion signals → 'Complete' | ||
| * 3. If audit text contains partial-progress signals → 'Partial' | ||
| * 4. Default → 'Not Started' | ||
| */ | ||
| export function deriveAuditStatus(auditText: string, description: string): AuditStatus { | ||
| if (!hasExplicitCriteria(description)) { | ||
| return 'Missing Criteria'; | ||
| } | ||
|
|
||
| const text = auditText.toLowerCase(); | ||
|
|
||
| // Strong completion signals (all criteria must be satisfied) | ||
| const completePatterns = [ | ||
| /\ball criteria (met|satisfied|complete)\b/, | ||
| /\bfully (complete|done|finished|implemented)\b/, | ||
| /\bcomplete\b.*\ball\b/, | ||
| /\ball (done|complete|finished)\b/, | ||
| /\bimplementation complete\b/, | ||
| /\bdelivery complete\b/, | ||
| ]; | ||
| if (completePatterns.some(p => p.test(text))) { | ||
| return 'Complete'; | ||
| } | ||
|
|
||
| // Partial-progress signals | ||
| const partialPatterns = [ | ||
| /\bpartially\b/, | ||
| /\bin progress\b/, | ||
| /\bsome criteria\b/, | ||
| /\bpartial\b/, | ||
| /\bincomplete\b/, | ||
| /\bremaining\b/, | ||
| /\bnot all\b/, | ||
| /\bpending\b/, | ||
| /\bwork in progress\b/, | ||
| /\bwip\b/, | ||
| ]; | ||
| if (partialPatterns.some(p => p.test(text))) { | ||
| return 'Partial'; | ||
| } | ||
|
|
||
| // Default conservative | ||
| return 'Not Started'; | ||
| } | ||
|
|
||
| /** | ||
| * Get the current user identity for audit authorship. | ||
| * Returns the OS username, falling back to 'unknown' if unavailable. | ||
| */ | ||
| export function getCurrentUser(): string { | ||
| export function resolveAuditAuthor(): string { | ||
| const explicit = process.env.WL_USER || process.env.USER || process.env.USERNAME; | ||
| if (explicit && explicit.trim()) return explicit.trim(); | ||
| try { | ||
| return os.userInfo().username || 'unknown'; | ||
| const username = os.userInfo().username; | ||
| if (username && username.trim()) return username.trim(); | ||
| } catch { | ||
| return process.env.USER || process.env.USERNAME || 'unknown'; | ||
| // fall back below | ||
| } | ||
| return 'worklog'; | ||
| } | ||
|
|
||
| /** | ||
| * Build a complete AuditEntry from freeform text and the work item description. | ||
| * Populates `time` from now, `author` from the current OS user, | ||
| * and derives `status` conservatively. | ||
| */ | ||
| export function buildAuditEntry(auditText: string, description: string): AuditEntry { | ||
| export function buildAuditEntry(auditText: string, author?: string): WorkItemAudit { | ||
| return { | ||
| time: new Date().toISOString(), | ||
| author: getCurrentUser(), | ||
| author: author && author.trim() ? author.trim() : resolveAuditAuthor(), | ||
| text: auditText, | ||
| status: deriveAuditStatus(auditText, description), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.