@mastra/factory 0.26.0 → 0.27.0-alpha.1
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 +10 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +7 -3
- package/dist/factory.js.map +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/default-rules.d.ts +0 -1
- package/dist/integrations/incidentio/default-rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/default-rules.js +0 -2
- package/dist/integrations/incidentio/default-rules.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +2 -27
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/default-rules.d.ts +0 -1
- package/dist/integrations/jira/default-rules.d.ts.map +1 -1
- package/dist/integrations/jira/default-rules.js +0 -2
- package/dist/integrations/jira/default-rules.js.map +1 -1
- package/dist/integrations/jira/routes.d.ts +1 -1
- package/dist/integrations/jira/routes.d.ts.map +1 -1
- package/dist/integrations/jira/routes.js +6 -3
- package/dist/integrations/jira/routes.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +2 -22
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/default-rules.d.ts +0 -1
- package/dist/integrations/linear/default-rules.d.ts.map +1 -1
- package/dist/integrations/linear/default-rules.js +0 -2
- package/dist/integrations/linear/default-rules.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts +1 -1
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +13 -15
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +2 -23
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/jira/routes.d.ts +1 -1
- package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
- package/dist/integrations/platform/jira/routes.js +6 -3
- package/dist/integrations/platform/jira/routes.js.map +1 -1
- package/dist/routes/contracts.d.ts +54 -1
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +54 -1
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/knowledge.d.ts +12 -228
- package/dist/routes/knowledge.d.ts.map +1 -1
- package/dist/routes/knowledge.js +207 -1045
- package/dist/routes/knowledge.js.map +1 -1
- package/dist/routes/skills.d.ts +9 -0
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +145 -4
- package/dist/routes/skills.js.map +1 -1
- package/dist/routes/surface.d.ts +2 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +7 -5
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +24 -45
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +1 -0
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/types.d.ts +0 -7
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +0 -2
- package/dist/rules/validation.js.map +1 -1
- package/dist/session/org-seed.d.ts +1 -1
- package/dist/session/org-seed.js.map +1 -1
- package/dist/skills/catalog.d.ts +28 -3
- package/dist/skills/catalog.d.ts.map +1 -1
- package/dist/skills/catalog.js +51 -8
- package/dist/skills/catalog.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +1 -0
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +2 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/skill-overrides/base.d.ts +56 -0
- package/dist/storage/domains/skill-overrides/base.d.ts.map +1 -0
- package/dist/storage/domains/skill-overrides/base.js +157 -0
- package/dist/storage/domains/skill-overrides/base.js.map +1 -0
- package/dist/storage/domains/work-items/base.d.ts +0 -34
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +10 -139
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/workspace.d.ts +13 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +94 -17
- package/dist/workspace.js.map +1 -1
- package/package.json +9 -9
- package/dist/integrations/incidentio/claim.d.ts +0 -8
- package/dist/integrations/incidentio/claim.d.ts.map +0 -1
- package/dist/integrations/incidentio/claim.js +0 -13
- package/dist/integrations/incidentio/claim.js.map +0 -1
- package/dist/integrations/jira/claim.d.ts +0 -21
- package/dist/integrations/jira/claim.d.ts.map +0 -1
- package/dist/integrations/jira/claim.js +0 -37
- package/dist/integrations/jira/claim.js.map +0 -1
- package/dist/integrations/linear/claim.d.ts +0 -8
- package/dist/integrations/linear/claim.d.ts.map +0 -1
- package/dist/integrations/linear/claim.js +0 -13
- package/dist/integrations/linear/claim.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The tenant organization a session's knowledge is scoped to.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Knowledge writes scope every node and record on
|
|
5
5
|
* `factoryOrgId`. A session that reaches the curation seam without one used to
|
|
6
6
|
* fall back to the session owner id — for factory sessions the agent
|
|
7
7
|
* controller's own id — so the knowledge landed under an org rung no reader
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"org-seed.js","names":[],"sources":["../../src/session/org-seed.ts"],"sourcesContent":["/**\n * The tenant organization a session's knowledge is scoped to.\n *\n *
|
|
1
|
+
{"version":3,"file":"org-seed.js","names":[],"sources":["../../src/session/org-seed.ts"],"sourcesContent":["/**\n * The tenant organization a session's knowledge is scoped to.\n *\n * Knowledge writes scope every node and record on\n * `factoryOrgId`. A session that reaches the curation seam without one used to\n * fall back to the session owner id — for factory sessions the agent\n * controller's own id — so the knowledge landed under an org rung no reader\n * ever queries. The write succeeded and the read could never see it.\n *\n * The fix is that every session-creation path seeds the org it already holds,\n * and a path that cannot resolve one marks the session `factoryOrgUnresolved`\n * so the curation side refuses loudly instead of inventing an identity. \"No\n * project id\" is not a proxy for \"not a factory session\" — chat sessions and\n * Slack channel sessions are factory-owned and carry no project id — which is\n * why the unresolved case needs its own explicit marker.\n */\n\n/**\n * Session-state fields org seeding writes. The index signatures mirror\n * `MastraCodeState` so a concrete `Session.state.set(Partial<MastraCodeState>)`\n * stays assignable to this minimal surface (contravariant parameter check).\n */\nexport interface OrgSeedStateWrites {\n [key: string]: unknown;\n [key: `subagentModelId_${string}`]: string | undefined;\n factoryOrgId?: string;\n factoryOrgUnresolved?: boolean;\n}\n\n/** The slice of a session needed to seed its organization. */\nexport interface OrgSeedableSession {\n state: {\n get: () => Record<string, unknown> | undefined;\n set: (updates: OrgSeedStateWrites) => Promise<void> | void;\n };\n}\n\n/**\n * A request context carrying the tenant on its `user` key. Slack stamps\n * `{ id, organizationId }` and the GitHub webhook `{ workosId, organizationId }`,\n * so only the shared `organizationId` field may be read here.\n */\nexport interface OrgBearingRequestContext {\n get: (key: string) => unknown;\n}\n\n/** Read the tenant org off a request context's `user` key, if there is one. */\nexport function readRequestContextOrgId(requestContext: OrgBearingRequestContext | undefined): string | undefined {\n if (!requestContext) return undefined;\n const user = requestContext.get('user');\n if (!user || typeof user !== 'object') return undefined;\n const orgId = (user as { organizationId?: unknown }).organizationId;\n return typeof orgId === 'string' ? orgId : undefined;\n}\n\n/**\n * Whether a session state value counts as a resolved organization.\n *\n * The curation side trims before deciding (`sdk/src/knowledge-scope.ts`), so the\n * recovery guards have to agree with it: a whitespace-only value that reads as\n * truthy here would look resolved to a heal path while curation still refuses,\n * and nothing would ever repair it. Not every seam routes its seed through\n * `seedSessionOrg`, so this cannot be assumed away.\n */\nexport function hasResolvedOrg(orgId: unknown): boolean {\n return typeof orgId === 'string' && orgId.trim().length > 0;\n}\n\n/**\n * Seed the session's organization, or mark it unresolved when there is none.\n *\n * An absent, empty, or whitespace-only org is a refusal, not a fallback: a\n * blank org rung is not something canonicalization can save. A successful\n * resolve also clears a stale marker, because the session-start hook runs at\n * most once per session per process and nothing else would ever clear it.\n *\n * Best-effort by contract — every caller is a session-created listener that\n * must not sink a run that is otherwise ready.\n */\nexport async function seedSessionOrg(session: OrgSeedableSession, orgId: string | null | undefined): Promise<void> {\n const resolved = typeof orgId === 'string' ? orgId.trim() : '';\n // Some session shapes (approval stubs, lightweight doubles) carry no state at\n // all. There is nothing to seed and nothing to mark, so this is not a warning.\n if (typeof session.state?.get !== 'function' || typeof session.state?.set !== 'function') return;\n try {\n const state = session.state.get() ?? {};\n if (!resolved) {\n if (state.factoryOrgUnresolved !== true) {\n await session.state.set({ factoryOrgUnresolved: true });\n }\n return;\n }\n const updates: OrgSeedStateWrites = {};\n if (state.factoryOrgId !== resolved) updates.factoryOrgId = resolved;\n if (state.factoryOrgUnresolved) updates.factoryOrgUnresolved = false;\n if (Object.keys(updates).length > 0) await session.state.set(updates);\n } catch (error) {\n console.warn('[Factory org seed] Unable to record the session organization.', error);\n }\n}\n"],"mappings":";;AA+CA,SAAgB,wBAAwB,gBAA0E;CAChH,IAAI,CAAC,gBAAgB,OAAO,KAAA;CAC5B,MAAM,OAAO,eAAe,IAAI,MAAM;CACtC,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU,OAAO,KAAA;CAC9C,MAAM,QAAS,KAAsC;CACrD,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;;;;;;;;;;AAWA,SAAgB,eAAe,OAAyB;CACtD,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS;AAC5D;;;;;;;;;;;;AAaA,eAAsB,eAAe,SAA6B,OAAiD;CACjH,MAAM,WAAW,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;CAG5D,IAAI,OAAO,QAAQ,OAAO,QAAQ,cAAc,OAAO,QAAQ,OAAO,QAAQ,YAAY;CAC1F,IAAI;EACF,MAAM,QAAQ,QAAQ,MAAM,IAAI,KAAK,CAAC;EACtC,IAAI,CAAC,UAAU;GACb,IAAI,MAAM,yBAAyB,MACjC,MAAM,QAAQ,MAAM,IAAI,EAAE,sBAAsB,KAAK,CAAC;GAExD;EACF;EACA,MAAM,UAA8B,CAAC;EACrC,IAAI,MAAM,iBAAiB,UAAU,QAAQ,eAAe;EAC5D,IAAI,MAAM,sBAAsB,QAAQ,uBAAuB;EAC/D,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,GAAG,MAAM,QAAQ,MAAM,IAAI,OAAO;CACtE,SAAS,OAAO;EACd,QAAQ,KAAK,iEAAiE,KAAK;CACrF;AACF"}
|
package/dist/skills/catalog.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { InlineSkill } from '@mastra/core/skills';
|
|
2
|
+
import type { SkillOverrideRecord } from '../storage/domains/skill-overrides/base.js';
|
|
2
3
|
/** Where a skill comes from: shipped with Factory, the app's `factory-skills/` folder, or `MastraFactory({ skills })`. */
|
|
3
4
|
export type FactorySkillOrigin = 'bundled' | 'folder' | 'code';
|
|
4
5
|
export interface FactorySkillInfo {
|
|
@@ -6,15 +7,39 @@ export interface FactorySkillInfo {
|
|
|
6
7
|
description: string;
|
|
7
8
|
/** SKILL.md body with the frontmatter block removed. */
|
|
8
9
|
content: string;
|
|
10
|
+
/** Frontmatter fields besides `name` and `description` (license, user-invocable, …), so an editor can keep them. */
|
|
11
|
+
frontmatter?: Record<string, unknown>;
|
|
9
12
|
origin: FactorySkillOrigin;
|
|
10
13
|
/** True for the skills Factory ships, including when the app overrides one. */
|
|
11
14
|
builtIn: boolean;
|
|
12
15
|
/** Set when the SKILL.md fails the runtime's parsing/validation, so the agent will not be able to load it. */
|
|
13
16
|
error?: string;
|
|
17
|
+
/** Set when the project has an edited copy; `description` and `content` then come from the edit. */
|
|
18
|
+
edited?: {
|
|
19
|
+
updatedBy: string;
|
|
20
|
+
updatedAt: string;
|
|
21
|
+
};
|
|
22
|
+
/** True when the code, folder, or bundled SKILL.md changed since the project's edit was made. */
|
|
23
|
+
originalChanged?: boolean;
|
|
14
24
|
}
|
|
25
|
+
/** The SKILL.md a skill resolves to without any project edit, and where it came from. */
|
|
26
|
+
export interface FactorySkillOriginal {
|
|
27
|
+
raw: string;
|
|
28
|
+
origin: FactorySkillOrigin;
|
|
29
|
+
}
|
|
30
|
+
/** Fingerprint of an original SKILL.md, stored with an edit so the catalog can tell when the original moved on. */
|
|
31
|
+
export declare function hashSkillContent(raw: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Read the original SKILL.md of every skill the Factory skill mount serves,
|
|
34
|
+
* keyed by name. Code skills win over folder skills, which win over bundled
|
|
35
|
+
* skills of the same name.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readFactorySkillOriginals(codeSkills?: readonly InlineSkill[]): Promise<Map<string, FactorySkillOriginal>>;
|
|
15
38
|
/**
|
|
16
|
-
* List the skills the Factory skill mount serves, sorted by name.
|
|
17
|
-
*
|
|
39
|
+
* List the skills the Factory skill mount serves, sorted by name. With a
|
|
40
|
+
* project's `overrides`, edited skills show the edited text, who edited them,
|
|
41
|
+
* and whether the original changed since. Edits of skills that no longer
|
|
42
|
+
* exist are not listed, matching what sessions load.
|
|
18
43
|
*/
|
|
19
|
-
export declare function listFactorySkills(codeSkills?: readonly InlineSkill[]): Promise<FactorySkillInfo[]>;
|
|
44
|
+
export declare function listFactorySkills(codeSkills?: readonly InlineSkill[], overrides?: readonly SkillOverrideRecord[]): Promise<FactorySkillInfo[]>;
|
|
20
45
|
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/skills/catalog.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","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CAAC,CAoB7B"}
|
package/dist/skills/catalog.js
CHANGED
|
@@ -2,6 +2,7 @@ import { FACTORY_SKILLS_MOUNT, FACTORY_SKILL_NAMES, FactorySkillSource, resolveL
|
|
|
2
2
|
import { existsSync } from "fs";
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
import { validateSkillContent } from "@mastra/core/skills";
|
|
5
|
+
import { createHash } from "crypto";
|
|
5
6
|
// src/skills/catalog.ts
|
|
6
7
|
/**
|
|
7
8
|
* Read-only catalog of the Factory skills.
|
|
@@ -13,6 +14,10 @@ import { validateSkillContent } from "@mastra/core/skills";
|
|
|
13
14
|
* settings UI shows exactly what each skill instructs the agent to do — and
|
|
14
15
|
* whether the runtime can load it.
|
|
15
16
|
*/
|
|
17
|
+
/** Fingerprint of an original SKILL.md, stored with an edit so the catalog can tell when the original moved on. */
|
|
18
|
+
function hashSkillContent(raw) {
|
|
19
|
+
return createHash("sha256").update(raw).digest("hex");
|
|
20
|
+
}
|
|
16
21
|
function parseSkillMarkdown(name, raw) {
|
|
17
22
|
const result = validateSkillContent({
|
|
18
23
|
content: raw,
|
|
@@ -20,14 +25,18 @@ function parseSkillMarkdown(name, raw) {
|
|
|
20
25
|
});
|
|
21
26
|
const description = typeof result.metadata?.description === "string" ? result.metadata.description : "";
|
|
22
27
|
const content = result.instructions ?? stripFrontmatter(raw);
|
|
28
|
+
const extra = Object.entries(result.metadata ?? {}).filter(([key, value]) => key !== "name" && key !== "description" && value !== void 0);
|
|
29
|
+
const frontmatter = extra.length > 0 ? { frontmatter: Object.fromEntries(extra) } : {};
|
|
23
30
|
if (!result.valid) return {
|
|
24
31
|
description,
|
|
25
32
|
content,
|
|
33
|
+
...frontmatter,
|
|
26
34
|
error: result.errors.join("\n")
|
|
27
35
|
};
|
|
28
36
|
return {
|
|
29
37
|
description,
|
|
30
|
-
content
|
|
38
|
+
content,
|
|
39
|
+
...frontmatter
|
|
31
40
|
};
|
|
32
41
|
}
|
|
33
42
|
/** Best-effort body extraction when the frontmatter cannot be parsed, so users can still read the file they need to fix. */
|
|
@@ -46,15 +55,16 @@ const NO_REPOSITORY_SKILLS = {
|
|
|
46
55
|
readdir: async () => []
|
|
47
56
|
};
|
|
48
57
|
/**
|
|
49
|
-
*
|
|
50
|
-
* win over folder skills, which win over bundled
|
|
58
|
+
* Read the original SKILL.md of every skill the Factory skill mount serves,
|
|
59
|
+
* keyed by name. Code skills win over folder skills, which win over bundled
|
|
60
|
+
* skills of the same name.
|
|
51
61
|
*/
|
|
52
|
-
async function
|
|
62
|
+
async function readFactorySkillOriginals(codeSkills = []) {
|
|
53
63
|
const localRoot = resolveLocalFactorySkillsPath();
|
|
54
64
|
const source = new FactorySkillSource(NO_REPOSITORY_SKILLS, [], localRoot, async () => true, codeSkills);
|
|
55
65
|
const codeNames = new Set(codeSkills.map((skill) => skill.name));
|
|
56
66
|
const entries = (await source.readdir(FACTORY_SKILLS_MOUNT)).filter((entry) => entry.type === "directory");
|
|
57
|
-
const
|
|
67
|
+
const originals = /* @__PURE__ */ new Map();
|
|
58
68
|
for (const name of entries.map((entry) => entry.name).sort()) {
|
|
59
69
|
let raw;
|
|
60
70
|
try {
|
|
@@ -63,15 +73,48 @@ async function listFactorySkills(codeSkills = []) {
|
|
|
63
73
|
continue;
|
|
64
74
|
}
|
|
65
75
|
const origin = codeNames.has(name) ? "code" : localRoot && existsSync(join(localRoot, name, "SKILL.md")) ? "folder" : "bundled";
|
|
76
|
+
originals.set(name, {
|
|
77
|
+
raw,
|
|
78
|
+
origin
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return originals;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* List the skills the Factory skill mount serves, sorted by name. With a
|
|
85
|
+
* project's `overrides`, edited skills show the edited text, who edited them,
|
|
86
|
+
* and whether the original changed since. Edits of skills that no longer
|
|
87
|
+
* exist are not listed, matching what sessions load.
|
|
88
|
+
*/
|
|
89
|
+
async function listFactorySkills(codeSkills = [], overrides = []) {
|
|
90
|
+
const edits = new Map(overrides.map((override) => [override.skillName, override]));
|
|
91
|
+
const skills = [];
|
|
92
|
+
for (const [name, { raw, origin }] of await readFactorySkillOriginals(codeSkills)) {
|
|
93
|
+
const edit = edits.get(name);
|
|
94
|
+
const builtIn = FACTORY_SKILL_NAMES.has(name);
|
|
95
|
+
if (!edit) {
|
|
96
|
+
skills.push({
|
|
97
|
+
name,
|
|
98
|
+
...parseSkillMarkdown(name, raw),
|
|
99
|
+
origin,
|
|
100
|
+
builtIn
|
|
101
|
+
});
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
66
104
|
skills.push({
|
|
67
105
|
name,
|
|
68
|
-
...parseSkillMarkdown(name,
|
|
106
|
+
...parseSkillMarkdown(name, edit.content),
|
|
69
107
|
origin,
|
|
70
|
-
builtIn
|
|
108
|
+
builtIn,
|
|
109
|
+
edited: {
|
|
110
|
+
updatedBy: edit.updatedBy,
|
|
111
|
+
updatedAt: edit.updatedAt.toISOString()
|
|
112
|
+
},
|
|
113
|
+
originalChanged: hashSkillContent(raw) !== edit.baseHash
|
|
71
114
|
});
|
|
72
115
|
}
|
|
73
116
|
return skills;
|
|
74
117
|
}
|
|
75
|
-
export { listFactorySkills };
|
|
118
|
+
export { hashSkillContent, listFactorySkills, readFactorySkillOriginals };
|
|
76
119
|
|
|
77
120
|
//# sourceMappingURL=catalog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","names":[],"sources":["../../src/skills/catalog.ts"],"sourcesContent":["/**\n * Read-only catalog of the Factory skills.\n *\n * Lists every skill the Factory skill mount serves — the built-in skills the\n * pipeline invokes at each stage (triage, plan, review, …) and the app's own\n * skills from `MastraFactory({ skills })` or its `factory-skills/` folder. It\n * reads them through the same `FactorySkillSource` sessions use, so the\n * settings UI shows exactly what each skill instructs the agent to do — and\n * whether the runtime can load it.\n */\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport type { InlineSkill } from '@mastra/core/skills';\nimport { validateSkillContent } from '@mastra/core/skills';\nimport type { SkillSource } from '@mastra/core/workspace';\n\nimport {\n FACTORY_SKILL_NAMES,\n FACTORY_SKILLS_MOUNT,\n FactorySkillSource,\n resolveLocalFactorySkillsPath,\n} from '../workspace.js';\n\n/** Where a skill comes from: shipped with Factory, the app's `factory-skills/` folder, or `MastraFactory({ skills })`. */\nexport type FactorySkillOrigin = 'bundled' | 'folder' | 'code';\n\nexport interface FactorySkillInfo {\n name: string;\n description: string;\n /** SKILL.md body with the frontmatter block removed. */\n content: string;\n origin: FactorySkillOrigin;\n /** True for the skills Factory ships, including when the app overrides one. */\n builtIn: boolean;\n /** Set when the SKILL.md fails the runtime's parsing/validation, so the agent will not be able to load it. */\n error?: string;\n}\n\nfunction parseSkillMarkdown(name: string
|
|
1
|
+
{"version":3,"file":"catalog.js","names":[],"sources":["../../src/skills/catalog.ts"],"sourcesContent":["/**\n * Read-only catalog of the Factory skills.\n *\n * Lists every skill the Factory skill mount serves — the built-in skills the\n * pipeline invokes at each stage (triage, plan, review, …) and the app's own\n * skills from `MastraFactory({ skills })` or its `factory-skills/` folder. It\n * reads them through the same `FactorySkillSource` sessions use, so the\n * settings UI shows exactly what each skill instructs the agent to do — and\n * whether the runtime can load it.\n */\nimport { createHash } from 'node:crypto';\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport type { InlineSkill } from '@mastra/core/skills';\nimport { validateSkillContent } from '@mastra/core/skills';\nimport type { SkillSource } from '@mastra/core/workspace';\n\nimport type { SkillOverrideRecord } from '../storage/domains/skill-overrides/base.js';\nimport {\n FACTORY_SKILL_NAMES,\n FACTORY_SKILLS_MOUNT,\n FactorySkillSource,\n resolveLocalFactorySkillsPath,\n} from '../workspace.js';\n\n/** Where a skill comes from: shipped with Factory, the app's `factory-skills/` folder, or `MastraFactory({ skills })`. */\nexport type FactorySkillOrigin = 'bundled' | 'folder' | 'code';\n\nexport interface FactorySkillInfo {\n name: string;\n description: string;\n /** SKILL.md body with the frontmatter block removed. */\n content: string;\n /** Frontmatter fields besides `name` and `description` (license, user-invocable, …), so an editor can keep them. */\n frontmatter?: Record<string, unknown>;\n origin: FactorySkillOrigin;\n /** True for the skills Factory ships, including when the app overrides one. */\n builtIn: boolean;\n /** Set when the SKILL.md fails the runtime's parsing/validation, so the agent will not be able to load it. */\n error?: string;\n /** Set when the project has an edited copy; `description` and `content` then come from the edit. */\n edited?: { updatedBy: string; updatedAt: string };\n /** True when the code, folder, or bundled SKILL.md changed since the project's edit was made. */\n originalChanged?: boolean;\n}\n\n/** The SKILL.md a skill resolves to without any project edit, and where it came from. */\nexport interface FactorySkillOriginal {\n raw: string;\n origin: FactorySkillOrigin;\n}\n\n/** Fingerprint of an original SKILL.md, stored with an edit so the catalog can tell when the original moved on. */\nexport function hashSkillContent(raw: string): string {\n return createHash('sha256').update(raw).digest('hex');\n}\n\nfunction parseSkillMarkdown(\n name: string,\n raw: string,\n): Pick<FactorySkillInfo, 'description' | 'content' | 'frontmatter' | 'error'> {\n // Use the same parser and validation the runtime applies when loading skills,\n // so the catalog never shows a skill as healthy that the agent will drop.\n const result = validateSkillContent({ content: raw, directoryName: name });\n const description = typeof result.metadata?.description === 'string' ? result.metadata.description : '';\n const content = result.instructions ?? stripFrontmatter(raw);\n const extra = Object.entries(result.metadata ?? {}).filter(\n ([key, value]) => key !== 'name' && key !== 'description' && value !== undefined,\n );\n const frontmatter = extra.length > 0 ? { frontmatter: Object.fromEntries(extra) } : {};\n if (!result.valid) return { description, content, ...frontmatter, error: result.errors.join('\\n') };\n return { description, content, ...frontmatter };\n}\n\n/** Best-effort body extraction when the frontmatter cannot be parsed, so users can still read the file they need to fix. */\nfunction stripFrontmatter(raw: string): string {\n const match = raw.match(/^---\\r?\\n[\\s\\S]*?\\r?\\n---\\r?\\n?/);\n return (match ? raw.slice(match[0].length) : raw).trim();\n}\n\nconst NO_REPOSITORY_SKILLS: SkillSource = {\n exists: async () => false,\n stat: async path => {\n throw new Error(`ENOENT: no such file or directory, '${path}'`);\n },\n readFile: async path => {\n throw new Error(`ENOENT: no such file or directory, '${path}'`);\n },\n readdir: async () => [],\n};\n\n/**\n * Read the original SKILL.md of every skill the Factory skill mount serves,\n * keyed by name. Code skills win over folder skills, which win over bundled\n * skills of the same name.\n */\nexport async function readFactorySkillOriginals(\n codeSkills: readonly InlineSkill[] = [],\n): Promise<Map<string, FactorySkillOriginal>> {\n const localRoot = resolveLocalFactorySkillsPath();\n const source = new FactorySkillSource(NO_REPOSITORY_SKILLS, [], localRoot, async () => true, codeSkills);\n const codeNames = new Set(codeSkills.map(skill => skill.name));\n const entries = (await source.readdir(FACTORY_SKILLS_MOUNT)).filter(entry => entry.type === 'directory');\n const originals = new Map<string, FactorySkillOriginal>();\n for (const name of entries.map(entry => entry.name).sort()) {\n let raw: string;\n try {\n raw = String(await source.readFile(join(FACTORY_SKILLS_MOUNT, name, 'SKILL.md')));\n } catch {\n continue;\n }\n const origin: FactorySkillOrigin = codeNames.has(name)\n ? 'code'\n : localRoot && existsSync(join(localRoot, name, 'SKILL.md'))\n ? 'folder'\n : 'bundled';\n originals.set(name, { raw, origin });\n }\n return originals;\n}\n\n/**\n * List the skills the Factory skill mount serves, sorted by name. With a\n * project's `overrides`, edited skills show the edited text, who edited them,\n * and whether the original changed since. Edits of skills that no longer\n * exist are not listed, matching what sessions load.\n */\nexport async function listFactorySkills(\n codeSkills: readonly InlineSkill[] = [],\n overrides: readonly SkillOverrideRecord[] = [],\n): Promise<FactorySkillInfo[]> {\n const edits = new Map(overrides.map(override => [override.skillName, override]));\n const skills: FactorySkillInfo[] = [];\n for (const [name, { raw, origin }] of await readFactorySkillOriginals(codeSkills)) {\n const edit = edits.get(name);\n const builtIn = FACTORY_SKILL_NAMES.has(name);\n if (!edit) {\n skills.push({ name, ...parseSkillMarkdown(name, raw), origin, builtIn });\n continue;\n }\n skills.push({\n name,\n ...parseSkillMarkdown(name, edit.content),\n origin,\n builtIn,\n edited: { updatedBy: edit.updatedBy, updatedAt: edit.updat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iBAAiB,iBAAiB,GAAG,MAAM,KAAK;EAClD,CAAC;CACH;CACA,OAAO;AACT"}
|
|
@@ -10,6 +10,7 @@ export declare const AUDIT_ACTIONS: {
|
|
|
10
10
|
readonly intake: readonly ['config_updated', 'binding_updated', 'label_route_updated'];
|
|
11
11
|
readonly session: readonly ['owner_transferred'];
|
|
12
12
|
readonly board: readonly ['created', 'updated', 'deleted'];
|
|
13
|
+
readonly skill: readonly ['updated', 'reverted'];
|
|
13
14
|
};
|
|
14
15
|
export type AuditNamespace = keyof typeof AUDIT_ACTIONS;
|
|
15
16
|
export type AuditAction = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/audit/actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,aAAa;aACxB,SAAS,YACP,SAAS,EACT,SAAS,EACT,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB;aAErB,GAAG,YAAG,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU;aAChF,GAAG,YAAG,QAAQ,EAAE,MAAM,EAAE,WAAW;aACnC,KAAK,YAAG,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU;aACjD,MAAM,YAAG,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB;aACnE,OAAO,YAAG,mBAAmB;aAC7B,KAAK,YAAG,SAAS,EAAE,SAAS,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/audit/actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,aAAa;aACxB,SAAS,YACP,SAAS,EACT,SAAS,EACT,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB;aAErB,GAAG,YAAG,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU;aAChF,GAAG,YAAG,QAAQ,EAAE,MAAM,EAAE,WAAW;aACnC,KAAK,YAAG,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU;aACjD,MAAM,YAAG,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB;aACnE,OAAO,YAAG,mBAAmB;aAC7B,KAAK,YAAG,SAAS,EAAE,SAAS,EAAE,SAAS;aACvC,KAAK,YAAG,SAAS,EAAE,UAAU;CACrB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,aAAa,CAAC;AAExD,MAAM,MAAM,WAAW,GAAG;KACvB,SAAS,IAAI,cAAc,GAAG,WAAW,SAAS,IAAI,CAAC,OAAO,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAAE;CACnG,CAAC,cAAc,CAAC,CAAC;AAElB,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,cAAc,CAEvE;AAED,wBAAgB,eAAe,IAAI,cAAc,EAAE,CAElD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAIxG;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,WAAW,CAGjE;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,EAAE,CAExF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","names":[],"sources":["../../../../src/storage/domains/audit/actions.ts"],"sourcesContent":["/**\n * Every action the trail can hold, by namespace. Register new ones in the\n * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.\n */\nexport const AUDIT_ACTIONS = {\n work_item: [\n 'created',\n 'updated',\n 'deleted',\n 'stage_moved',\n 'transition_rejected',\n 'comment_created',\n 'comment_edited',\n 'comment_deleted',\n 'comment_mentioned',\n 'labels_reconciled',\n ],\n run: ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'],\n git: ['commit', 'push', 'pr_opened'],\n agent: ['commit', 'push', 'pr_opened', 'signaled'],\n intake: ['config_updated', 'binding_updated', 'label_route_updated'],\n session: ['owner_transferred'],\n board: ['created', 'updated', 'deleted'],\n} as const;\n\nexport type AuditNamespace = keyof typeof AUDIT_ACTIONS;\n\nexport type AuditAction = {\n [Namespace in AuditNamespace]: `factory.${Namespace}.${(typeof AUDIT_ACTIONS)[Namespace][number]}`;\n}[AuditNamespace];\n\nexport function isAuditNamespace(value: string): value is AuditNamespace {\n return Object.hasOwn(AUDIT_ACTIONS, value);\n}\n\nexport function auditNamespaces(): AuditNamespace[] {\n return Object.keys(AUDIT_ACTIONS).filter(isAuditNamespace);\n}\n\nexport function parseAuditAction(action: string): { namespace: AuditNamespace; leaf: string } | undefined {\n const [prefix, namespace, leaf, ...rest] = action.split('.');\n if (prefix !== 'factory' || namespace === undefined || leaf === undefined || rest.length > 0) return undefined;\n return isAuditNamespace(namespace) ? { namespace, leaf } : undefined;\n}\n\nexport function isAuditAction(value: string): value is AuditAction {\n const parsed = parseAuditAction(value);\n return parsed !== undefined && AUDIT_ACTIONS[parsed.namespace].some(leaf => leaf === parsed.leaf);\n}\n\nexport function auditActionsInNamespaces(namespaces: readonly AuditNamespace[]): string[] {\n return namespaces.flatMap(namespace => AUDIT_ACTIONS[namespace].map(leaf => `factory.${namespace}.${leaf}`));\n}\n"],"mappings":";;;;;AAIA,MAAa,gBAAgB;CAC3B,WAAW;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,KAAK;EAAC;EAAW;EAAS;EAAY;EAAa;EAAS;EAAU;CAAU;CAChF,KAAK;EAAC;EAAU;EAAQ;CAAW;CACnC,OAAO;EAAC;EAAU;EAAQ;EAAa;CAAU;CACjD,QAAQ;EAAC;EAAkB;EAAmB;CAAqB;CACnE,SAAS,CAAC,mBAAmB;CAC7B,OAAO;EAAC;EAAW;EAAW;CAAS;
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../../../../src/storage/domains/audit/actions.ts"],"sourcesContent":["/**\n * Every action the trail can hold, by namespace. Register new ones in the\n * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.\n */\nexport const AUDIT_ACTIONS = {\n work_item: [\n 'created',\n 'updated',\n 'deleted',\n 'stage_moved',\n 'transition_rejected',\n 'comment_created',\n 'comment_edited',\n 'comment_deleted',\n 'comment_mentioned',\n 'labels_reconciled',\n ],\n run: ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'],\n git: ['commit', 'push', 'pr_opened'],\n agent: ['commit', 'push', 'pr_opened', 'signaled'],\n intake: ['config_updated', 'binding_updated', 'label_route_updated'],\n session: ['owner_transferred'],\n board: ['created', 'updated', 'deleted'],\n skill: ['updated', 'reverted'],\n} as const;\n\nexport type AuditNamespace = keyof typeof AUDIT_ACTIONS;\n\nexport type AuditAction = {\n [Namespace in AuditNamespace]: `factory.${Namespace}.${(typeof AUDIT_ACTIONS)[Namespace][number]}`;\n}[AuditNamespace];\n\nexport function isAuditNamespace(value: string): value is AuditNamespace {\n return Object.hasOwn(AUDIT_ACTIONS, value);\n}\n\nexport function auditNamespaces(): AuditNamespace[] {\n return Object.keys(AUDIT_ACTIONS).filter(isAuditNamespace);\n}\n\nexport function parseAuditAction(action: string): { namespace: AuditNamespace; leaf: string } | undefined {\n const [prefix, namespace, leaf, ...rest] = action.split('.');\n if (prefix !== 'factory' || namespace === undefined || leaf === undefined || rest.length > 0) return undefined;\n return isAuditNamespace(namespace) ? { namespace, leaf } : undefined;\n}\n\nexport function isAuditAction(value: string): value is AuditAction {\n const parsed = parseAuditAction(value);\n return parsed !== undefined && AUDIT_ACTIONS[parsed.namespace].some(leaf => leaf === parsed.leaf);\n}\n\nexport function auditActionsInNamespaces(namespaces: readonly AuditNamespace[]): string[] {\n return namespaces.flatMap(namespace => AUDIT_ACTIONS[namespace].map(leaf => `factory.${namespace}.${leaf}`));\n}\n"],"mappings":";;;;;AAIA,MAAa,gBAAgB;CAC3B,WAAW;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,KAAK;EAAC;EAAW;EAAS;EAAY;EAAa;EAAS;EAAU;CAAU;CAChF,KAAK;EAAC;EAAU;EAAQ;CAAW;CACnC,OAAO;EAAC;EAAU;EAAQ;EAAa;CAAU;CACjD,QAAQ;EAAC;EAAkB;EAAmB;CAAqB;CACnE,SAAS,CAAC,mBAAmB;CAC7B,OAAO;EAAC;EAAW;EAAW;CAAS;CACvC,OAAO,CAAC,WAAW,UAAU;AAC/B;AAQA,SAAgB,iBAAiB,OAAwC;CACvE,OAAO,OAAO,OAAO,eAAe,KAAK;AAC3C;AAEA,SAAgB,kBAAoC;CAClD,OAAO,OAAO,KAAK,aAAa,CAAC,CAAC,OAAO,gBAAgB;AAC3D;AAEA,SAAgB,iBAAiB,QAAyE;CACxG,MAAM,CAAC,QAAQ,WAAW,MAAM,GAAG,QAAQ,OAAO,MAAM,GAAG;CAC3D,IAAI,WAAW,aAAa,cAAc,KAAA,KAAa,SAAS,KAAA,KAAa,KAAK,SAAS,GAAG,OAAO,KAAA;CACrG,OAAO,iBAAiB,SAAS,IAAI;EAAE;EAAW;CAAK,IAAI,KAAA;AAC7D;AAEA,SAAgB,cAAc,OAAqC;CACjE,MAAM,SAAS,iBAAiB,KAAK;CACrC,OAAO,WAAW,KAAA,KAAa,cAAc,OAAO,UAAU,CAAC,MAAK,SAAQ,SAAS,OAAO,IAAI;AAClG;AAEA,SAAgB,yBAAyB,YAAiD;CACxF,OAAO,WAAW,SAAQ,cAAa,cAAc,UAAU,CAAC,KAAI,SAAQ,WAAW,UAAU,GAAG,MAAM,CAAC;AAC7G"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { FactoryStorageDomain } from '@mastra/core/storage';
|
|
2
|
+
import type { CollectionSchema } from '@mastra/core/storage';
|
|
3
|
+
/** A project's edited copy of one Factory skill's SKILL.md. */
|
|
4
|
+
export interface SkillOverrideRecord {
|
|
5
|
+
orgId: string;
|
|
6
|
+
projectId: string;
|
|
7
|
+
skillName: string;
|
|
8
|
+
/** The full edited SKILL.md, frontmatter included. */
|
|
9
|
+
content: string;
|
|
10
|
+
/** sha256 of the original SKILL.md the edit was made against. */
|
|
11
|
+
baseHash: string;
|
|
12
|
+
updatedBy: string;
|
|
13
|
+
updatedAt: Date;
|
|
14
|
+
}
|
|
15
|
+
/** Every override of one project, read at one revision. */
|
|
16
|
+
export interface SkillOverrideSnapshot {
|
|
17
|
+
revision: number;
|
|
18
|
+
overrides: SkillOverrideRecord[];
|
|
19
|
+
}
|
|
20
|
+
interface ProjectScope {
|
|
21
|
+
orgId: string;
|
|
22
|
+
projectId: string;
|
|
23
|
+
}
|
|
24
|
+
interface SkillScope extends ProjectScope {
|
|
25
|
+
skillName: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const SKILL_OVERRIDES_SCHEMA: CollectionSchema;
|
|
28
|
+
/**
|
|
29
|
+
* One row per project whose `revision` is incremented in the same transaction as every save and
|
|
30
|
+
* revert, so skill sources can tell an unchanged override set from one indexed row read.
|
|
31
|
+
*/
|
|
32
|
+
export declare const SKILL_OVERRIDE_REVISIONS_SCHEMA: CollectionSchema;
|
|
33
|
+
export declare class SkillOverridesStorage extends FactoryStorageDomain {
|
|
34
|
+
#private;
|
|
35
|
+
constructor();
|
|
36
|
+
init(): Promise<void>;
|
|
37
|
+
dangerouslyClearAll(): Promise<void>;
|
|
38
|
+
/** 0 until the project's first save. */
|
|
39
|
+
revision(scope: ProjectScope): Promise<number>;
|
|
40
|
+
list(scope: ProjectScope): Promise<SkillOverrideRecord[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Reads the revision before the rows, so a write landing in between pairs newer rows with an
|
|
43
|
+
* older revision: the caller re-reads at the next check instead of caching stale rows as current.
|
|
44
|
+
*/
|
|
45
|
+
snapshot(scope: ProjectScope): Promise<SkillOverrideSnapshot>;
|
|
46
|
+
get({ skillName, ...scope }: SkillScope): Promise<SkillOverrideRecord | null>;
|
|
47
|
+
upsert({ content, baseHash, updatedBy, skillName, ...scope }: SkillScope & {
|
|
48
|
+
content: string;
|
|
49
|
+
baseHash: string;
|
|
50
|
+
updatedBy: string;
|
|
51
|
+
}): Promise<SkillOverrideRecord>;
|
|
52
|
+
/** False when the skill had no override; the revision only moves when a row was removed. */
|
|
53
|
+
delete({ skillName, ...scope }: SkillScope): Promise<boolean>;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/skill-overrides/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF,+DAA+D;AAC/D,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,2DAA2D;AAC3D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,mBAAmB,EAAE,CAAC;CAClC;AAED,UAAU,YAAY;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,S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ES_SCHEMA = {
|
|
4
|
+
name: "factory_skill_overrides",
|
|
5
|
+
columns: {
|
|
6
|
+
id: { type: "uuid-pk" },
|
|
7
|
+
org_id: { type: "text" },
|
|
8
|
+
factory_project_id: { type: "text" },
|
|
9
|
+
skill_name: { type: "text" },
|
|
10
|
+
content: { type: "text" },
|
|
11
|
+
base_hash: { type: "text" },
|
|
12
|
+
updated_by: { type: "text" },
|
|
13
|
+
updated_at: { type: "timestamp" }
|
|
14
|
+
},
|
|
15
|
+
uniqueIndexes: [{
|
|
16
|
+
name: "factory_skill_overrides_scope_key",
|
|
17
|
+
columns: [
|
|
18
|
+
"org_id",
|
|
19
|
+
"factory_project_id",
|
|
20
|
+
"skill_name"
|
|
21
|
+
]
|
|
22
|
+
}]
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* One row per project whose `revision` is incremented in the same transaction as every save and
|
|
26
|
+
* revert, so skill sources can tell an unchanged override set from one indexed row read.
|
|
27
|
+
*/
|
|
28
|
+
const SKILL_OVERRIDE_REVISIONS_SCHEMA = {
|
|
29
|
+
name: "factory_skill_override_revisions",
|
|
30
|
+
columns: {
|
|
31
|
+
id: { type: "uuid-pk" },
|
|
32
|
+
org_id: { type: "text" },
|
|
33
|
+
factory_project_id: { type: "text" },
|
|
34
|
+
revision: {
|
|
35
|
+
type: "integer",
|
|
36
|
+
default: 0
|
|
37
|
+
},
|
|
38
|
+
updated_at: { type: "timestamp" }
|
|
39
|
+
},
|
|
40
|
+
uniqueIndexes: [{
|
|
41
|
+
name: "factory_skill_override_revisions_scope_key",
|
|
42
|
+
columns: ["org_id", "factory_project_id"]
|
|
43
|
+
}]
|
|
44
|
+
};
|
|
45
|
+
function toRecord(row) {
|
|
46
|
+
return {
|
|
47
|
+
orgId: row.org_id,
|
|
48
|
+
projectId: row.factory_project_id,
|
|
49
|
+
skillName: row.skill_name,
|
|
50
|
+
content: row.content,
|
|
51
|
+
baseHash: row.base_hash,
|
|
52
|
+
updatedBy: row.updated_by,
|
|
53
|
+
updatedAt: row.updated_at
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const projectWhere = ({ orgId, projectId }) => ({
|
|
57
|
+
org_id: orgId,
|
|
58
|
+
factory_project_id: projectId
|
|
59
|
+
});
|
|
60
|
+
var SkillOverridesStorage = class extends FactoryStorageDomain {
|
|
61
|
+
constructor() {
|
|
62
|
+
super("skill-overrides");
|
|
63
|
+
}
|
|
64
|
+
async init() {
|
|
65
|
+
await this.ensureCollections([SKILL_OVERRIDES_SCHEMA, SKILL_OVERRIDE_REVISIONS_SCHEMA]);
|
|
66
|
+
}
|
|
67
|
+
async dangerouslyClearAll() {
|
|
68
|
+
await this.ops.deleteMany("factory_skill_overrides", {});
|
|
69
|
+
await this.ops.deleteMany("factory_skill_override_revisions", {});
|
|
70
|
+
}
|
|
71
|
+
get #db() {
|
|
72
|
+
return this.ops;
|
|
73
|
+
}
|
|
74
|
+
/** 0 until the project's first save. */
|
|
75
|
+
async revision(scope) {
|
|
76
|
+
return (await this.#db.findOne("factory_skill_override_revisions", projectWhere(scope)))?.revision ?? 0;
|
|
77
|
+
}
|
|
78
|
+
async list(scope) {
|
|
79
|
+
return (await this.#db.findMany("factory_skill_overrides", projectWhere(scope), { orderBy: [["skill_name", "asc"]] })).map(toRecord);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reads the revision before the rows, so a write landing in between pairs newer rows with an
|
|
83
|
+
* older revision: the caller re-reads at the next check instead of caching stale rows as current.
|
|
84
|
+
*/
|
|
85
|
+
async snapshot(scope) {
|
|
86
|
+
return {
|
|
87
|
+
revision: await this.revision(scope),
|
|
88
|
+
overrides: await this.list(scope)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async get({ skillName, ...scope }) {
|
|
92
|
+
const row = await this.#db.findOne("factory_skill_overrides", {
|
|
93
|
+
...projectWhere(scope),
|
|
94
|
+
skill_name: skillName
|
|
95
|
+
});
|
|
96
|
+
return row ? toRecord(row) : null;
|
|
97
|
+
}
|
|
98
|
+
async upsert({ content, baseHash, updatedBy, skillName, ...scope }) {
|
|
99
|
+
await this.#ensureRevisionRow(scope);
|
|
100
|
+
return this.storage.withTransaction(async (ops) => {
|
|
101
|
+
const now = await this.#bumpRevision(ops, scope);
|
|
102
|
+
return toRecord(await ops.upsertOne("factory_skill_overrides", [
|
|
103
|
+
"org_id",
|
|
104
|
+
"factory_project_id",
|
|
105
|
+
"skill_name"
|
|
106
|
+
], {
|
|
107
|
+
...projectWhere(scope),
|
|
108
|
+
skill_name: skillName,
|
|
109
|
+
content,
|
|
110
|
+
base_hash: baseHash,
|
|
111
|
+
updated_by: updatedBy,
|
|
112
|
+
updated_at: now
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** False when the skill had no override; the revision only moves when a row was removed. */
|
|
117
|
+
async delete({ skillName, ...scope }) {
|
|
118
|
+
await this.#ensureRevisionRow(scope);
|
|
119
|
+
return this.storage.withTransaction(async (ops) => {
|
|
120
|
+
let deleted = false;
|
|
121
|
+
await ops.updateAtomic("factory_skill_override_revisions", projectWhere(scope), async (row) => {
|
|
122
|
+
deleted = await ops.deleteMany("factory_skill_overrides", {
|
|
123
|
+
...projectWhere(scope),
|
|
124
|
+
skill_name: skillName
|
|
125
|
+
}) > 0;
|
|
126
|
+
return deleted ? {
|
|
127
|
+
revision: row.revision + 1,
|
|
128
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
129
|
+
} : null;
|
|
130
|
+
});
|
|
131
|
+
return deleted;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Created outside the write transaction: on Postgres a lost insert race would abort the
|
|
136
|
+
* transaction, while `upsertOne` here retries it as an update.
|
|
137
|
+
*/
|
|
138
|
+
async #ensureRevisionRow(scope) {
|
|
139
|
+
if (await this.#db.findOne("factory_skill_override_revisions", projectWhere(scope))) return;
|
|
140
|
+
await this.#db.upsertOne("factory_skill_override_revisions", ["org_id", "factory_project_id"], {
|
|
141
|
+
...projectWhere(scope),
|
|
142
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** Locks the project's revision row, so concurrent writers to one project serialize behind it. */
|
|
146
|
+
async #bumpRevision(ops, scope) {
|
|
147
|
+
const now = /* @__PURE__ */ new Date();
|
|
148
|
+
if (!await ops.updateAtomic("factory_skill_override_revisions", projectWhere(scope), (row) => ({
|
|
149
|
+
revision: row.revision + 1,
|
|
150
|
+
updated_at: now
|
|
151
|
+
}))) throw new Error("Skill override revision row is missing");
|
|
152
|
+
return now;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
export { SKILL_OVERRIDES_SCHEMA, SKILL_OVERRIDE_REVISIONS_SCHEMA, SkillOverridesStorage };
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/skill-overrides/base.ts"],"sourcesContent":["import { FactoryStorageDomain } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\n/** A project's edited copy of one Factory skill's SKILL.md. */\nexport interface SkillOverrideRecord {\n orgId: string;\n projectId: string;\n skillName: string;\n /** The full edited SKILL.md, frontmatter included. */\n content: string;\n /** sha256 of the original SKILL.md the edit was made against. */\n baseHash: string;\n updatedBy: string;\n updatedAt: Date;\n}\n\n/** Every override of one project, read at one revision. */\nexport interface SkillOverrideSnapshot {\n revision: number;\n overrides: SkillOverrideRecord[];\n}\n\ninterface ProjectScope {\n orgId: string;\n projectId: string;\n}\n\ninterface SkillScope extends ProjectScope {\n skillName: string;\n}\n\nexport const SKILL_OVERRIDES_SCHEMA: CollectionSchema = {\n name: 'factory_skill_overrides',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n skill_name: { type: 'text' },\n content: { type: 'text' },\n base_hash: { type: 'text' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'factory_skill_overrides_scope_key', columns: ['org_id', 'factory_project_id', 'skill_name'] },\n ],\n};\n\n/**\n * One row per project whose `revision` is incremented in the same transaction as every save and\n * revert, so skill sources can tell an unchanged override set from one indexed row read.\n */\nexport const SKILL_OVERRIDE_REVISIONS_SCHEMA: CollectionSchema = {\n name: 'factory_skill_override_revisions',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n revision: { type: 'integer', default: 0 },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'factory_skill_override_revisions_scope_key', columns: ['org_id', 'factory_project_id'] }],\n};\n\ninterface SkillOverrideDbRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n skill_name: string;\n content: string;\n base_hash: string;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface RevisionDbRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n revision: number;\n updated_at: Date;\n}\n\nfunction toRecord(row: SkillOverrideDbRow): SkillOverrideRecord {\n return {\n orgId: row.org_id,\n projectId: row.factory_project_id,\n skillName: row.skill_name,\n content: row.content,\n baseHash: row.base_hash,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n };\n}\n\nconst projectWhere = ({ orgId, projectId }: ProjectScope) => ({ org_id: orgId, factory_project_id: projectId });\n\nexport class SkillOverridesStorage extends FactoryStorageDomain {\n constructor() {\n super('skill-overrides');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([SKILL_OVERRIDES_SCHEMA, SKILL_OVERRIDE_REVISIONS_SCHEMA]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany('factory_skill_overrides', {});\n await this.ops.deleteMany('factory_skill_override_revisions', {});\n }\n\n get #db(): FactoryStorageOps {\n return this.ops;\n }\n\n /** 0 until the project's first save. */\n async revision(scope: ProjectScope): Promise<number> {\n const row = await this.#db.findOne<RevisionDbRow>('factory_skill_override_revisions', projectWhere(scope));\n return row?.revision ?? 0;\n }\n\n async list(scope: ProjectScope): Promise<SkillOverrideRecord[]> {\n const rows = await this.#db.findMany<SkillOverrideDbRow>('factory_skill_overrides', projectWhere(scope), {\n orderBy: [['skill_name', 'asc']],\n });\n return rows.map(toRecord);\n }\n\n /**\n * Reads the revision before the rows, so a write landing in between pairs newer rows with an\n * older revision: the caller re-reads at the next check instead of caching stale rows as current.\n */\n async snapshot(scope: ProjectScope): Promise<SkillOverrideSnapshot> {\n const revision = await this.revision(scope);\n return { revision, overrides: await this.list(scope) };\n }\n\n async get({ skillName, ...scope }: SkillScope): Promise<SkillOverrideRecord | null> {\n const row = await this.#db.findOne<SkillOverrideDbRow>('factory_skill_overrides', {\n ...projectWhere(scope),\n skill_name: skillName,\n });\n return row ? toRecord(row) : null;\n }\n\n async upsert({\n content,\n baseHash,\n updatedBy,\n skillName,\n ...scope\n }: SkillScope & { content: string; baseHash: string; updatedBy: string }): Promise<SkillOverrideRecord> {\n await this.#ensureRevisionRow(scope);\n return this.storage.withTransaction(async ops => {\n const now = await this.#bumpRevision(ops, scope);\n const row = await ops.upsertOne<SkillOverrideDbRow>(\n 'factory_skill_overrides',\n ['org_id', 'factory_project_id', 'skill_name'],\n {\n ...projectWhere(scope),\n skill_name: skillName,\n content,\n base_hash: baseHash,\n updated_by: updatedBy,\n updated_at: now,\n },\n );\n return toRecord(row);\n });\n }\n\n /** False when the skill had no override; the revision only moves when a row was removed. */\n async delete({ skillName, ...scope }: SkillScope): Promise<boolean> {\n await this.#ensureRevisionRow(scope);\n return this.storage.withTransaction(async ops => {\n // Lock the revision row first so the delete and the bump commit together.\n let deleted = false;\n await ops.updateAtomic<RevisionDbRow>('factory_skill_override_revisions', projectWhere(scope), async row => {\n deleted =\n (await ops.deleteMany('factory_skill_overrides', { ...projectWhere(scope), skill_name: skillName })) > 0;\n return deleted ? { revision: row.revision + 1, updated_at: new Date() } : null;\n });\n return deleted;\n });\n }\n\n /**\n * Created outside the write transaction: on Postgres a lost insert race would abort the\n * transaction, while `upsertOne` here retries it as an update.\n */\n async #ensureRevisionRow(scope: ProjectScope): Promise<void> {\n if (await this.#db.findOne('factory_skill_override_revisions', projectWhere(scope))) return;\n await this.#db.upsertOne<RevisionDbRow>('factory_skill_override_revisions', ['org_id', 'factory_project_id'], {\n ...projectWhere(scope),\n updated_at: new Date(),\n });\n }\n\n /** Locks the project's revision row, so concurrent writers to one project serialize behind it. */\n async #bumpRevision(ops: FactoryStorageOps, scope: ProjectScope): Promise<Date> {\n const now = new Date();\n const row = await ops.updateAtomic<RevisionDbRow>('factory_skill_override_revisions', projectWhere(scope), row => ({\n revision: row.revision + 1,\n updated_at: now,\n }));\n if (!row) throw new Error('Skill override revision row is missing');\n return now;\n }\n}\n"],"mappings":";;AA+BA,MAAa,yBAA2C;CACtD,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,YAAY,EAAE,MAAM,OAAO;EAC3B,SAAS,EAAE,MAAM,OAAO;EACxB,WAAW,EAAE,MAAM,OAAO;EAC1B,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,eAAe,CACb;EAAE,MAAM;EAAqC,SAAS;GAAC;GAAU;GAAsB;EAAY;CAAE,CACvG;AACF;;;;;AAMA,MAAa,kCAAoD;CAC/D,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,UAAU;GAAE,MAAM;GAAW,SAAS;EAAE;EACxC,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,eAAe,CAAC;EAAE,MAAM;EAA8C,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AACnH;AAqBA,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|
|
|
387
387
|
factoryProjectId: string;
|
|
388
388
|
board: string | null;
|
|
389
389
|
externalSource: ExternalWorkItemSource | null;
|
|
390
|
-
/**
|
|
391
|
-
* Org-wide ownership key for the external record this card tracks, or null
|
|
392
|
-
* for cards that never claimed one (older rows, integrations without claims,
|
|
393
|
-
* finished cards). Unique per org while set.
|
|
394
|
-
*/
|
|
395
|
-
claimKey: string | null;
|
|
396
390
|
parentWorkItemId: string | null;
|
|
397
391
|
title: string;
|
|
398
392
|
stages: WorkItemStage[];
|
|
@@ -431,8 +425,6 @@ export interface WorkItemRow {
|
|
|
431
425
|
export interface CreateWorkItemInput {
|
|
432
426
|
board?: string;
|
|
433
427
|
externalSource?: ExternalWorkItemSource | null;
|
|
434
|
-
/** See {@link WorkItemRow.claimKey}. Refused with {@link WorkItemClaimConflictError} when another project holds it. */
|
|
435
|
-
claimKey?: string | null;
|
|
436
428
|
parentWorkItemId?: string | null;
|
|
437
429
|
title: string;
|
|
438
430
|
stages?: WorkItemStage[];
|
|
@@ -494,12 +486,6 @@ export declare function externalSourceKey(source: ExternalWorkItemSource | null
|
|
|
494
486
|
export declare class WorkItemRelationError extends Error {
|
|
495
487
|
readonly code = "invalid_work_item_relation";
|
|
496
488
|
}
|
|
497
|
-
/** Another card in the org already holds the claim the write asked for. */
|
|
498
|
-
export declare class WorkItemClaimConflictError extends Error {
|
|
499
|
-
readonly claimant: WorkItemRow;
|
|
500
|
-
readonly code = "work_item_claim_conflict";
|
|
501
|
-
constructor(claimant: WorkItemRow);
|
|
502
|
-
}
|
|
503
489
|
export declare class WorkItemUpdateConflictError extends Error {
|
|
504
490
|
readonly reason: 'board' | 'revision';
|
|
505
491
|
readonly code = "work_item_update_conflict";
|
|
@@ -594,26 +580,6 @@ export declare class WorkItemsStorage extends FactoryStorageDomain {
|
|
|
594
580
|
orgId: string;
|
|
595
581
|
source: ExternalWorkItemSource;
|
|
596
582
|
}): Promise<WorkItemRow[]>;
|
|
597
|
-
/** The one card in the org holding `claimKey`, if any. */
|
|
598
|
-
getByClaimKey({ orgId, claimKey }: {
|
|
599
|
-
orgId: string;
|
|
600
|
-
claimKey: string;
|
|
601
|
-
}): Promise<WorkItemRow | null>;
|
|
602
|
-
/** Drop the org-wide claims a project's cards hold, so a deleted project stops reserving their records. */
|
|
603
|
-
releaseProjectClaims({ orgId, factoryProjectId }: {
|
|
604
|
-
orgId: string;
|
|
605
|
-
factoryProjectId: string;
|
|
606
|
-
}): Promise<void>;
|
|
607
|
-
/**
|
|
608
|
-
* Give an unclaimed card the org-wide claim for its record. Returns the card
|
|
609
|
-
* once claimed, or null when the card already carries a different claim or
|
|
610
|
-
* another card in the org holds this one.
|
|
611
|
-
*/
|
|
612
|
-
claimWorkItem({ orgId, id, claimKey, }: {
|
|
613
|
-
orgId: string;
|
|
614
|
-
id: string;
|
|
615
|
-
claimKey: string;
|
|
616
|
-
}): Promise<WorkItemRow | null>;
|
|
617
583
|
getForProject(orgId: string, factoryProjectId: string, id: string): Promise<WorkItemRow | null>;
|
|
618
584
|
getTransitionResultByIngress(orgId: string, factoryProjectId: string, identity: string): Promise<Record<string, unknown> | null>;
|
|
619
585
|
commitTransition(input: CommitFactoryTransitionInput): Promise<CommitFactoryTransitionResult>;
|