claude-alfred 0.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.
Files changed (44) hide show
  1. package/README.ja.md +283 -0
  2. package/README.md +283 -0
  3. package/content/hooks/hooks.json +41 -0
  4. package/content/mcp/.mcp.json +12 -0
  5. package/dist/audit-DujZ6YAy.mjs +18 -0
  6. package/dist/cli.mjs +509 -0
  7. package/dist/dispatcher-BzOdcjaa.mjs +93 -0
  8. package/dist/embedder-BshPIMrW.mjs +215 -0
  9. package/dist/epic-CdRKNGvP.mjs +227 -0
  10. package/dist/fts-BDdUbNfM.mjs +195 -0
  11. package/dist/helpers-BsdW4kgn.mjs +94 -0
  12. package/dist/knowledge-CCCixwb8.mjs +156 -0
  13. package/dist/post-tool-qemgso2b.mjs +88 -0
  14. package/dist/postinstall.mjs +49 -0
  15. package/dist/pre-compact-Cmg9kprV.mjs +181 -0
  16. package/dist/project-CpgK3fwQ.mjs +79 -0
  17. package/dist/schema-CcIFwr_0.mjs +289 -0
  18. package/dist/server-DF7CXxKi.mjs +2635 -0
  19. package/dist/server-Dsf47Pd4.mjs +19220 -0
  20. package/dist/session-start-DUYF6E0V.mjs +209 -0
  21. package/dist/store-Clcihees.mjs +338 -0
  22. package/dist/types-C3butmI8.mjs +6823 -0
  23. package/dist/user-prompt-BDeST0mR.mjs +144 -0
  24. package/dist/vectors-DvuAqDeO.mjs +83 -0
  25. package/package.json +46 -0
  26. package/web/dist/assets/activity-UyW12k7Z.js +1 -0
  27. package/web/dist/assets/api-BI8AW-mC.js +1 -0
  28. package/web/dist/assets/dist-BHj_gZG8.js +1 -0
  29. package/web/dist/assets/dist-DDZSXOC-.js +1 -0
  30. package/web/dist/assets/index-B9C85vN2.js +10 -0
  31. package/web/dist/assets/index-bIyYMf1a.css +1 -0
  32. package/web/dist/assets/knowledge-DmvXTX67.js +5 -0
  33. package/web/dist/assets/link-BSgD_zxQ.js +1 -0
  34. package/web/dist/assets/matchContext-CO01nzZ3.js +1 -0
  35. package/web/dist/assets/progress-DBmt_Ww6.js +6 -0
  36. package/web/dist/assets/routes-zEN1XNFl.js +1 -0
  37. package/web/dist/assets/scroll-area-DPCDB42s.js +45 -0
  38. package/web/dist/assets/separator-5sy8HYz5.js +1 -0
  39. package/web/dist/assets/skeleton-D7GRd6oJ.js +1 -0
  40. package/web/dist/assets/tabs-VSkG1f0-.js +1 -0
  41. package/web/dist/assets/tasks-CKNc1U7M.js +1 -0
  42. package/web/dist/assets/tasks._slug-DPzi78wf.js +8 -0
  43. package/web/dist/assets/utils-Dw49HYRP.js +1 -0
  44. package/web/dist/index.html +17 -0
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+ import { Embedder } from "./embedder-BshPIMrW.mjs";
3
+ import { emitAdditionalContext } from "./dispatcher-BzOdcjaa.mjs";
4
+ import { openDefaultCached } from "./store-Clcihees.mjs";
5
+ import { n as trackHitCounts, r as truncate, t as searchPipeline } from "./helpers-BsdW4kgn.mjs";
6
+ //#region src/hooks/user-prompt.ts
7
+ const INTENT_KEYWORDS = {
8
+ research: [
9
+ "research",
10
+ "investigate",
11
+ "understand",
12
+ "explore",
13
+ "learn",
14
+ "pattern",
15
+ "調べ",
16
+ "調査",
17
+ "理解",
18
+ "質問"
19
+ ],
20
+ plan: [
21
+ "plan",
22
+ "design",
23
+ "architect",
24
+ "how to",
25
+ "approach",
26
+ "アーキテクチャ",
27
+ "設計",
28
+ "計画"
29
+ ],
30
+ implement: [
31
+ "implement",
32
+ "add",
33
+ "create",
34
+ "build",
35
+ "refactor",
36
+ "追加",
37
+ "実装",
38
+ "リファクタ"
39
+ ],
40
+ bugfix: [
41
+ "fix",
42
+ "bug",
43
+ "error",
44
+ "broken",
45
+ "failing",
46
+ "修正",
47
+ "バグ",
48
+ "エラー"
49
+ ],
50
+ review: [
51
+ "review",
52
+ "check",
53
+ "audit",
54
+ "inspect",
55
+ "レビュー",
56
+ "確認"
57
+ ],
58
+ tdd: [
59
+ "test",
60
+ "tdd",
61
+ "spec",
62
+ "テスト"
63
+ ],
64
+ "save-knowledge": [
65
+ "remember",
66
+ "save",
67
+ "note",
68
+ "record",
69
+ "覚え",
70
+ "保存",
71
+ "メモ"
72
+ ]
73
+ };
74
+ const INTENT_TO_SKILL = {
75
+ research: "/alfred:brief",
76
+ plan: "/alfred:attend",
77
+ implement: "/alfred:attend",
78
+ bugfix: "/alfred:mend",
79
+ review: "/alfred:inspect",
80
+ tdd: "/alfred:tdd"
81
+ };
82
+ async function userPromptSubmit(ev, signal) {
83
+ if (!ev.prompt || !ev.cwd) return;
84
+ const prompt = ev.prompt.trim();
85
+ if (!prompt) return;
86
+ let store;
87
+ try {
88
+ store = openDefaultCached();
89
+ } catch {
90
+ return;
91
+ }
92
+ let emb = null;
93
+ try {
94
+ emb = Embedder.create();
95
+ } catch {}
96
+ const limit = 5;
97
+ const result = await searchPipeline(store, emb, prompt, limit, limit * 3);
98
+ const parts = [];
99
+ const intent = classifyIntent(prompt);
100
+ if (intent && intent !== "save-knowledge") {
101
+ const skill = INTENT_TO_SKILL[intent];
102
+ if (skill) parts.push(`Skill suggestion: ${skill} — ${intentDescription(intent)}`);
103
+ }
104
+ if (result.docs.length > 0) {
105
+ trackHitCounts(store, result.docs);
106
+ const contextLines = result.docs.map((d) => {
107
+ return `- ${d.subType !== "general" ? `[${d.subType}] ` : ""}${d.title}: ${truncate(d.content, 150)}`;
108
+ });
109
+ parts.push("Related knowledge:\n" + contextLines.join("\n"));
110
+ }
111
+ if (parts.length > 0) emitAdditionalContext("UserPromptSubmit", parts.join("\n\n"));
112
+ }
113
+ function classifyIntent(prompt) {
114
+ const lower = prompt.toLowerCase();
115
+ let bestIntent = "";
116
+ let bestScore = 0;
117
+ for (const [intent, keywords] of Object.entries(INTENT_KEYWORDS)) {
118
+ let score = 0;
119
+ for (const kw of keywords) if (lower.includes(kw)) score++;
120
+ if (score > bestScore) {
121
+ bestScore = score;
122
+ bestIntent = intent;
123
+ }
124
+ }
125
+ if (bestIntent === "research") {
126
+ let saveScore = 0;
127
+ for (const kw of INTENT_KEYWORDS["save-knowledge"]) if (lower.includes(kw)) saveScore++;
128
+ if (saveScore > 0) return "save-knowledge";
129
+ }
130
+ return bestScore > 0 ? bestIntent : null;
131
+ }
132
+ function intentDescription(intent) {
133
+ switch (intent) {
134
+ case "research": return "調査・リサーチの構造化";
135
+ case "plan": return "仕様策定→承認→実装の自律フロー";
136
+ case "implement": return "仕様策定→承認→実装の自律フロー";
137
+ case "bugfix": return "再現→分析→修正→検証の自律バグ修正";
138
+ case "review": return "6プロファイル品質レビュー";
139
+ case "tdd": return "Red→Green→Refactor の自律TDD";
140
+ default: return "";
141
+ }
142
+ }
143
+ //#endregion
144
+ export { userPromptSubmit };
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ import { h as __exportAll } from "./types-C3butmI8.mjs";
3
+ //#region src/store/vectors.ts
4
+ var vectors_exports = /* @__PURE__ */ __exportAll({
5
+ cosineSimilarity: () => cosineSimilarity,
6
+ deserializeFloat32: () => deserializeFloat32,
7
+ insertEmbedding: () => insertEmbedding,
8
+ serializeFloat32: () => serializeFloat32,
9
+ vectorSearchKnowledge: () => vectorSearchKnowledge
10
+ });
11
+ const MIN_SIMILARITY = .3;
12
+ const DEFAULT_MAX_VECTOR_CANDIDATES = 1e4;
13
+ const EARLY_STOP_THRESHOLD = .7;
14
+ function envIntOrDefault(key, fallback) {
15
+ const v = process.env[key];
16
+ if (v) {
17
+ const n = parseInt(v, 10);
18
+ if (!isNaN(n) && n > 0) return n;
19
+ }
20
+ return fallback;
21
+ }
22
+ function insertEmbedding(store, source, sourceId, model, vector) {
23
+ if (store.expectedDims > 0 && vector.length !== store.expectedDims) throw new Error(`store: insert embedding: dimension mismatch: got ${vector.length}, expected ${store.expectedDims}`);
24
+ const blob = serializeFloat32(vector);
25
+ store.db.prepare(`
26
+ INSERT OR REPLACE INTO embeddings (source, source_id, model, dims, vector)
27
+ VALUES (?, ?, ?, ?, ?)
28
+ `).run(source, sourceId, model, vector.length, blob);
29
+ }
30
+ function vectorSearchKnowledge(store, queryVec, limit) {
31
+ if (!queryVec || queryVec.length === 0) return [];
32
+ if (limit <= 0) limit = 10;
33
+ const maxCandidates = envIntOrDefault("ALFRED_MAX_VECTOR_CANDIDATES", DEFAULT_MAX_VECTOR_CANDIDATES);
34
+ const earlyStopCount = Math.max(limit * 3, 50);
35
+ const rows = store.db.prepare(`
36
+ SELECT e.source_id, e.vector FROM embeddings e
37
+ JOIN knowledge_index k ON k.id = e.source_id
38
+ WHERE e.source = 'knowledge' AND k.enabled = 1
39
+ LIMIT ?
40
+ `).all(maxCandidates);
41
+ const candidates = [];
42
+ let highQualityCount = 0;
43
+ for (const row of rows) {
44
+ const vec = deserializeFloat32(row.vector);
45
+ if (vec.length !== queryVec.length) continue;
46
+ const sim = cosineSimilarity(queryVec, vec);
47
+ if (sim < MIN_SIMILARITY) continue;
48
+ candidates.push({
49
+ sourceId: row.source_id,
50
+ score: sim
51
+ });
52
+ if (sim >= EARLY_STOP_THRESHOLD) {
53
+ highQualityCount++;
54
+ if (highQualityCount >= earlyStopCount) break;
55
+ }
56
+ }
57
+ candidates.sort((a, b) => b.score - a.score);
58
+ return candidates.slice(0, limit);
59
+ }
60
+ function cosineSimilarity(a, b) {
61
+ if (a.length !== b.length || a.length === 0) return 0;
62
+ let dot = 0, normA = 0, normB = 0;
63
+ for (let i = 0; i < a.length; i++) {
64
+ dot += a[i] * b[i];
65
+ normA += a[i] * a[i];
66
+ normB += b[i] * b[i];
67
+ }
68
+ if (normA === 0 || normB === 0) return 0;
69
+ return dot / (Math.sqrt(normA) * Math.sqrt(normB));
70
+ }
71
+ function serializeFloat32(vec) {
72
+ const buf = Buffer.allocUnsafe(vec.length * 4);
73
+ for (let i = 0; i < vec.length; i++) buf.writeFloatLE(vec[i], i * 4);
74
+ return buf;
75
+ }
76
+ function deserializeFloat32(blob) {
77
+ const n = blob.length / 4;
78
+ const vec = new Array(n);
79
+ for (let i = 0; i < n; i++) vec[i] = blob.readFloatLE(i * 4);
80
+ return vec;
81
+ }
82
+ //#endregion
83
+ export { vectors_exports as i, deserializeFloat32 as n, vectorSearchKnowledge as r, cosineSimilarity as t };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "claude-alfred",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "alfred": "dist/cli.mjs"
7
+ },
8
+ "files": [
9
+ "dist/",
10
+ "web/dist/",
11
+ "templates/",
12
+ "content/"
13
+ ],
14
+ "engines": {
15
+ "node": ">=22"
16
+ },
17
+ "scripts": {
18
+ "build": "tsdown",
19
+ "build:web": "cd web && npm run build",
20
+ "dev": "tsx watch src/cli.ts",
21
+ "typecheck": "tsc --noEmit",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest",
24
+ "postinstall": "node dist/postinstall.mjs || true",
25
+ "prepack": "npm run build:web && npm run build"
26
+ },
27
+ "dependencies": {
28
+ "better-sqlite3": "^12"
29
+ },
30
+ "devDependencies": {
31
+ "@hono/node-server": "^1",
32
+ "@modelcontextprotocol/sdk": "^1.27",
33
+ "@tsconfig/node22": "^22.0.5",
34
+ "@types/better-sqlite3": "^7",
35
+ "@types/node": "^22",
36
+ "citty": "^0.2",
37
+ "eta": "^4",
38
+ "hono": "^4",
39
+ "tsdown": "^0",
40
+ "tsx": "^4",
41
+ "typescript": "^5.8",
42
+ "vitest": "^3",
43
+ "yaml": "^2",
44
+ "zod": "^3"
45
+ }
46
+ }
@@ -0,0 +1 @@
1
+ import{h as e,m as t,q as n,t as r}from"./utils-Dw49HYRP.js";import{S as i,_ as a,g as o,h as s,r as c,t as l,v as u,y as d}from"./api-BI8AW-mC.js";import{i as f,r as p,t as m}from"./tabs-VSkG1f0-.js";import{t as h}from"./progress-DBmt_Ww6.js";import{t as g}from"./skeleton-D7GRd6oJ.js";var _=t();function v({className:e,...t}){return(0,_.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,_.jsx)(`table`,{"data-slot":`table`,className:r(`w-full caption-bottom text-sm`,e),...t})})}function y({className:e,...t}){return(0,_.jsx)(`thead`,{"data-slot":`table-header`,className:r(`[&_tr]:border-b`,e),...t})}function b({className:e,...t}){return(0,_.jsx)(`tbody`,{"data-slot":`table-body`,className:r(`[&_tr:last-child]:border-0`,e),...t})}function x({className:e,...t}){return(0,_.jsx)(`tr`,{"data-slot":`table-row`,className:r(`border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function S({className:e,...t}){return(0,_.jsx)(`th`,{"data-slot":`table-head`,className:r(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function C({className:e,...t}){return(0,_.jsx)(`td`,{"data-slot":`table-cell`,className:r(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}var w=n(e()),T=[`all`,`spec.init`,`spec.complete`,`review.submit`];function E(){let[e,t]=(0,w.useState)(`all`),{data:n,isLoading:r}=i(l(100,e===`all`?void 0:e)),{data:a}=i(c()),o=n?.entries??[],s=(a?.epics??[]).filter(e=>e.status!==`completed`);return(0,_.jsxs)(`div`,{className:`space-y-6`,children:[(0,_.jsx)(m,{value:e,onValueChange:t,children:(0,_.jsx)(p,{children:T.map(e=>(0,_.jsx)(f,{value:e,className:`text-xs`,children:e===`all`?`All`:e},e))})}),r?(0,_.jsx)(`div`,{className:`space-y-2`,children:Array.from({length:5}).map((e,t)=>(0,_.jsx)(g,{className:`h-10 w-full`},`skel-${t}`))}):(0,_.jsx)(D,{entries:o}),s.length>0&&(0,_.jsx)(A,{epics:s})]})}function D({entries:e}){return(0,_.jsxs)(v,{children:[(0,_.jsx)(y,{children:(0,_.jsxs)(x,{children:[(0,_.jsx)(S,{className:`w-44`,children:`Timestamp`}),(0,_.jsx)(S,{className:`w-32`,children:`Action`}),(0,_.jsx)(S,{children:`Target`}),(0,_.jsx)(S,{children:`Detail`})]})}),(0,_.jsxs)(b,{children:[e.map((e,t)=>(0,_.jsxs)(x,{children:[(0,_.jsx)(C,{className:`text-xs text-muted-foreground font-mono`,children:j(e.timestamp)}),(0,_.jsx)(C,{children:(0,_.jsx)(k,{action:e.action})}),(0,_.jsx)(C,{className:`text-sm`,children:e.target}),(0,_.jsx)(C,{className:`text-xs text-muted-foreground max-w-xs truncate`,children:e.detail})]},`${e.timestamp}-${t}`)),e.length===0&&(0,_.jsx)(x,{children:(0,_.jsx)(C,{colSpan:4,className:`text-center text-sm text-muted-foreground`,children:`No activity found.`})})]})]})}var O={"spec.init":`#40513b`,"spec.complete":`#2d8b7a`,"spec.delete":`#c0392b`,"review.submit":`#628141`,"living-spec.update":`#7b6b8d`};function k({action:e}){let t=O[e]??`#6b7280`;return(0,_.jsx)(d,{variant:`outline`,className:`text-xs`,style:{borderColor:`${t}40`,color:t},children:e})}function A({epics:e}){return(0,_.jsxs)(`div`,{className:`space-y-3`,children:[(0,_.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Epics`}),(0,_.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:e.map(e=>{let t=e.total>0?e.completed/e.total*100:0;return(0,_.jsxs)(s,{children:[(0,_.jsx)(a,{className:`pb-2`,children:(0,_.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,_.jsx)(u,{className:`text-sm`,children:e.name}),(0,_.jsx)(d,{variant:`outline`,className:`text-xs`,children:e.status})]})}),(0,_.jsxs)(o,{className:`space-y-2`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(h,{value:t,className:`h-1.5 flex-1`}),(0,_.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.completed,`/`,e.total]})]}),e.tasks&&e.tasks.length>0&&(0,_.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.tasks.map(e=>(0,_.jsx)(d,{variant:`outline`,className:`text-[10px]`,style:{borderColor:e.status===`completed`?`rgba(45,139,122,0.3)`:`rgba(107,114,128,0.3)`,color:e.status===`completed`?`#2d8b7a`:`#6b7280`},children:e.slug},e.slug))})]})]},e.slug)})})]})}function j(e){try{return new Date(e).toLocaleString(`ja-JP`,{month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return e}}export{E as component};
@@ -0,0 +1 @@
1
+ import{B as e,C as t,F as n,G as r,L as i,M as a,R as o,S as s,U as c,V as l,W as u,_ as d,h as f,j as p,k as m,m as h,n as g,p as _,q as v,s as y,t as b,x,y as S,z as C}from"./utils-Dw49HYRP.js";var w=class extends r{constructor(e,t){super(),this.options=t,this.#e=e,this.#s=null,this.#o=s(),this.bindMethods(),this.setOptions(t)}#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),E(this.#t,this.options)?this.#h():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return D(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return D(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(t){let n=this.options,r=this.#t;if(this.options=this.#e.defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof o(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),n._defaulted&&!e(this.options,n)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let i=this.hasListeners();i&&O(this.#t,r,this.options,n)&&this.#h(),this.updateResult(),i&&(this.#t!==r||o(this.options.enabled,this.#t)!==o(n.enabled,this.#t)||C(this.options.staleTime,this.#t)!==C(n.staleTime,this.#t))&&this.#g();let a=this.#_();i&&(this.#t!==r||o(this.options.enabled,this.#t)!==o(n.enabled,this.#t)||a!==this.#p)&&this.#v(a)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return A(this,n)&&(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),n===`promise`&&(this.trackProp(`data`),!this.options.experimental_prefetchInRender&&this.#o.status===`pending`&&this.#o.reject(Error(`experimental_prefetchInRender feature flag is not enabled`))),Reflect.get(e,n))})}trackProp(e){this.#m.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t);return n.fetch().then(()=>this.createResult(n,t))}fetch(e){return this.#h({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#h(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(n)),t}#g(){this.#b();let e=C(this.options.staleTime,this.#t);if(p||this.#r.isStale||!a(e))return;let t=c(this.#r.dataUpdatedAt,e)+1;this.#d=u.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return(typeof this.options.refetchInterval==`function`?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(e){this.#x(),this.#p=e,!(p||o(this.options.enabled,this.#t)===!1||!a(this.#p)||this.#p===0)&&(this.#f=u.setInterval(()=>{(this.options.refetchIntervalInBackground||t.isFocused())&&this.#h()},this.#p))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#d&&=(u.clearTimeout(this.#d),void 0)}#x(){this.#f&&=(u.clearInterval(this.#f),void 0)}createResult(e,t){let n=this.#t,r=this.options,a=this.#r,c=this.#i,l=this.#a,u=e===n?this.#n:e.state,{state:d}=e,f={...d},p=!1,m;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&E(e,t),o=i&&O(e,n,t,r);(a||o)&&(f={...f,...S(d.data,e.options)}),t._optimisticResults===`isRestoring`&&(f.fetchStatus=`idle`)}let{error:h,errorUpdatedAt:g,status:_}=f;m=f.data;let v=!1;if(t.placeholderData!==void 0&&m===void 0&&_===`pending`){let e;a?.isPlaceholderData&&t.placeholderData===l?.placeholderData?(e=a.data,v=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#u?.state.data,this.#u):t.placeholderData,e!==void 0&&(_=`success`,m=i(a?.data,e,t),p=!0)}if(t.select&&m!==void 0&&!v)if(a&&m===c?.data&&t.select===this.#c)m=this.#l;else try{this.#c=t.select,m=t.select(m),m=i(a?.data,m,t),this.#l=m,this.#s=null}catch(e){this.#s=e}this.#s&&(h=this.#s,m=this.#l,g=Date.now(),_=`error`);let y=f.fetchStatus===`fetching`,b=_===`pending`,x=_===`error`,C=b&&y,w=m!==void 0,T={status:_,fetchStatus:f.fetchStatus,isPending:b,isSuccess:_===`success`,isError:x,isInitialLoading:C,isLoading:C,data:m,dataUpdatedAt:f.dataUpdatedAt,error:h,errorUpdatedAt:g,failureCount:f.fetchFailureCount,failureReason:f.fetchFailureReason,errorUpdateCount:f.errorUpdateCount,isFetched:f.dataUpdateCount>0||f.errorUpdateCount>0,isFetchedAfterMount:f.dataUpdateCount>u.dataUpdateCount||f.errorUpdateCount>u.errorUpdateCount,isFetching:y,isRefetching:y&&!b,isLoadingError:x&&!w,isPaused:f.fetchStatus===`paused`,isPlaceholderData:p,isRefetchError:x&&w,isStale:k(e,t),refetch:this.refetch,promise:this.#o,isEnabled:o(t.enabled,e)!==!1};if(this.options.experimental_prefetchInRender){let t=T.data!==void 0,r=T.status===`error`&&!t,i=e=>{r?e.reject(T.error):t&&e.resolve(T.data)},a=()=>{i(this.#o=T.promise=s())},o=this.#o;switch(o.status){case`pending`:e.queryHash===n.queryHash&&i(o);break;case`fulfilled`:(r||T.data!==o.value)&&a();break;case`rejected`:(!r||T.error!==o.reason)&&a();break}}return T}updateResult(){let t=this.#r,n=this.createResult(this.#t,this.options);this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#u=this.#t),!e(n,t)&&(this.#r=n,this.#C({listeners:(()=>{if(!t)return!0;let{notifyOnChangeProps:e}=this.options,n=typeof e==`function`?e():e;if(n===`all`||!n&&!this.#m.size)return!0;let r=new Set(n??this.#m);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(e=>{let n=e;return this.#r[n]!==t[n]&&r.has(n)})})()}))}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}#C(e){x.batch(()=>{e.listeners&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}};function T(e,t){return o(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status===`error`&&t.retryOnMount===!1)}function E(e,t){return T(e,t)||e.state.data!==void 0&&D(e,t,t.refetchOnMount)}function D(e,t,n){if(o(t.enabled,e)!==!1&&C(t.staleTime,e)!==`static`){let r=typeof n==`function`?n(e):n;return r===`always`||r!==!1&&k(e,t)}return!1}function O(e,t,n,r){return(e!==t||o(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&k(e,n)}function k(e,t){return o(t.enabled,e)!==!1&&e.isStaleByTime(C(t.staleTime,e))}function A(t,n){return!e(t.getCurrentResult(),n)}var j=class extends r{#e;#t=void 0;#n;#r;constructor(e,t){super(),this.#e=e,this.setOptions(t),this.bindMethods(),this.#i()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){let n=this.options;this.options=this.#e.defaultMutationOptions(t),e(this.options,n)||this.#e.getMutationCache().notify({type:`observerOptionsUpdated`,mutation:this.#n,observer:this}),n?.mutationKey&&this.options.mutationKey&&m(n.mutationKey)!==m(this.options.mutationKey)?this.reset():this.#n?.state.status===`pending`&&this.#n.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#n?.removeObserver(this)}onMutationUpdate(e){this.#i(),this.#a(e)}getCurrentResult(){return this.#t}reset(){this.#n?.removeObserver(this),this.#n=void 0,this.#i(),this.#a()}mutate(e,t){return this.#r=t,this.#n?.removeObserver(this),this.#n=this.#e.getMutationCache().build(this.#e,this.options),this.#n.addObserver(this),this.#n.execute(e)}#i(){let e=this.#n?.state??d();this.#t={...e,isPending:e.status===`pending`,isSuccess:e.status===`success`,isError:e.status===`error`,isIdle:e.status===`idle`,mutate:this.mutate,reset:this.reset}}#a(e){x.batch(()=>{if(this.#r&&this.hasListeners()){let t=this.#t.variables,n=this.#t.context,r={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type===`success`){try{this.#r.onSuccess?.(e.data,t,n,r)}catch(e){Promise.reject(e)}try{this.#r.onSettled?.(e.data,null,t,n,r)}catch(e){Promise.reject(e)}}else if(e?.type===`error`){try{this.#r.onError?.(e.error,t,n,r)}catch(e){Promise.reject(e)}try{this.#r.onSettled?.(void 0,e.error,t,n,r)}catch(e){Promise.reject(e)}}}this.listeners.forEach(e=>{e(this.#t)})})}},M=v(f(),1),N=M.createContext(!1),P=()=>M.useContext(N);N.Provider;var F=h();function I(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var L=M.createContext(I()),ee=()=>M.useContext(L),te=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?l(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||e.experimental_prefetchInRender||r)&&(t.isReset()||(e.retryOnMount=!1))},ne=e=>{M.useEffect(()=>{e.clearReset()},[e])},re=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||l(n,[e.error,r])),ie=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},ae=(e,t)=>e.isLoading&&e.isFetching&&!t,R=(e,t)=>e?.suspense&&t.isPending,z=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function B(e,t,r){let i=P(),a=ee(),o=_(r),s=o.defaultQueryOptions(e);o.getDefaultOptions().queries?._experimental_beforeQuery?.(s);let c=o.getQueryCache().get(s.queryHash);s._optimisticResults=i?`isRestoring`:`optimistic`,ie(s),te(s,a,c),ne(a);let l=!o.getQueryCache().get(s.queryHash),[u]=M.useState(()=>new t(o,s)),d=u.getOptimisticResult(s),f=!i&&e.subscribed!==!1;if(M.useSyncExternalStore(M.useCallback(e=>{let t=f?u.subscribe(x.batchCalls(e)):n;return u.updateResult(),t},[u,f]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),M.useEffect(()=>{u.setOptions(s)},[s,u]),R(s,d))throw z(s,u,a);if(re({result:d,errorResetBoundary:a,throwOnError:s.throwOnError,query:c,suspense:s.suspense}))throw d.error;return o.getDefaultOptions().queries?._experimental_afterQuery?.(s,d),s.experimental_prefetchInRender&&!p&&ae(d,i)&&(l?z(s,u,a):c?.promise)?.catch(n).finally(()=>{u.updateResult()}),s.notifyOnChangeProps?d:u.trackResult(d)}function V(e,t){return B(e,w,t)}function H(e){return e}function U(e,t){let r=_(t),[i]=M.useState(()=>new j(r,e));M.useEffect(()=>{i.setOptions(e)},[i,e]);let a=M.useSyncExternalStore(M.useCallback(e=>i.subscribe(x.batchCalls(e)),[i]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),o=M.useCallback((e,t)=>{i.mutate(e,t).catch(n)},[i]);if(a.error&&l(i.options.throwOnError,[a.error]))throw a.error;return{...a,mutate:o,mutateAsync:a.mutate}}var W=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,G=g,K=(e,t)=>n=>{if(t?.variants==null)return G(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=W(t)||W(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return G(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)},q=K(`inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function J({className:e,variant:t=`default`,asChild:n=!1,...r}){return(0,F.jsx)(n?y:`span`,{"data-slot":`badge`,"data-variant":t,className:b(q({variant:t}),e),...r})}function oe({className:e,...t}){return(0,F.jsx)(`div`,{"data-slot":`card`,className:b(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function se({className:e,...t}){return(0,F.jsx)(`div`,{"data-slot":`card-header`,className:b(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,e),...t})}function ce({className:e,...t}){return(0,F.jsx)(`div`,{"data-slot":`card-title`,className:b(`leading-none font-semibold`,e),...t})}function le({className:e,...t}){return(0,F.jsx)(`div`,{"data-slot":`card-content`,className:b(`px-6`,e),...t})}var Y=5e3,X=6e4;async function Z(e){let t=await fetch(e);if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error??`HTTP ${t.status}`)}return t.json()}function Q(e,...t){return[`/api/tasks`,encodeURIComponent(e),...t.map(encodeURIComponent)].join(`/`)}var ue=()=>H({queryKey:[`tasks`],queryFn:()=>Z(`/api/tasks`),staleTime:Y}),de=e=>H({queryKey:[`specs`,e],queryFn:()=>Z(Q(e,`specs`)),staleTime:X,enabled:!!e}),fe=(e,t)=>H({queryKey:[`spec-content`,e,t],queryFn:()=>Z(Q(e,`specs`,t)),staleTime:X,enabled:!!e&&!!t}),pe=(e=50)=>H({queryKey:[`knowledge`,e],queryFn:()=>Z(`/api/knowledge?limit=${e}`),staleTime:Y}),$=()=>H({queryKey:[`knowledge-stats`],queryFn:()=>Z(`/api/knowledge/stats`),staleTime:X}),me=(e,t=10)=>H({queryKey:[`knowledge-search`,e],queryFn:()=>Z(`/api/knowledge/search?q=${encodeURIComponent(e)}&limit=${t}`),staleTime:X,enabled:e.length>0}),he=(e=50,t)=>H({queryKey:[`activity`,e,t],queryFn:()=>{let n=new URLSearchParams({limit:String(e)});return t&&n.set(`filter`,t),Z(`/api/activity?${n}`)},staleTime:Y}),ge=()=>H({queryKey:[`epics`],queryFn:()=>Z(`/api/epics`),staleTime:Y}),_e=(e=20)=>H({queryKey:[`decisions`,e],queryFn:()=>Z(`/api/decisions?limit=${e}`),staleTime:Y}),ve=()=>H({queryKey:[`health`],queryFn:()=>Z(`/api/health`),staleTime:X}),ye=e=>H({queryKey:[`validation`,e],queryFn:()=>Z(Q(e,`validation`)),staleTime:X,enabled:!!e}),be=e=>H({queryKey:[`review-history`,e],queryFn:()=>Z(`${Q(e,`review`)}/history`),staleTime:X,enabled:!!e});async function xe(e,t,n){let r=await fetch(Q(e,`review`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({status:t,comments:n})});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error??`HTTP ${r.status}`)}return r.json()}function Se(){let e=_();return U({mutationFn:async({id:e,enabled:t})=>{if(!(await fetch(`/api/knowledge/${e}/enabled`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:t})})).ok)throw Error(`Failed to toggle enabled`)},onSuccess:()=>{e.invalidateQueries({queryKey:[`knowledge`]}),e.invalidateQueries({queryKey:[`health`]})}})}export{V as S,se as _,pe as a,K as b,be as c,xe as d,ue as f,le as g,oe as h,ve as i,fe as l,ye as m,_e as n,me as o,Se as p,ge as r,$ as s,he as t,de as u,ce as v,U as x,J as y};
@@ -0,0 +1 @@
1
+ import{h as e,q as t,u as n}from"./utils-Dw49HYRP.js";typeof window<`u`&&window.document&&window.document.createElement;function r(e,t,{checkForDefaultPrevented:n=!0}={}){return function(r){if(e?.(r),n===!1||!r.defaultPrevented)return t?.(r)}}var i=t(e(),1),a=globalThis?.document?i.useLayoutEffect:()=>{},o=i.useInsertionEffect||a;function s({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){let[a,o,s]=c({defaultProp:t,onChange:n}),u=e!==void 0,d=u?e:a;{let t=i.useRef(e!==void 0);i.useEffect(()=>{let e=t.current;if(e!==u){let t=e?`controlled`:`uncontrolled`,n=u?`controlled`:`uncontrolled`;console.warn(`${r} is changing from ${t} to ${n}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`)}t.current=u},[u,r])}return[d,i.useCallback(t=>{if(u){let n=l(t)?t(e):t;n!==e&&s.current?.(n)}else o(t)},[u,e,o,s])]}function c({defaultProp:e,onChange:t}){let[n,r]=i.useState(e),a=i.useRef(n),s=i.useRef(t);return o(()=>{s.current=t},[t]),i.useEffect(()=>{a.current!==n&&(s.current?.(n),a.current=n)},[n,a]),[n,r,s]}function l(e){return typeof e==`function`}function u(e,t){return i.useReducer((e,n)=>t[e][n]??e,e)}var d=e=>{let{present:t,children:r}=e,a=f(t),o=typeof r==`function`?r({present:a.isPresent}):i.Children.only(r),s=n(a.ref,m(o));return typeof r==`function`||a.isPresent?i.cloneElement(o,{ref:s}):null};d.displayName=`Presence`;function f(e){let[t,n]=i.useState(),r=i.useRef(null),o=i.useRef(e),s=i.useRef(`none`),[c,l]=u(e?`mounted`:`unmounted`,{mounted:{UNMOUNT:`unmounted`,ANIMATION_OUT:`unmountSuspended`},unmountSuspended:{MOUNT:`mounted`,ANIMATION_END:`unmounted`},unmounted:{MOUNT:`mounted`}});return i.useEffect(()=>{let e=p(r.current);s.current=c===`mounted`?e:`none`},[c]),a(()=>{let t=r.current,n=o.current;if(n!==e){let r=s.current,i=p(t);e?l(`MOUNT`):i===`none`||t?.display===`none`?l(`UNMOUNT`):l(n&&r!==i?`ANIMATION_OUT`:`UNMOUNT`),o.current=e}},[e,l]),a(()=>{if(t){let e,n=t.ownerDocument.defaultView??window,i=i=>{let a=p(r.current).includes(CSS.escape(i.animationName));if(i.target===t&&a&&(l(`ANIMATION_END`),!o.current)){let r=t.style.animationFillMode;t.style.animationFillMode=`forwards`,e=n.setTimeout(()=>{t.style.animationFillMode===`forwards`&&(t.style.animationFillMode=r)})}},a=e=>{e.target===t&&(s.current=p(r.current))};return t.addEventListener(`animationstart`,a),t.addEventListener(`animationcancel`,i),t.addEventListener(`animationend`,i),()=>{n.clearTimeout(e),t.removeEventListener(`animationstart`,a),t.removeEventListener(`animationcancel`,i),t.removeEventListener(`animationend`,i)}}else l(`ANIMATION_END`)},[t,l]),{isPresent:[`mounted`,`unmountSuspended`].includes(c),ref:i.useCallback(e=>{r.current=e?getComputedStyle(e):null,n(e)},[])}}function p(e){return e?.animationName||`none`}function m(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var h=i.useId||(()=>void 0),g=0;function _(e){let[t,n]=i.useState(h());return a(()=>{e||n(e=>e??String(g++))},[e]),e||(t?`radix-${t}`:``)}function v(e){let t=i.useRef(e);return i.useEffect(()=>{t.current=e}),i.useMemo(()=>(...e)=>t.current?.(...e),[])}export{a,s as i,_ as n,r as o,d as r,v as t};
@@ -0,0 +1 @@
1
+ import{h as e,m as t,q as n}from"./utils-Dw49HYRP.js";var r=n(e(),1);t();var i=r.createContext(void 0);function a(e){let t=r.useContext(i);return e||t||`ltr`}export{a as t};