faceted-prompting 0.0.0 → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +208 -2
- package/bin/facet +2 -0
- package/dist/cli/compose-context.d.ts +8 -0
- package/dist/cli/compose-context.d.ts.map +1 -0
- package/dist/cli/compose-context.js +194 -0
- package/dist/cli/compose-context.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +144 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/install-skill/facets.d.ts +28 -0
- package/dist/cli/install-skill/facets.d.ts.map +1 -0
- package/dist/cli/install-skill/facets.js +160 -0
- package/dist/cli/install-skill/facets.js.map +1 -0
- package/dist/cli/install-skill/flow.d.ts +13 -0
- package/dist/cli/install-skill/flow.d.ts.map +1 -0
- package/dist/cli/install-skill/flow.js +63 -0
- package/dist/cli/install-skill/flow.js.map +1 -0
- package/dist/cli/install-skill/modes.d.ts +27 -0
- package/dist/cli/install-skill/modes.d.ts.map +1 -0
- package/dist/cli/install-skill/modes.js +130 -0
- package/dist/cli/install-skill/modes.js.map +1 -0
- package/dist/cli/install-skill/targets.d.ts +10 -0
- package/dist/cli/install-skill/targets.d.ts.map +1 -0
- package/dist/cli/install-skill/targets.js +27 -0
- package/dist/cli/install-skill/targets.js.map +1 -0
- package/dist/cli/path-guard.d.ts +12 -0
- package/dist/cli/path-guard.d.ts.map +1 -0
- package/dist/cli/path-guard.js +81 -0
- package/dist/cli/path-guard.js.map +1 -0
- package/dist/cli/runner.d.ts +10 -0
- package/dist/cli/runner.d.ts.map +1 -0
- package/dist/cli/runner.js +66 -0
- package/dist/cli/runner.js.map +1 -0
- package/dist/cli/select.d.ts +7 -0
- package/dist/cli/select.d.ts.map +1 -0
- package/dist/cli/select.js +70 -0
- package/dist/cli/select.js.map +1 -0
- package/dist/cli/skill-commands.d.ts +8 -0
- package/dist/cli/skill-commands.d.ts.map +1 -0
- package/dist/cli/skill-commands.js +44 -0
- package/dist/cli/skill-commands.js.map +1 -0
- package/dist/cli/skill-file-ops.d.ts +3 -0
- package/dist/cli/skill-file-ops.d.ts.map +1 -0
- package/dist/cli/skill-file-ops.js +89 -0
- package/dist/cli/skill-file-ops.js.map +1 -0
- package/dist/cli/skill-renderer.d.ts +24 -0
- package/dist/cli/skill-renderer.d.ts.map +1 -0
- package/dist/cli/skill-renderer.js +194 -0
- package/dist/cli/skill-renderer.js.map +1 -0
- package/dist/cli/skill-types.d.ts +31 -0
- package/dist/cli/skill-types.d.ts.map +1 -0
- package/dist/cli/skill-types.js +2 -0
- package/dist/cli/skill-types.js.map +1 -0
- package/dist/cli/types.d.ts +17 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/compose-definition.d.ts +3 -0
- package/dist/compose-definition.d.ts.map +1 -0
- package/dist/compose-definition.js +99 -0
- package/dist/compose-definition.js.map +1 -0
- package/dist/compose.d.ts +18 -0
- package/dist/compose.d.ts.map +1 -0
- package/dist/compose.js +51 -0
- package/dist/compose.js.map +1 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +82 -0
- package/dist/config/index.js.map +1 -0
- package/dist/data-engine.d.ts +49 -0
- package/dist/data-engine.d.ts.map +1 -0
- package/dist/data-engine.js +85 -0
- package/dist/data-engine.js.map +1 -0
- package/dist/escape.d.ts +14 -0
- package/dist/escape.d.ts.map +1 -0
- package/dist/escape.js +16 -0
- package/dist/escape.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/init/index.d.ts +17 -0
- package/dist/init/index.d.ts.map +1 -0
- package/dist/init/index.js +197 -0
- package/dist/init/index.js.map +1 -0
- package/dist/output/index.d.ts +10 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +67 -0
- package/dist/output/index.js.map +1 -0
- package/dist/prompt-payload.d.ts +8 -0
- package/dist/prompt-payload.d.ts.map +1 -0
- package/dist/prompt-payload.js +24 -0
- package/dist/prompt-payload.js.map +1 -0
- package/dist/resolve.d.ts +73 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +160 -0
- package/dist/resolve.js.map +1 -0
- package/dist/scope.d.ts +47 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +69 -0
- package/dist/scope.js.map +1 -0
- package/dist/template.d.ts +27 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +49 -0
- package/dist/template.js.map +1 -0
- package/dist/truncation.d.ts +36 -0
- package/dist/truncation.d.ts.map +1 -0
- package/dist/truncation.js +63 -0
- package/dist/truncation.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +49 -6
package/dist/scope.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @scope reference resolution utilities for TAKT repertoire packages.
|
|
3
|
+
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - isScopeRef(): detect @{owner}/{repo}/{facet-name} format
|
|
6
|
+
* - parseScopeRef(): parse and normalize components
|
|
7
|
+
* - resolveScopeRef(): build file path in repertoire directory
|
|
8
|
+
* - validateScopeOwner/Repo/FacetName(): name constraint validation
|
|
9
|
+
*/
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
/** Matches @{owner}/{repo}/{facet-name} format. */
|
|
12
|
+
const SCOPE_REF_PATTERN = /^@[^/]+\/[^/]+\/[^/]+$/;
|
|
13
|
+
/**
|
|
14
|
+
* Return true if the string is an @{owner}/{repo}/{facet-name} scope reference.
|
|
15
|
+
*/
|
|
16
|
+
export function isScopeRef(ref) {
|
|
17
|
+
return SCOPE_REF_PATTERN.test(ref);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse an @scope reference into its components.
|
|
21
|
+
* Normalizes owner and repo to lowercase.
|
|
22
|
+
*
|
|
23
|
+
* @param ref - e.g. "@nrslib/takt-fullstack/expert-coder"
|
|
24
|
+
*/
|
|
25
|
+
export function parseScopeRef(ref) {
|
|
26
|
+
const withoutAt = ref.slice(1);
|
|
27
|
+
const firstSlash = withoutAt.indexOf('/');
|
|
28
|
+
const owner = withoutAt.slice(0, firstSlash).toLowerCase();
|
|
29
|
+
const rest = withoutAt.slice(firstSlash + 1);
|
|
30
|
+
const secondSlash = rest.indexOf('/');
|
|
31
|
+
const repo = rest.slice(0, secondSlash).toLowerCase();
|
|
32
|
+
const name = rest.slice(secondSlash + 1);
|
|
33
|
+
validateScopeOwner(owner);
|
|
34
|
+
validateScopeRepo(repo);
|
|
35
|
+
validateScopeFacetName(name);
|
|
36
|
+
return { owner, repo, name };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Resolve a scope reference to a file path in the repertoire directory.
|
|
40
|
+
*
|
|
41
|
+
* Path: {repertoireDir}/@{owner}/{repo}/facets/{facetType}/{name}.md
|
|
42
|
+
*
|
|
43
|
+
* @param scopeRef - parsed scope reference
|
|
44
|
+
* @param facetType - e.g. "personas", "policies", "knowledge"
|
|
45
|
+
* @param repertoireDir - root repertoire directory (e.g. ~/.takt/repertoire)
|
|
46
|
+
* @returns Absolute path to the facet file.
|
|
47
|
+
*/
|
|
48
|
+
export function resolveScopeRef(scopeRef, facetType, repertoireDir) {
|
|
49
|
+
return join(repertoireDir, `@${scopeRef.owner}`, scopeRef.repo, 'facets', facetType, `${scopeRef.name}.md`);
|
|
50
|
+
}
|
|
51
|
+
/** Validate owner name: must match /^[a-z0-9][a-z0-9-]*$/ */
|
|
52
|
+
export function validateScopeOwner(owner) {
|
|
53
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(owner)) {
|
|
54
|
+
throw new Error(`Invalid scope owner: "${owner}". Must match /^[a-z0-9][a-z0-9-]*$/ (lowercase alphanumeric and hyphens, not starting with hyphen).`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Validate repo name: must match /^[a-z0-9][a-z0-9._-]*$/ */
|
|
58
|
+
export function validateScopeRepo(repo) {
|
|
59
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/.test(repo)) {
|
|
60
|
+
throw new Error(`Invalid scope repo: "${repo}". Must match /^[a-z0-9][a-z0-9._-]*$/ (lowercase alphanumeric, hyphens, dots, underscores, not starting with hyphen).`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Validate facet name: must match /^[a-z0-9][a-z0-9-]*$/ */
|
|
64
|
+
export function validateScopeFacetName(name) {
|
|
65
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) {
|
|
66
|
+
throw new Error(`Invalid scope facet name: "${name}". Must match /^[a-z0-9][a-z0-9-]*$/ (lowercase alphanumeric and hyphens, not starting with hyphen).`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAYjC,mDAAmD;AACnD,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAEnD;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,SAAS,CAAC,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CAAC;AACH,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,8BAA8B,IAAI,sGAAsG,CACzI,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal template engine for Markdown prompt templates.
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - {{#if variable}}...{{else}}...{{/if}} conditional blocks (no nesting)
|
|
6
|
+
* - {{variableName}} substitution
|
|
7
|
+
*
|
|
8
|
+
* This module has ZERO dependencies on TAKT internals.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Process {{#if variable}}...{{else}}...{{/if}} conditional blocks.
|
|
12
|
+
*
|
|
13
|
+
* A variable is truthy when it is a non-empty string or boolean true.
|
|
14
|
+
* Nesting is NOT supported.
|
|
15
|
+
*/
|
|
16
|
+
export declare function processConditionals(template: string, vars: Record<string, string | boolean>): string;
|
|
17
|
+
/**
|
|
18
|
+
* Replace {{variableName}} placeholders with values from vars.
|
|
19
|
+
* Undefined or false variables are replaced with empty string.
|
|
20
|
+
* True is replaced with the string "true".
|
|
21
|
+
*/
|
|
22
|
+
export declare function substituteVariables(template: string, vars: Record<string, string | boolean>): string;
|
|
23
|
+
/**
|
|
24
|
+
* Render a template string by processing conditionals then substituting variables.
|
|
25
|
+
*/
|
|
26
|
+
export declare function renderTemplate(template: string, vars: Record<string, string | boolean>): string;
|
|
27
|
+
//# sourceMappingURL=template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GACrC,MAAM,CAcR;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GACrC,MAAM,CAUR;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GACrC,MAAM,CAGR"}
|
package/dist/template.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal template engine for Markdown prompt templates.
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - {{#if variable}}...{{else}}...{{/if}} conditional blocks (no nesting)
|
|
6
|
+
* - {{variableName}} substitution
|
|
7
|
+
*
|
|
8
|
+
* This module has ZERO dependencies on TAKT internals.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Process {{#if variable}}...{{else}}...{{/if}} conditional blocks.
|
|
12
|
+
*
|
|
13
|
+
* A variable is truthy when it is a non-empty string or boolean true.
|
|
14
|
+
* Nesting is NOT supported.
|
|
15
|
+
*/
|
|
16
|
+
export function processConditionals(template, vars) {
|
|
17
|
+
return template.replace(/\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g, (_match, varName, body) => {
|
|
18
|
+
const value = vars[varName];
|
|
19
|
+
const isTruthy = value !== undefined && value !== false && value !== '';
|
|
20
|
+
const elseIndex = body.indexOf('{{else}}');
|
|
21
|
+
if (isTruthy) {
|
|
22
|
+
return elseIndex >= 0 ? body.slice(0, elseIndex) : body;
|
|
23
|
+
}
|
|
24
|
+
return elseIndex >= 0 ? body.slice(elseIndex + '{{else}}'.length) : '';
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Replace {{variableName}} placeholders with values from vars.
|
|
29
|
+
* Undefined or false variables are replaced with empty string.
|
|
30
|
+
* True is replaced with the string "true".
|
|
31
|
+
*/
|
|
32
|
+
export function substituteVariables(template, vars) {
|
|
33
|
+
return template.replace(/\{\{(\w+)\}\}/g, (_match, varName) => {
|
|
34
|
+
const value = vars[varName];
|
|
35
|
+
if (value === undefined || value === false)
|
|
36
|
+
return '';
|
|
37
|
+
if (value === true)
|
|
38
|
+
return 'true';
|
|
39
|
+
return value;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Render a template string by processing conditionals then substituting variables.
|
|
44
|
+
*/
|
|
45
|
+
export function renderTemplate(template, vars) {
|
|
46
|
+
const afterConditionals = processConditionals(template, vars);
|
|
47
|
+
return substituteVariables(afterConditionals, vars);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,IAAsC;IAEtC,OAAO,QAAQ,CAAC,OAAO,CACrB,4CAA4C,EAC5C,CAAC,MAAM,EAAE,OAAe,EAAE,IAAY,EAAU,EAAE;QAChD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5B,MAAM,QAAQ,GAAG,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,EAAE,CAAC;QAExE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1D,CAAC;QACD,OAAO,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,IAAsC;IAEtC,OAAO,QAAQ,CAAC,OAAO,CACrB,gBAAgB,EAChB,CAAC,MAAM,EAAE,OAAe,EAAE,EAAE;QAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;YAAE,OAAO,EAAE,CAAC;QACtD,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAgB,EAChB,IAAsC;IAEtC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9D,OAAO,mBAAmB,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context truncation for knowledge and policy facets.
|
|
3
|
+
*
|
|
4
|
+
* When facet content exceeds a character limit, it is trimmed and
|
|
5
|
+
* annotated with source-path metadata so the LLM can consult the
|
|
6
|
+
* original file.
|
|
7
|
+
*
|
|
8
|
+
* This module has ZERO dependencies on TAKT internals.
|
|
9
|
+
*/
|
|
10
|
+
interface PreparedContextBlock {
|
|
11
|
+
readonly content: string;
|
|
12
|
+
readonly truncated: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Trim content to a maximum character length, appending a
|
|
16
|
+
* "...TRUNCATED..." marker when truncation occurs.
|
|
17
|
+
*/
|
|
18
|
+
export declare function trimContextContent(content: string, maxChars: number): PreparedContextBlock;
|
|
19
|
+
/**
|
|
20
|
+
* Standard notice appended to knowledge and policy blocks.
|
|
21
|
+
*/
|
|
22
|
+
export declare function renderConflictNotice(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Prepare a knowledge facet for inclusion in a prompt.
|
|
25
|
+
*
|
|
26
|
+
* Trims to maxChars, appends truncation notice and source path if available.
|
|
27
|
+
*/
|
|
28
|
+
export declare function prepareKnowledgeContent(content: string, maxChars: number, sourcePath?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Prepare a policy facet for inclusion in a prompt.
|
|
31
|
+
*
|
|
32
|
+
* Trims to maxChars, appends authoritative-source notice and source path if available.
|
|
33
|
+
*/
|
|
34
|
+
export declare function preparePolicyContent(content: string, maxChars: number, sourcePath?: string): string;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=truncation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncation.d.ts","sourceRoot":"","sources":["../src/truncation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,UAAU,oBAAoB;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACf,oBAAoB,CAQtB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAcR;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAcR"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context truncation for knowledge and policy facets.
|
|
3
|
+
*
|
|
4
|
+
* When facet content exceeds a character limit, it is trimmed and
|
|
5
|
+
* annotated with source-path metadata so the LLM can consult the
|
|
6
|
+
* original file.
|
|
7
|
+
*
|
|
8
|
+
* This module has ZERO dependencies on TAKT internals.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Trim content to a maximum character length, appending a
|
|
12
|
+
* "...TRUNCATED..." marker when truncation occurs.
|
|
13
|
+
*/
|
|
14
|
+
export function trimContextContent(content, maxChars) {
|
|
15
|
+
if (content.length <= maxChars) {
|
|
16
|
+
return { content, truncated: false };
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
content: `${content.slice(0, maxChars)}\n...TRUNCATED...`,
|
|
20
|
+
truncated: true,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Standard notice appended to knowledge and policy blocks.
|
|
25
|
+
*/
|
|
26
|
+
export function renderConflictNotice() {
|
|
27
|
+
return 'If prompt content conflicts with source files, source files take precedence.';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Prepare a knowledge facet for inclusion in a prompt.
|
|
31
|
+
*
|
|
32
|
+
* Trims to maxChars, appends truncation notice and source path if available.
|
|
33
|
+
*/
|
|
34
|
+
export function prepareKnowledgeContent(content, maxChars, sourcePath) {
|
|
35
|
+
const prepared = trimContextContent(content, maxChars);
|
|
36
|
+
const lines = [prepared.content];
|
|
37
|
+
if (prepared.truncated && sourcePath) {
|
|
38
|
+
lines.push('', `Knowledge is truncated. You MUST consult the source files before making decisions. Source: ${sourcePath}`);
|
|
39
|
+
}
|
|
40
|
+
if (sourcePath) {
|
|
41
|
+
lines.push('', `Knowledge Source: ${sourcePath}`);
|
|
42
|
+
}
|
|
43
|
+
lines.push('', renderConflictNotice());
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Prepare a policy facet for inclusion in a prompt.
|
|
48
|
+
*
|
|
49
|
+
* Trims to maxChars, appends authoritative-source notice and source path if available.
|
|
50
|
+
*/
|
|
51
|
+
export function preparePolicyContent(content, maxChars, sourcePath) {
|
|
52
|
+
const prepared = trimContextContent(content, maxChars);
|
|
53
|
+
const lines = [prepared.content];
|
|
54
|
+
if (prepared.truncated && sourcePath) {
|
|
55
|
+
lines.push('', `Policy is authoritative. If truncated, you MUST read the full policy file and follow it strictly. Source: ${sourcePath}`);
|
|
56
|
+
}
|
|
57
|
+
if (sourcePath) {
|
|
58
|
+
lines.push('', `Policy Source: ${sourcePath}`);
|
|
59
|
+
}
|
|
60
|
+
lines.push('', renderConflictNotice());
|
|
61
|
+
return lines.join('\n');
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=truncation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncation.js","sourceRoot":"","sources":["../src/truncation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,QAAgB;IAEhB,IAAI,OAAO,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC/B,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACvC,CAAC;IACD,OAAO;QACL,OAAO,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,mBAAmB;QACzD,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,8EAA8E,CAAC;AACxF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAe,EACf,QAAgB,EAChB,UAAmB;IAEnB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,KAAK,GAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,QAAQ,CAAC,SAAS,IAAI,UAAU,EAAE,CAAC;QACrC,KAAK,CAAC,IAAI,CACR,EAAE,EACF,8FAA8F,UAAU,EAAE,CAC3G,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,qBAAqB,UAAU,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,oBAAoB,EAAE,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAe,EACf,QAAgB,EAChB,UAAmB;IAEnB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,KAAK,GAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,QAAQ,CAAC,SAAS,IAAI,UAAU,EAAE,CAAC;QACrC,KAAK,CAAC,IAAI,CACR,EAAE,EACF,6GAA6G,UAAU,EAAE,CAC1H,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,kBAAkB,UAAU,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,oBAAoB,EAAE,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for Faceted Prompting.
|
|
3
|
+
*
|
|
4
|
+
* Defines the vocabulary of facets (persona, policy, knowledge, instruction,
|
|
5
|
+
* output-contract) and the structures used by compose() and DataEngine.
|
|
6
|
+
*
|
|
7
|
+
* This module has ZERO dependencies on TAKT internals.
|
|
8
|
+
*/
|
|
9
|
+
/** Plural directory names used in facet resolution. */
|
|
10
|
+
export type FacetKind = 'personas' | 'policies' | 'knowledge' | 'instructions' | 'output-contracts';
|
|
11
|
+
/** A single piece of facet content with optional metadata. */
|
|
12
|
+
export interface FacetContent {
|
|
13
|
+
/** Raw text body of the facet. */
|
|
14
|
+
readonly body: string;
|
|
15
|
+
/** Filesystem path the content was loaded from, if applicable. */
|
|
16
|
+
readonly sourcePath?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A complete set of resolved facet contents to be composed.
|
|
20
|
+
*
|
|
21
|
+
* All fields are optional — a FacetSet may contain only a subset of facets.
|
|
22
|
+
*/
|
|
23
|
+
export interface FacetSet {
|
|
24
|
+
readonly persona?: FacetContent;
|
|
25
|
+
readonly policies?: readonly FacetContent[];
|
|
26
|
+
readonly knowledge?: readonly FacetContent[];
|
|
27
|
+
readonly instruction?: FacetContent;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The output of compose(): facet content assigned to LLM message slots.
|
|
31
|
+
*
|
|
32
|
+
* persona → systemPrompt
|
|
33
|
+
* policy + knowledge + instruction → userMessage
|
|
34
|
+
*/
|
|
35
|
+
export interface ComposedPrompt {
|
|
36
|
+
readonly systemPrompt: string;
|
|
37
|
+
readonly userMessage: string;
|
|
38
|
+
}
|
|
39
|
+
export interface CopyFiles {
|
|
40
|
+
readonly persona: readonly string[];
|
|
41
|
+
readonly knowledge: readonly string[];
|
|
42
|
+
readonly policies: readonly string[];
|
|
43
|
+
readonly instructions: readonly string[];
|
|
44
|
+
}
|
|
45
|
+
export interface ComposedPromptPayload {
|
|
46
|
+
readonly systemPrompt: string;
|
|
47
|
+
readonly userPrompt: string;
|
|
48
|
+
readonly copyFiles: CopyFiles;
|
|
49
|
+
}
|
|
50
|
+
/** User-message sections that can be ordered in compose definitions. */
|
|
51
|
+
export type ComposeOrderEntry = 'policies' | 'knowledge' | 'instruction';
|
|
52
|
+
/** CLI compose definition loaded from YAML. */
|
|
53
|
+
export interface ComposeDefinition {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly description?: string;
|
|
56
|
+
readonly persona: string;
|
|
57
|
+
readonly template?: string;
|
|
58
|
+
readonly knowledge?: readonly string[];
|
|
59
|
+
readonly policies?: readonly string[];
|
|
60
|
+
readonly instruction?: string;
|
|
61
|
+
readonly order?: readonly ComposeOrderEntry[];
|
|
62
|
+
}
|
|
63
|
+
/** Options controlling compose() behaviour. */
|
|
64
|
+
export interface ComposeOptions {
|
|
65
|
+
/** Maximum character length for knowledge/policy content before truncation. */
|
|
66
|
+
readonly contextMaxChars: number;
|
|
67
|
+
/** Optional user-message section order for policies/knowledge/instruction. */
|
|
68
|
+
readonly userMessageOrder?: readonly ComposeOrderEntry[];
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uDAAuD;AACvD,MAAM,MAAM,SAAS,GACjB,UAAU,GACV,UAAU,GACV,WAAW,GACX,cAAc,GACd,kBAAkB,CAAC;AAEvB,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC5C,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC7C,QAAQ,CAAC,WAAW,CA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CAAC;IACjC,8EAA8E;IAC9E,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC1D"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for Faceted Prompting.
|
|
3
|
+
*
|
|
4
|
+
* Defines the vocabulary of facets (persona, policy, knowledge, instruction,
|
|
5
|
+
* output-contract) and the structures used by compose() and DataEngine.
|
|
6
|
+
*
|
|
7
|
+
* This module has ZERO dependencies on TAKT internals.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "faceted-prompting",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Faceted Prompting
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Faceted Prompting — structured prompt composition for LLMs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"facet": "./bin/facet"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"bin/facet"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"watch": "tsc --watch",
|
|
24
|
+
"test": "npm run test:unit",
|
|
25
|
+
"test:unit": "vitest run --config vitest.config.ts",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"test:e2e": "tmp=\"$(mktemp -t faceted-prompting-e2e.XXXXXX)\"; mkdir -p e2e/results; npm run test:e2e:cli >\"$tmp\" 2>&1; code=$?; cat \"$tmp\"; rm -f \"$tmp\"; if [ \"$code\" -eq 0 ]; then msg='test:e2e passed'; else msg=\"test:e2e failed (exit=$code)\"; fi; if command -v osascript >/dev/null 2>&1; then osascript -e \"display notification \\\"$msg\\\" with title \\\"faceted-prompting\\\" subtitle \\\"E2E\\\"\" >/dev/null 2>&1 || true; fi; echo \"[faceted-prompting] $msg\"; exit $code",
|
|
28
|
+
"test:e2e:cli": "vitest run --config vitest.config.e2e.ts --outputFile.json=e2e/results/cli.json",
|
|
29
|
+
"lint": "eslint src/",
|
|
30
|
+
"check:release": "npm run build && npm run lint && npm run test:unit && npm run test:e2e; code=$?; if [ \"$code\" -eq 0 ]; then msg='check:release passed'; else msg=\"check:release failed (exit=$code)\"; fi; if command -v osascript >/dev/null 2>&1; then osascript -e \"display notification \\\"$msg\\\" with title \\\"faceted-prompting\\\" subtitle \\\"Release Check\\\"\" >/dev/null 2>&1 || true; fi; echo \"[faceted-prompting] $msg\"; exit $code",
|
|
31
|
+
"prepublishOnly": "npm run build && npm run test"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"prompt",
|
|
35
|
+
"llm",
|
|
36
|
+
"faceted-prompting",
|
|
37
|
+
"prompt-engineering",
|
|
38
|
+
"ai"
|
|
39
|
+
],
|
|
6
40
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.19.11",
|
|
46
|
+
"eslint": "^9.0.0",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vitest": "^3.2.4"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"traced-config": "^0.1.0",
|
|
52
|
+
"yaml": "^2.8.1"
|
|
10
53
|
}
|
|
11
54
|
}
|