@phren/cli 0.1.37 → 0.1.39
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 +3 -2
- package/dist/cli/hooks.js +3 -0
- package/dist/cli/namespaces-notes.d.ts +1 -0
- package/dist/cli/namespaces-notes.js +142 -0
- package/dist/cli/namespaces-store.js +2 -3
- package/dist/cli/namespaces.d.ts +1 -0
- package/dist/cli/namespaces.js +1 -0
- package/dist/cli-hooks-git.d.ts +1 -1
- package/dist/cli-hooks-git.js +1 -0
- package/dist/cli-registry.js +19 -0
- package/dist/core/note.d.ts +9 -0
- package/dist/core/note.js +20 -0
- package/dist/data/notes.d.ts +28 -0
- package/dist/data/notes.js +193 -0
- package/dist/generated/memory-ui-graph.browser.js +363 -293
- package/dist/governance/rbac.d.ts +1 -1
- package/dist/governance/rbac.js +4 -0
- package/dist/index.js +2 -0
- package/dist/link/doctor.js +68 -0
- package/dist/link/link.js +17 -1
- package/dist/memory-ui-graph.runtime.js +363 -293
- package/dist/phren-core.d.ts +1 -1
- package/dist/phren-core.js +1 -1
- package/dist/shared/index.js +2 -0
- package/dist/store-registry.d.ts +1 -0
- package/dist/store-registry.js +1 -1
- package/dist/tools/notes.d.ts +3 -0
- package/dist/tools/notes.js +146 -0
- package/dist/ui/data.d.ts +2 -0
- package/dist/ui/data.js +7 -0
- package/dist/ui/page.js +10 -2
- package/dist/ui/scripts.d.ts +2 -0
- package/dist/ui/scripts.js +310 -14
- package/dist/ui/server.js +89 -23
- package/dist/ui/styles.d.ts +2 -0
- package/dist/ui/styles.js +59 -0
- package/package.json +9 -1
package/dist/phren-core.d.ts
CHANGED
|
@@ -59,6 +59,6 @@ export type FindingTag = FindingType;
|
|
|
59
59
|
/** Canonical set of known observation tags — derived from FINDING_TYPES */
|
|
60
60
|
export declare const KNOWN_OBSERVATION_TAGS: Set<string>;
|
|
61
61
|
/** Document types in the FTS index */
|
|
62
|
-
export declare const DOC_TYPES: readonly ["claude", "findings", "reference", "skills", "summary", "task", "changelog", "canonical", "review-queue", "skill", "other"];
|
|
62
|
+
export declare const DOC_TYPES: readonly ["claude", "findings", "notes", "reference", "skills", "summary", "task", "changelog", "canonical", "review-queue", "skill", "other"];
|
|
63
63
|
export type DocType = (typeof DOC_TYPES)[number];
|
|
64
64
|
export declare function capCache<K, V>(cache: Map<K, V>): void;
|
package/dist/phren-core.js
CHANGED
|
@@ -93,7 +93,7 @@ export const FINDING_TAGS = FINDING_TYPES;
|
|
|
93
93
|
/** Canonical set of known observation tags — derived from FINDING_TYPES */
|
|
94
94
|
export const KNOWN_OBSERVATION_TAGS = new Set(FINDING_TYPES);
|
|
95
95
|
/** Document types in the FTS index */
|
|
96
|
-
export const DOC_TYPES = ["claude", "findings", "reference", "skills", "summary", "task", "changelog", "canonical", "review-queue", "skill", "other"];
|
|
96
|
+
export const DOC_TYPES = ["claude", "findings", "notes", "reference", "skills", "summary", "task", "changelog", "canonical", "review-queue", "skill", "other"];
|
|
97
97
|
// ── Cache eviction helper ────────────────────────────────────────────────────
|
|
98
98
|
const CACHE_MAX = 1000;
|
|
99
99
|
const CACHE_EVICT = 100;
|
package/dist/shared/index.js
CHANGED
|
@@ -167,6 +167,8 @@ function pathHasSegment(relPath, segment) {
|
|
|
167
167
|
}
|
|
168
168
|
export function classifyFile(filename, relPath) {
|
|
169
169
|
// Directory takes priority over filename-based classification
|
|
170
|
+
if (pathHasSegment(relPath, "notes"))
|
|
171
|
+
return "notes";
|
|
170
172
|
if (pathHasSegment(relPath, "reference"))
|
|
171
173
|
return "reference";
|
|
172
174
|
if (pathHasSegment(relPath, "skills"))
|
package/dist/store-registry.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export interface TeamBootstrap {
|
|
|
26
26
|
description?: string;
|
|
27
27
|
default_role?: StoreRole;
|
|
28
28
|
}
|
|
29
|
+
export declare const STORES_FILENAME = "stores.yaml";
|
|
29
30
|
export declare function storesFilePath(phrenPath: string): string;
|
|
30
31
|
export declare function generateStoreId(): string;
|
|
31
32
|
export declare function readStoreRegistry(phrenPath: string): StoreRegistry | null;
|
package/dist/store-registry.js
CHANGED
|
@@ -7,7 +7,7 @@ import { withFileLock } from "./governance/locks.js";
|
|
|
7
7
|
import { isRecord, PhrenError } from "./phren-core.js";
|
|
8
8
|
import { getProjectDirs } from "./shared.js";
|
|
9
9
|
// ── Constants ────────────────────────────────────────────────────────────────
|
|
10
|
-
const STORES_FILENAME = "stores.yaml";
|
|
10
|
+
export const STORES_FILENAME = "stores.yaml";
|
|
11
11
|
const TEAM_BOOTSTRAP_FILENAME = ".phren-team.yaml";
|
|
12
12
|
const VALID_ROLES = new Set(["primary", "team", "readonly"]);
|
|
13
13
|
const VALID_SYNC_MODES = new Set(["managed-git", "pull-only"]);
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { FINDING_TYPES } from "../shared.js";
|
|
4
|
+
import { FINDINGS_FILENAME } from "../data/access.js";
|
|
5
|
+
import { addNote, editNote, listNotes, removeNote } from "../data/notes.js";
|
|
6
|
+
import { promoteNote } from "../core/note.js";
|
|
7
|
+
import { permissionDeniedError } from "../governance/rbac.js";
|
|
8
|
+
import { mcpResponse, resolveStoreForProject } from "./types.js";
|
|
9
|
+
function resolve(ctx, projectInput) {
|
|
10
|
+
try {
|
|
11
|
+
return { ok: true, value: resolveStoreForProject(ctx, projectInput) };
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function noteSummary(note) {
|
|
18
|
+
const promoted = note.promoted ? " · promoted" : "";
|
|
19
|
+
return `- ${note.date} ${note.time.slice(0, 5)} · ${note.id}${promoted}\n ${note.text.replace(/\n/g, "\n ")}`;
|
|
20
|
+
}
|
|
21
|
+
async function refreshIndex(ctx, storeRole, ...files) {
|
|
22
|
+
if (storeRole === "primary") {
|
|
23
|
+
for (const file of files)
|
|
24
|
+
ctx.updateFileInIndex(file);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// Incremental indexing is rooted at the primary store. A federated/team-store
|
|
28
|
+
// write therefore needs a rebuild so the file retains its real project/store identity.
|
|
29
|
+
await ctx.rebuildIndex();
|
|
30
|
+
}
|
|
31
|
+
export function register(server, ctx) {
|
|
32
|
+
server.registerTool("get_notes", {
|
|
33
|
+
title: "◆ phren · notes",
|
|
34
|
+
description: "List lightweight daily notes for a project. Notes are searchable scratch context and are not injected into agent prompts automatically.",
|
|
35
|
+
inputSchema: z.object({
|
|
36
|
+
project: z.string().describe("Project name, optionally store-qualified (for example team/project)."),
|
|
37
|
+
date: z.string().optional().describe("Optional YYYY-MM-DD date filter."),
|
|
38
|
+
limit: z.number().int().min(1).max(500).optional().describe("Maximum notes to return. Defaults to 100."),
|
|
39
|
+
}),
|
|
40
|
+
}, async ({ project: projectInput, date, limit }) => {
|
|
41
|
+
const target = resolve(ctx, projectInput);
|
|
42
|
+
if (!target.ok)
|
|
43
|
+
return mcpResponse({ ok: false, error: target.error });
|
|
44
|
+
const { phrenPath, project } = target.value;
|
|
45
|
+
const result = listNotes(phrenPath, project, { date, limit: limit ?? 100 });
|
|
46
|
+
if (!result.ok)
|
|
47
|
+
return mcpResponse({ ok: false, error: result.error, errorCode: result.code });
|
|
48
|
+
return mcpResponse({
|
|
49
|
+
ok: true,
|
|
50
|
+
message: result.data.length ? result.data.map(noteSummary).join("\n\n") : `No notes found for ${project}${date ? ` on ${date}` : ""}.`,
|
|
51
|
+
data: { project, notes: result.data },
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
server.registerTool("add_note", {
|
|
55
|
+
title: "◆ phren · add note",
|
|
56
|
+
description: "Add a lightweight Markdown note to a project's daily notes. Use findings instead for durable, agent-curated knowledge.",
|
|
57
|
+
inputSchema: z.object({
|
|
58
|
+
project: z.string().describe("Project name, optionally store-qualified."),
|
|
59
|
+
text: z.string().min(1).describe("Note text; Markdown and multiple lines are supported."),
|
|
60
|
+
date: z.string().optional().describe("Optional YYYY-MM-DD date. Defaults to today."),
|
|
61
|
+
}),
|
|
62
|
+
}, async ({ project: projectInput, text, date }) => {
|
|
63
|
+
const target = resolve(ctx, projectInput);
|
|
64
|
+
if (!target.ok)
|
|
65
|
+
return mcpResponse({ ok: false, error: target.error });
|
|
66
|
+
const { phrenPath, project, storeRole } = target.value;
|
|
67
|
+
const denied = permissionDeniedError(phrenPath, "add_note", project);
|
|
68
|
+
if (denied)
|
|
69
|
+
return mcpResponse({ ok: false, error: denied });
|
|
70
|
+
return ctx.withWriteQueue(async () => {
|
|
71
|
+
const result = addNote(phrenPath, project, text, { date });
|
|
72
|
+
if (!result.ok)
|
|
73
|
+
return mcpResponse({ ok: false, error: result.error, errorCode: result.code });
|
|
74
|
+
await refreshIndex(ctx, storeRole, result.data.path);
|
|
75
|
+
return mcpResponse({ ok: true, message: `Note added to ${project}: ${result.data.id}`, data: { project, note: result.data } });
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
server.registerTool("edit_note", {
|
|
79
|
+
title: "◆ phren · edit note",
|
|
80
|
+
description: "Replace the text of one daily note. Identify it with the stable nid returned by get_notes.",
|
|
81
|
+
inputSchema: z.object({
|
|
82
|
+
project: z.string(),
|
|
83
|
+
note: z.string().min(1).describe("Stable nid (preferred) or an unambiguous text match."),
|
|
84
|
+
text: z.string().min(1).describe("Replacement Markdown text."),
|
|
85
|
+
}),
|
|
86
|
+
}, async ({ project: projectInput, note, text }) => {
|
|
87
|
+
const target = resolve(ctx, projectInput);
|
|
88
|
+
if (!target.ok)
|
|
89
|
+
return mcpResponse({ ok: false, error: target.error });
|
|
90
|
+
const { phrenPath, project, storeRole } = target.value;
|
|
91
|
+
const denied = permissionDeniedError(phrenPath, "edit_note", project);
|
|
92
|
+
if (denied)
|
|
93
|
+
return mcpResponse({ ok: false, error: denied });
|
|
94
|
+
return ctx.withWriteQueue(async () => {
|
|
95
|
+
const result = editNote(phrenPath, project, note, text);
|
|
96
|
+
if (!result.ok)
|
|
97
|
+
return mcpResponse({ ok: false, error: result.error, errorCode: result.code });
|
|
98
|
+
await refreshIndex(ctx, storeRole, result.data.path);
|
|
99
|
+
return mcpResponse({ ok: true, message: `Updated ${result.data.id}.`, data: { project, note: result.data } });
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
server.registerTool("remove_note", {
|
|
103
|
+
title: "◆ phren · remove note",
|
|
104
|
+
description: "Remove one daily note by stable nid or unambiguous text match.",
|
|
105
|
+
inputSchema: z.object({ project: z.string(), note: z.string().min(1) }),
|
|
106
|
+
}, async ({ project: projectInput, note }) => {
|
|
107
|
+
const target = resolve(ctx, projectInput);
|
|
108
|
+
if (!target.ok)
|
|
109
|
+
return mcpResponse({ ok: false, error: target.error });
|
|
110
|
+
const { phrenPath, project, storeRole } = target.value;
|
|
111
|
+
const denied = permissionDeniedError(phrenPath, "remove_note", project);
|
|
112
|
+
if (denied)
|
|
113
|
+
return mcpResponse({ ok: false, error: denied });
|
|
114
|
+
return ctx.withWriteQueue(async () => {
|
|
115
|
+
const result = removeNote(phrenPath, project, note);
|
|
116
|
+
if (!result.ok)
|
|
117
|
+
return mcpResponse({ ok: false, error: result.error, errorCode: result.code });
|
|
118
|
+
await refreshIndex(ctx, storeRole, result.data.path);
|
|
119
|
+
return mcpResponse({ ok: true, message: `Removed ${result.data.id}.`, data: { project, note: result.data } });
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
server.registerTool("promote_note", {
|
|
123
|
+
title: "◆ phren · promote note",
|
|
124
|
+
description: "Copy a daily note into durable findings and mark the source note as promoted. The note remains in the daily record.",
|
|
125
|
+
inputSchema: z.object({
|
|
126
|
+
project: z.string(),
|
|
127
|
+
note: z.string().min(1),
|
|
128
|
+
findingType: z.enum(FINDING_TYPES).optional(),
|
|
129
|
+
}),
|
|
130
|
+
}, async ({ project: projectInput, note, findingType }) => {
|
|
131
|
+
const target = resolve(ctx, projectInput);
|
|
132
|
+
if (!target.ok)
|
|
133
|
+
return mcpResponse({ ok: false, error: target.error });
|
|
134
|
+
const { phrenPath, project, storeRole } = target.value;
|
|
135
|
+
const denied = permissionDeniedError(phrenPath, "promote_note", project);
|
|
136
|
+
if (denied)
|
|
137
|
+
return mcpResponse({ ok: false, error: denied });
|
|
138
|
+
return ctx.withWriteQueue(async () => {
|
|
139
|
+
const result = promoteNote(phrenPath, project, note, findingType);
|
|
140
|
+
if (!result.ok)
|
|
141
|
+
return mcpResponse({ ok: false, error: result.error, errorCode: result.code });
|
|
142
|
+
await refreshIndex(ctx, storeRole, result.data.note.path, path.join(phrenPath, project, FINDINGS_FILENAME));
|
|
143
|
+
return mcpResponse({ ok: true, message: `Promoted ${result.data.note.id} to a finding.`, data: { project, ...result.data } });
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
package/dist/ui/data.d.ts
CHANGED
|
@@ -81,6 +81,8 @@ export declare function isAllowedFilePath(filePath: string, phrenPath: string):
|
|
|
81
81
|
* not the entire phren store.
|
|
82
82
|
*/
|
|
83
83
|
export declare function isAllowedSkillPath(filePath: string, phrenPath: string): boolean;
|
|
84
|
+
/** Allow only the four exact lifecycle-hook config files surfaced by the UI. */
|
|
85
|
+
export declare function isAllowedHookConfigPath(filePath: string, phrenPath: string): boolean;
|
|
84
86
|
export declare function collectSkillsForUI(phrenPath: string, profile?: string): Array<{
|
|
85
87
|
name: string;
|
|
86
88
|
source: string;
|
package/dist/ui/data.js
CHANGED
|
@@ -111,6 +111,13 @@ export function isAllowedSkillPath(filePath, phrenPath) {
|
|
|
111
111
|
const segments = resolved.split(path.sep);
|
|
112
112
|
return segments.some((seg) => seg === "skills");
|
|
113
113
|
}
|
|
114
|
+
/** Allow only the four exact lifecycle-hook config files surfaced by the UI. */
|
|
115
|
+
export function isAllowedHookConfigPath(filePath, phrenPath) {
|
|
116
|
+
if (!isAllowedFilePath(filePath, phrenPath))
|
|
117
|
+
return false;
|
|
118
|
+
const resolved = path.resolve(filePath);
|
|
119
|
+
return Object.values(hookConfigPaths(phrenPath)).some((configPath) => path.resolve(configPath) === resolved);
|
|
120
|
+
}
|
|
114
121
|
export function collectSkillsForUI(phrenPath, profile = "") {
|
|
115
122
|
return getAllSkills(phrenPath, profile).map((skill) => ({
|
|
116
123
|
name: skill.name,
|
package/dist/ui/page.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WEB_UI_STYLES, renderWebUiScript } from "./assets.js";
|
|
2
2
|
import { renderGraphScript } from "./graph.js";
|
|
3
|
-
import { LAYOUT_VIEWPORT_STYLES, PROJECT_REFERENCE_UI_STYLES, REVIEW_UI_STYLES, SETTINGS_TAB_UI_STYLES, TASK_UI_STYLES } from "./styles.js";
|
|
3
|
+
import { FINDING_CAPTURE_UI_STYLES, LAYOUT_VIEWPORT_STYLES, NOTES_UI_STYLES, PROJECT_REFERENCE_UI_STYLES, REVIEW_UI_STYLES, SETTINGS_TAB_UI_STYLES, TASK_UI_STYLES } from "./styles.js";
|
|
4
4
|
import { PHREN_DEEP_VOID_STYLES } from "./deep-void.js";
|
|
5
5
|
import { GRAPH_HUD_STYLES } from "./graph-chrome.js";
|
|
6
|
-
import { renderSharedWebUiHelpers, renderSkillUiEnhancementScript, renderProfileSwitcherScript, renderProjectReferenceEnhancementScript, renderTasksAndSettingsScript, renderReviewQueueKeyboardScript, renderSearchScript, renderEventWiringScript, renderGraphHostScript, renderActivityStreamScript, renderGraphWalkScript, } from "./scripts.js";
|
|
6
|
+
import { renderSharedWebUiHelpers, renderSkillUiEnhancementScript, renderProfileSwitcherScript, renderFindingCaptureEnhancementScript, renderNotesEnhancementScript, renderProjectReferenceEnhancementScript, renderTasksAndSettingsScript, renderReviewQueueKeyboardScript, renderSearchScript, renderEventWiringScript, renderGraphHostScript, renderActivityStreamScript, renderGraphWalkScript, } from "./scripts.js";
|
|
7
7
|
function h(s) {
|
|
8
8
|
return s
|
|
9
9
|
.replace(/&/g, "&")
|
|
@@ -31,6 +31,8 @@ ${REVIEW_UI_STYLES}
|
|
|
31
31
|
${PHREN_DEEP_VOID_STYLES}
|
|
32
32
|
${LAYOUT_VIEWPORT_STYLES}
|
|
33
33
|
${GRAPH_HUD_STYLES}
|
|
34
|
+
${FINDING_CAPTURE_UI_STYLES}
|
|
35
|
+
${NOTES_UI_STYLES}
|
|
34
36
|
</style>
|
|
35
37
|
</head>
|
|
36
38
|
<body>
|
|
@@ -405,6 +407,12 @@ ${renderGraphHostScript()}
|
|
|
405
407
|
${renderSharedWebUiHelpers(authToken || "")}
|
|
406
408
|
</script>
|
|
407
409
|
<script${nonceAttr}>
|
|
410
|
+
${renderFindingCaptureEnhancementScript()}
|
|
411
|
+
</script>
|
|
412
|
+
<script${nonceAttr}>
|
|
413
|
+
${renderNotesEnhancementScript()}
|
|
414
|
+
</script>
|
|
415
|
+
<script${nonceAttr}>
|
|
408
416
|
${renderSkillUiEnhancementScript(h(authToken || ""))}
|
|
409
417
|
</script>
|
|
410
418
|
<script${nonceAttr}>
|
package/dist/ui/scripts.d.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function renderSharedWebUiHelpers(authToken: string): string;
|
|
10
10
|
export declare function renderProfileSwitcherScript(_authToken: string): string;
|
|
11
|
+
export declare function renderFindingCaptureEnhancementScript(): string;
|
|
12
|
+
export declare function renderNotesEnhancementScript(): string;
|
|
11
13
|
export declare function renderSkillUiEnhancementScript(_authToken: string): string;
|
|
12
14
|
export declare function renderProjectReferenceEnhancementScript(_authToken: string): string;
|
|
13
15
|
export declare function renderTasksAndSettingsScript(authToken: string): string;
|
package/dist/ui/scripts.js
CHANGED
|
@@ -84,6 +84,251 @@ export function renderProfileSwitcherScript(_authToken) {
|
|
|
84
84
|
}
|
|
85
85
|
})();`;
|
|
86
86
|
}
|
|
87
|
+
export function renderFindingCaptureEnhancementScript() {
|
|
88
|
+
return `(function() {
|
|
89
|
+
function selectedProject() {
|
|
90
|
+
var card = document.querySelector('.project-card.selected');
|
|
91
|
+
return card ? (card.getAttribute('data-project') || '') : '';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function findingsTab() {
|
|
95
|
+
return document.querySelector('.project-detail-tab[data-file="FINDINGS.md"]');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function wireCaptureBar() {
|
|
99
|
+
var container = document.getElementById('project-content');
|
|
100
|
+
var tab = findingsTab();
|
|
101
|
+
if (!container || !tab || !tab.classList.contains('active')) return;
|
|
102
|
+
|
|
103
|
+
container.querySelectorAll('.finding-detail-card summary').forEach(function(summary) {
|
|
104
|
+
summary.textContent = (summary.textContent || '').replace(/\\s*<!--.*?-->\\s*/g, ' ').trim();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
var input = document.getElementById('finding-add-input');
|
|
108
|
+
if (!input) {
|
|
109
|
+
var project = selectedProject();
|
|
110
|
+
if (!project || container.querySelector('.project-detail-empty')) return;
|
|
111
|
+
var bar = document.createElement('div');
|
|
112
|
+
bar.className = 'finding-capture-bar';
|
|
113
|
+
bar.innerHTML = '<input id="finding-add-input" type="text" placeholder="Record durable knowledge…" aria-label="Finding text">' +
|
|
114
|
+
'<button type="button" class="btn btn-sm btn-primary" data-finding-capture-submit>Add finding</button>';
|
|
115
|
+
container.insertBefore(bar, container.firstChild);
|
|
116
|
+
input = bar.querySelector('#finding-add-input');
|
|
117
|
+
} else {
|
|
118
|
+
var existingBar = input.parentElement;
|
|
119
|
+
if (existingBar) existingBar.classList.add('finding-capture-bar');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!input || input.getAttribute('data-capture-wired') === 'true') return;
|
|
123
|
+
input.setAttribute('data-capture-wired', 'true');
|
|
124
|
+
input.setAttribute('placeholder', 'Record durable knowledge…');
|
|
125
|
+
input.addEventListener('keydown', function(event) {
|
|
126
|
+
if (event.key !== 'Enter') return;
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
window.phrenAddFinding(selectedProject());
|
|
129
|
+
});
|
|
130
|
+
var button = input.parentElement && input.parentElement.querySelector('button');
|
|
131
|
+
if (button) {
|
|
132
|
+
button.textContent = 'Add finding';
|
|
133
|
+
button.addEventListener('click', function(event) {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
window.phrenAddFinding(selectedProject());
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
window.selectProjectFile = function(file) {
|
|
141
|
+
var tab = document.querySelector('.project-detail-tab[data-file="' + file + '"]');
|
|
142
|
+
if (tab && typeof window.loadProjectFile === 'function') window.loadProjectFile(file, tab);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
var baseSelectProject = window.selectProject;
|
|
146
|
+
if (typeof baseSelectProject === 'function') {
|
|
147
|
+
window.selectProject = function(name, el) {
|
|
148
|
+
baseSelectProject(name, el);
|
|
149
|
+
var header = document.querySelector('.project-detail-header');
|
|
150
|
+
if (header && !header.querySelector('.capture-finding-btn')) {
|
|
151
|
+
var button = document.createElement('button');
|
|
152
|
+
button.type = 'button';
|
|
153
|
+
button.className = 'btn btn-sm btn-primary capture-finding-btn';
|
|
154
|
+
button.textContent = '+ Add finding';
|
|
155
|
+
button.addEventListener('click', function() {
|
|
156
|
+
window.selectProjectFile('FINDINGS.md');
|
|
157
|
+
window.setTimeout(function() {
|
|
158
|
+
wireCaptureBar();
|
|
159
|
+
var input = document.getElementById('finding-add-input');
|
|
160
|
+
if (input) input.focus();
|
|
161
|
+
}, 0);
|
|
162
|
+
});
|
|
163
|
+
header.appendChild(button);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var detailArea = document.getElementById('project-detail-area');
|
|
169
|
+
if (detailArea) {
|
|
170
|
+
new MutationObserver(function() { window.setTimeout(wireCaptureBar, 0); })
|
|
171
|
+
.observe(detailArea, { childList: true, subtree: true });
|
|
172
|
+
}
|
|
173
|
+
})();`;
|
|
174
|
+
}
|
|
175
|
+
export function renderNotesEnhancementScript() {
|
|
176
|
+
return `(function() {
|
|
177
|
+
var esc = window._phrenEsc;
|
|
178
|
+
var authUrl = window._phrenAuthUrl;
|
|
179
|
+
|
|
180
|
+
function selectedProject() {
|
|
181
|
+
var card = document.querySelector('.project-card.selected');
|
|
182
|
+
return card ? (card.getAttribute('data-project') || '') : '';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function request(project, method, values, done) {
|
|
186
|
+
window._phrenFetchCsrfToken(function(csrfToken) {
|
|
187
|
+
var body = new URLSearchParams(values || {});
|
|
188
|
+
if (csrfToken) body.set('_csrf', csrfToken);
|
|
189
|
+
fetch(authUrl('/api/notes/' + encodeURIComponent(project)), {
|
|
190
|
+
method: method,
|
|
191
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
192
|
+
body: window._phrenAuthBody(body.toString())
|
|
193
|
+
}).then(function(r) { return r.json(); }).then(function(data) {
|
|
194
|
+
if (!data.ok) throw new Error(data.error || 'Note operation failed');
|
|
195
|
+
done(data);
|
|
196
|
+
}).catch(function(err) { alert(String(err.message || err)); });
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function renderNotes(project, notes) {
|
|
201
|
+
var container = document.getElementById('project-content');
|
|
202
|
+
if (!container) return;
|
|
203
|
+
var today = new Date().toISOString().slice(0, 10);
|
|
204
|
+
var html = '<div class="notes-panel">' +
|
|
205
|
+
'<div class="note-capture">' +
|
|
206
|
+
'<textarea id="note-add-text" rows="3" placeholder="What happened today? Markdown is welcome." aria-label="Note text"></textarea>' +
|
|
207
|
+
'<div class="note-capture-actions"><input id="note-add-date" type="date" value="' + today + '" aria-label="Note date">' +
|
|
208
|
+
'<button type="button" class="btn btn-primary" data-note-action="add">Add note</button></div>' +
|
|
209
|
+
'</div>';
|
|
210
|
+
if (!notes.length) {
|
|
211
|
+
html += '<div class="project-detail-empty">No notes yet. Add a quick daily note above.</div>';
|
|
212
|
+
} else {
|
|
213
|
+
var lastDate = '';
|
|
214
|
+
notes.forEach(function(note) {
|
|
215
|
+
if (note.date !== lastDate) {
|
|
216
|
+
if (lastDate) html += '</div>';
|
|
217
|
+
lastDate = note.date;
|
|
218
|
+
html += '<div class="note-day"><div class="note-day-heading">' + esc(note.date) + '</div>';
|
|
219
|
+
}
|
|
220
|
+
html += '<article class="note-card" data-note-id="' + esc(note.id) + '">' +
|
|
221
|
+
'<div class="note-card-meta"><span>' + esc(String(note.time || '').slice(0, 5)) + '</span>' +
|
|
222
|
+
'<code>' + esc(note.id) + '</code>' +
|
|
223
|
+
(note.promoted ? '<span class="note-promoted">promoted</span>' : '') + '</div>' +
|
|
224
|
+
'<div class="note-card-text">' + esc(note.text).replace(/\\n/g, '<br>') + '</div>' +
|
|
225
|
+
'<div class="note-card-actions">' +
|
|
226
|
+
'<button type="button" class="btn btn-sm" data-note-action="edit">Edit</button>' +
|
|
227
|
+
(!note.promoted ? '<button type="button" class="btn btn-sm" data-note-action="promote">Promote to finding</button>' : '') +
|
|
228
|
+
'<button type="button" class="btn btn-sm note-remove" data-note-action="remove">Remove</button>' +
|
|
229
|
+
'</div>' +
|
|
230
|
+
'<textarea class="note-raw-text" hidden>' + esc(note.text) + '</textarea>' +
|
|
231
|
+
'</article>';
|
|
232
|
+
});
|
|
233
|
+
if (lastDate) html += '</div>';
|
|
234
|
+
}
|
|
235
|
+
container.innerHTML = html + '</div>';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function loadNotes(focusCapture) {
|
|
239
|
+
var project = selectedProject();
|
|
240
|
+
var container = document.getElementById('project-content');
|
|
241
|
+
if (!project || !container) return;
|
|
242
|
+
container.innerHTML = '<div class="project-detail-empty">Loading notes...</div>';
|
|
243
|
+
fetch(authUrl('/api/notes/' + encodeURIComponent(project)))
|
|
244
|
+
.then(function(r) { return r.json(); })
|
|
245
|
+
.then(function(data) {
|
|
246
|
+
if (!data.ok) throw new Error(data.error || 'Failed to load notes');
|
|
247
|
+
renderNotes(project, (data.data && data.data.notes) || []);
|
|
248
|
+
if (focusCapture) {
|
|
249
|
+
var input = document.getElementById('note-add-text');
|
|
250
|
+
if (input) input.focus();
|
|
251
|
+
}
|
|
252
|
+
}).catch(function(err) {
|
|
253
|
+
container.innerHTML = '<div class="project-detail-empty">' + esc(err.message || err) + '</div>';
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var baseSelectProject = window.selectProject;
|
|
258
|
+
if (typeof baseSelectProject === 'function') {
|
|
259
|
+
window.selectProject = function(name, el) {
|
|
260
|
+
baseSelectProject(name, el);
|
|
261
|
+
var tabs = document.querySelector('.project-detail-tabs');
|
|
262
|
+
if (tabs && !tabs.querySelector('[data-file="notes:daily"]')) {
|
|
263
|
+
var tab = document.createElement('button');
|
|
264
|
+
tab.type = 'button';
|
|
265
|
+
tab.className = 'project-detail-tab';
|
|
266
|
+
tab.setAttribute('data-ui-action', 'loadProjectFile');
|
|
267
|
+
tab.setAttribute('data-file', 'notes:daily');
|
|
268
|
+
tab.textContent = 'Notes';
|
|
269
|
+
var reference = tabs.querySelector('[data-file="reference:browser"]');
|
|
270
|
+
tabs.insertBefore(tab, reference);
|
|
271
|
+
}
|
|
272
|
+
var header = document.querySelector('.project-detail-header');
|
|
273
|
+
if (header && !header.querySelector('.capture-note-btn')) {
|
|
274
|
+
var button = document.createElement('button');
|
|
275
|
+
button.type = 'button';
|
|
276
|
+
button.className = 'btn btn-sm capture-note-btn';
|
|
277
|
+
button.textContent = '+ Add note';
|
|
278
|
+
button.addEventListener('click', function() {
|
|
279
|
+
window.selectProjectFile('notes:daily');
|
|
280
|
+
window.setTimeout(function() { loadNotes(true); }, 0);
|
|
281
|
+
});
|
|
282
|
+
header.appendChild(button);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
var baseLoadProjectFile = window.loadProjectFile;
|
|
288
|
+
window.loadProjectFile = function(file, btn) {
|
|
289
|
+
if (file !== 'notes:daily') return baseLoadProjectFile(file, btn);
|
|
290
|
+
document.querySelectorAll('.project-detail-tab').forEach(function(tab) { tab.classList.remove('active'); });
|
|
291
|
+
var notesTab = btn || document.querySelector('.project-detail-tab[data-file="notes:daily"]');
|
|
292
|
+
if (notesTab) notesTab.classList.add('active');
|
|
293
|
+
loadNotes(false);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
document.addEventListener('click', function(event) {
|
|
297
|
+
var button = event.target && event.target.closest ? event.target.closest('[data-note-action]') : null;
|
|
298
|
+
if (!button) return;
|
|
299
|
+
var project = selectedProject();
|
|
300
|
+
if (!project) return;
|
|
301
|
+
var action = button.getAttribute('data-note-action');
|
|
302
|
+
if (action === 'add') {
|
|
303
|
+
var text = document.getElementById('note-add-text');
|
|
304
|
+
var date = document.getElementById('note-add-date');
|
|
305
|
+
if (!text || !text.value.trim()) return;
|
|
306
|
+
request(project, 'POST', { text: text.value.trim(), date: date ? date.value : '' }, function() { loadNotes(true); });
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
var card = button.closest('.note-card');
|
|
310
|
+
if (!card) return;
|
|
311
|
+
var note = card.getAttribute('data-note-id') || '';
|
|
312
|
+
var raw = card.querySelector('.note-raw-text');
|
|
313
|
+
var current = raw ? raw.value : '';
|
|
314
|
+
if (action === 'edit') {
|
|
315
|
+
var next = prompt('Edit note', current);
|
|
316
|
+
if (next === null || !next.trim() || next === current) return;
|
|
317
|
+
request(project, 'PUT', { note: note, text: next.trim() }, function() { loadNotes(false); });
|
|
318
|
+
} else if (action === 'remove') {
|
|
319
|
+
if (!confirm('Remove this note?')) return;
|
|
320
|
+
request(project, 'DELETE', { note: note }, function() { loadNotes(false); });
|
|
321
|
+
} else if (action === 'promote') {
|
|
322
|
+
var findingType = prompt('Finding type (optional): decision, pitfall, pattern, tradeoff, architecture, bug', '');
|
|
323
|
+
if (findingType === null) return;
|
|
324
|
+
findingType = findingType.trim().toLowerCase();
|
|
325
|
+
var valid = ['', 'decision', 'pitfall', 'pattern', 'tradeoff', 'architecture', 'bug'];
|
|
326
|
+
if (valid.indexOf(findingType) === -1) { alert('Unknown finding type.'); return; }
|
|
327
|
+
request(project, 'POST', { action: 'promote', note: note, finding_type: findingType }, function() { loadNotes(false); });
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
})();`;
|
|
331
|
+
}
|
|
87
332
|
export function renderSkillUiEnhancementScript(_authToken) {
|
|
88
333
|
return `(function() {
|
|
89
334
|
var _skillCurrent = null;
|
|
@@ -1764,6 +2009,36 @@ export function renderEventWiringScript() {
|
|
|
1764
2009
|
else if (action === 'clear') { clearBatchSelection(); }
|
|
1765
2010
|
});
|
|
1766
2011
|
|
|
2012
|
+
// The legacy hook rows use .hook-item rather than .split-item. Their original
|
|
2013
|
+
// delegated handler therefore passes null to selectHookFromEl; wire the actual
|
|
2014
|
+
// row here so lifecycle hook details remain selectable.
|
|
2015
|
+
document.addEventListener('click', function(e) {
|
|
2016
|
+
var target = e.target;
|
|
2017
|
+
if (!target || typeof target.closest !== 'function') return;
|
|
2018
|
+
var hook = target.closest('.hook-item[data-ui-action="selectHookFromEl"]');
|
|
2019
|
+
if (hook && typeof selectHookFromEl === 'function') selectHookFromEl(hook);
|
|
2020
|
+
});
|
|
2021
|
+
|
|
2022
|
+
// Keep review-card action metadata aligned with the queue line after an edit.
|
|
2023
|
+
// The base submit handler sends the old line first; this listener then updates
|
|
2024
|
+
// the DOM identity used by subsequent approve/reject actions.
|
|
2025
|
+
document.addEventListener('submit', function(e) {
|
|
2026
|
+
var form = e.target;
|
|
2027
|
+
if (!form || form.getAttribute('data-ui-action') !== 'reviewEditSubmit') return;
|
|
2028
|
+
var card = form.closest('.review-card');
|
|
2029
|
+
var textarea = form.querySelector('textarea[name="new_text"]');
|
|
2030
|
+
if (!card || !textarea) return;
|
|
2031
|
+
var oldLine = form.getAttribute('data-line') || '';
|
|
2032
|
+
var text = String(textarea.value || '').replace(/[\\r\\n]+/g, ' ').trim();
|
|
2033
|
+
if (!text) return;
|
|
2034
|
+
var dateMatch = oldLine.match(/^- \\[(\\d{4}-\\d{2}-\\d{2})\\]\\s*/);
|
|
2035
|
+
var updatedLine = dateMatch ? '- [' + dateMatch[1] + '] ' + text : '- ' + text;
|
|
2036
|
+
var project = card.getAttribute('data-project') || form.getAttribute('data-project') || '';
|
|
2037
|
+
card.setAttribute('data-key', project + '\\\\x00' + updatedLine);
|
|
2038
|
+
form.setAttribute('data-line', updatedLine);
|
|
2039
|
+
card.querySelectorAll('[data-line]').forEach(function(el) { el.setAttribute('data-line', updatedLine); });
|
|
2040
|
+
});
|
|
2041
|
+
|
|
1767
2042
|
// --- Graph controls ---
|
|
1768
2043
|
var graphZoomIn = document.getElementById('graph-zoom-in');
|
|
1769
2044
|
if (graphZoomIn) graphZoomIn.addEventListener('click', function() { graphZoom(1.2); });
|
|
@@ -2408,20 +2683,41 @@ export function renderGraphHostScript() {
|
|
|
2408
2683
|
deleteNode(currentNode);
|
|
2409
2684
|
}
|
|
2410
2685
|
|
|
2411
|
-
//
|
|
2412
|
-
|
|
2686
|
+
// Persist edits made directly inside the project pane. The pane owns the
|
|
2687
|
+
// editor; the host only performs the mutation and updates the rendered node.
|
|
2688
|
+
function saveInlineFromPane(node) {
|
|
2413
2689
|
if (!node || (node.kind !== 'finding' && node.kind !== 'task')) return;
|
|
2414
|
-
var
|
|
2415
|
-
if (
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
if (
|
|
2423
|
-
|
|
2424
|
-
|
|
2690
|
+
var nextText = (node.editedText || '').trim();
|
|
2691
|
+
if (!nextText) return;
|
|
2692
|
+
if (node.kind === 'finding') {
|
|
2693
|
+
graphRequest('/api/findings/' + encodeURIComponent(node.projectName), 'PUT', {
|
|
2694
|
+
old_text: node.tooltipLabel || node.fullLabel || '',
|
|
2695
|
+
new_text: nextText,
|
|
2696
|
+
score_key: node.scoreKey || ''
|
|
2697
|
+
}).then(function(result) {
|
|
2698
|
+
if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Save failed');
|
|
2699
|
+
var api = graphApi();
|
|
2700
|
+
if (api && api.updateNode) api.updateNode(node.id, { text: nextText });
|
|
2701
|
+
graphToast('Finding updated', 'ok');
|
|
2702
|
+
}).catch(function(err) { graphToast('Update failed: ' + err.message, 'err'); });
|
|
2703
|
+
return;
|
|
2704
|
+
}
|
|
2705
|
+
graphRequest('/api/tasks/update', 'POST', {
|
|
2706
|
+
project: node.projectName,
|
|
2707
|
+
item: node.stableId || node.id || node.tooltipLabel || node.fullLabel || node.displayLabel || '',
|
|
2708
|
+
text: nextText,
|
|
2709
|
+
section: node.editedSection || node.section || 'Queue',
|
|
2710
|
+
priority: typeof node.editedPriority === 'string' ? node.editedPriority : (node.priority || '')
|
|
2711
|
+
}).then(function(result) {
|
|
2712
|
+
if (!result || !result.ok) throw new Error(result && result.error ? result.error : 'Save failed');
|
|
2713
|
+
var api = graphApi();
|
|
2714
|
+
if (api && api.updateNode) api.updateNode(node.id, {
|
|
2715
|
+
text: nextText,
|
|
2716
|
+
section: node.editedSection || node.section || 'Queue',
|
|
2717
|
+
priority: typeof node.editedPriority === 'string' ? node.editedPriority : (node.priority || '')
|
|
2718
|
+
});
|
|
2719
|
+
graphToast('Task updated', 'ok');
|
|
2720
|
+
}).catch(function(err) { graphToast('Update failed: ' + err.message, 'err'); });
|
|
2425
2721
|
}
|
|
2426
2722
|
|
|
2427
2723
|
function completeCurrentTask() {
|
|
@@ -2543,7 +2839,7 @@ export function renderGraphHostScript() {
|
|
|
2543
2839
|
api.onItemAction(function(payload, action) {
|
|
2544
2840
|
if (action === 'delete') deleteNode(payload);
|
|
2545
2841
|
else if (action === 'delete-batch') deleteNodes(payload);
|
|
2546
|
-
else if (action === '
|
|
2842
|
+
else if (action === 'save-inline') saveInlineFromPane(payload);
|
|
2547
2843
|
else if (action === 'merge') mergeNodes(payload);
|
|
2548
2844
|
});
|
|
2549
2845
|
}
|