@modality-counter/core 0.0.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 (32) hide show
  1. package/dist/index.js +1989 -0
  2. package/dist/types/__tests__/CategoryLinkValidation.test.d.ts +13 -0
  3. package/dist/types/__tests__/MethodValidation.test.d.ts +10 -0
  4. package/dist/types/__tests__/PersonaValidation.test.d.ts +10 -0
  5. package/dist/types/__tests__/TemplateValidator.test.d.ts +19 -0
  6. package/dist/types/__tests__/security-integrity.test.d.ts +1 -0
  7. package/dist/types/__tests__/security-validation.test.d.ts +1 -0
  8. package/dist/types/confs/const.d.ts +2 -0
  9. package/dist/types/confs/domain-config.d.ts +27 -0
  10. package/dist/types/counter_aliases.d.ts +55 -0
  11. package/dist/types/index.d.ts +25 -0
  12. package/dist/types/mcp_counter.d.ts +5 -0
  13. package/dist/types/protocols/__tests__/BehaviorProtocol.test.d.ts +1 -0
  14. package/dist/types/protocols/__tests__/PartyModeProtocol.test.d.ts +1 -0
  15. package/dist/types/protocols/__tests__/ProtocolValidation.test.d.ts +1 -0
  16. package/dist/types/schemas/ExecutionFlow.d.ts +11 -0
  17. package/dist/types/schemas/counter_schemas.d.ts +31 -0
  18. package/dist/types/schemas/methodology-validation.d.ts +180 -0
  19. package/dist/types/schemas/persona-validation.d.ts +68 -0
  20. package/dist/types/schemas/protocol-validation.d.ts +19 -0
  21. package/dist/types/schemas/template-validation.d.ts +84 -0
  22. package/dist/types/schemas/validation-types.d.ts +90 -0
  23. package/dist/types/tools/validate-counter.d.ts +23 -0
  24. package/dist/types/util_counter_data.d.ts +45 -0
  25. package/dist/types/util_mdx.d.ts +13 -0
  26. package/dist/types/util_prompts.d.ts +12 -0
  27. package/dist/types/util_scripts/DeepWiki.d.ts +63 -0
  28. package/dist/types/util_scripts/__tests__/chunk_size.test.d.ts +5 -0
  29. package/dist/types/util_scripts/chunk_size.d.ts +57 -0
  30. package/dist/types/util_scripts/extractBase64ImagesToFile.d.ts +5 -0
  31. package/dist/types/util_scripts/pagination.d.ts +53 -0
  32. package/package.json +61 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Validation Constants and Types for Counter System
3
+ *
4
+ * Central constants and type definitions for all validation components to avoid circular dependencies
5
+ * and maintain proper separation of concerns. This file contains both configurable validation limits
6
+ * and TypeScript type definitions for consistent validation across the system.
7
+ */
8
+ export declare const EXPECTED_OUTPUT_LIMITS: {
9
+ readonly ARRAY_MIN_ITEMS: 1;
10
+ readonly ARRAY_MAX_ITEMS: 20;
11
+ readonly GROUP_MIN_COUNT: 2;
12
+ readonly GROUP_MAX_COUNT: 5;
13
+ readonly ITEM_MIN_LENGTH: 30;
14
+ readonly ITEM_MAX_LENGTH: 200;
15
+ readonly GROUP_ITEM_MAX: 6;
16
+ readonly GROUP_ITEM_MIN: 1;
17
+ readonly TOTAL_ITEMS_MIN: 3;
18
+ readonly TOTAL_ITEMS_MAX: 20;
19
+ readonly GROUP_NAME_PATTERN: RegExp;
20
+ };
21
+ export declare const METHOD_LIMITS: {
22
+ readonly NAME_PATTERN: RegExp;
23
+ readonly TITLE_MIN_LENGTH: 1;
24
+ readonly ICON_MIN_LENGTH: 1;
25
+ readonly CATEGORY_MIN_LENGTH: 1;
26
+ readonly DESCRIPTION_MIN_LENGTH: 1;
27
+ };
28
+ export declare const PURPOSE_LIMITS: {
29
+ readonly MIN_LENGTH: 20;
30
+ readonly MAX_LENGTH: 500;
31
+ };
32
+ /**
33
+ * Available validation types in the Counter system
34
+ */
35
+ export type ValidationType = 'method' | 'template' | 'protocol' | 'persona' | 'unknown';
36
+ /**
37
+ * Validation status levels
38
+ */
39
+ export type ValidationStatus = 'excellent' | 'good_with_warnings' | 'critical_error';
40
+ /**
41
+ * Base validation result structure
42
+ * Used across all validation components with specific type constraints
43
+ */
44
+ export interface BaseValidationResult<T extends ValidationType = ValidationType> {
45
+ filename: string;
46
+ type: T;
47
+ status: ValidationStatus;
48
+ errors: string[];
49
+ warnings: string[];
50
+ advisories: string[];
51
+ score: number;
52
+ }
53
+ /**
54
+ * Method-specific validation result
55
+ */
56
+ export type MethodValidationResult = BaseValidationResult<'method'>;
57
+ /**
58
+ * Template-specific validation result
59
+ */
60
+ export type TemplateValidationResult = BaseValidationResult<'template'>;
61
+ /**
62
+ * Protocol-specific validation result
63
+ */
64
+ export type ProtocolValidationResult = BaseValidationResult<'protocol'>;
65
+ /**
66
+ * Persona-specific validation result
67
+ */
68
+ export type PersonaValidationResult = BaseValidationResult<'persona'>;
69
+ /**
70
+ * Unknown file type validation result
71
+ */
72
+ export type UnknownValidationResult = BaseValidationResult<'unknown'>;
73
+ /**
74
+ * Union type of all possible validation results
75
+ */
76
+ export type ValidationResult = MethodValidationResult | TemplateValidationResult | ProtocolValidationResult | PersonaValidationResult | UnknownValidationResult;
77
+ /**
78
+ * Validation results aggregation structure
79
+ */
80
+ export interface ValidationResults {
81
+ totalFiles: number;
82
+ validFiles: number;
83
+ criticalErrors: number;
84
+ warnings: number;
85
+ advisories: number;
86
+ results: ValidationResult[];
87
+ }
88
+ export type ExpectedOutputLimits = typeof EXPECTED_OUTPUT_LIMITS;
89
+ export type MethodLimits = typeof METHOD_LIMITS;
90
+ export type PurposeLimits = typeof PURPOSE_LIMITS;
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 🎯 Counter Universal Validation Tool - Zod Edition
4
+ *
5
+ * Modern TypeScript-first validation tool for Counter method and template files
6
+ * using Zod schemas for type-safe validation with excellent error messages.
7
+ *
8
+ * Usage:
9
+ * bun run validate-counter [--type=methods|templates|protocols|personas|all] [--report]
10
+ * bun run validate-counter --verify-protocols [--report]
11
+ *
12
+ * Features:
13
+ * - Type-safe validation with Zod schemas
14
+ * - Automatic TypeScript type generation
15
+ * - Superior error messages and debugging
16
+ * - Support for both flat array and nested object expected_output
17
+ * - Quality scoring and compliance assessment
18
+ */
19
+ import type { MethodValidationResult, TemplateValidationResult } from "../schemas/validation-types.js";
20
+ export declare function calculateQualityScore(result: Pick<MethodValidationResult, "errors" | "warnings" | "advisories">): number;
21
+ export declare function calculateTemplateQualityScore(result: Pick<TemplateValidationResult, "errors" | "warnings" | "advisories">): number;
22
+ export declare function validateWithQuality(data: unknown, type: "method" | "template"): MethodValidationResult;
23
+ export declare function validateTemplateWithQuality(data: unknown): TemplateValidationResult;
@@ -0,0 +1,45 @@
1
+ import { type ResourceType } from "./schemas/counter_schemas";
2
+ interface CounterItem {
3
+ callSign: string;
4
+ type: ResourceType;
5
+ id: string;
6
+ name: string;
7
+ description: string;
8
+ filePath: string;
9
+ folderPath?: string;
10
+ category?: string;
11
+ role?: string;
12
+ }
13
+ /**
14
+ * Get content by ID - TypeScript Promise Detection Solution
15
+ */
16
+ interface CounterContent {
17
+ promptData: Record<string, any>;
18
+ scriptResult?: any;
19
+ scriptSuccess?: boolean;
20
+ partyMode?: string;
21
+ }
22
+ export declare function getCounterContent(items: CounterItem[], callSign: string, params?: any, executeScript?: boolean): Promise<CounterContent>;
23
+ export declare function getAllCounterItems(types?: ResourceType[], baseDir?: string): Promise<CounterItem[]>;
24
+ /**
25
+ * Generic recursive file finder that scans directories for files matching criteria
26
+ * Internal utility for scanning templates, protocols, and other resource types
27
+ */
28
+ interface ScannedFile {
29
+ filename: string;
30
+ fullPath: string;
31
+ }
32
+ /**
33
+ * Find all template files - convenience wrapper around recursiveScanForFiles
34
+ */
35
+ export declare function findAllTemplateFiles(baseDir: string): ScannedFile[];
36
+ /**
37
+ * Extract all CounterMethod references from the references directory
38
+ * Returns object with filename as key and reference data as value
39
+ * When references array is provided, only those files are included with full content
40
+ */
41
+ export type MethodReference = Record<string, {
42
+ description: string;
43
+ content?: string;
44
+ }>;
45
+ export {};
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ /**
3
+ * Parse YAML frontmatter from markdown/mdx content
4
+ * Returns object with parsed frontmatter data and remaining content
5
+ */
6
+ export declare function parseFrontmatter(content: string): {
7
+ data: Record<string, unknown>;
8
+ content: string;
9
+ };
10
+ export declare const readMdx: (Component: React.ReactElement) => string;
11
+ export declare const importMdx: (filePath: string) => Promise<any>;
12
+ export declare const getDirName: () => string;
13
+ export declare const importAbsoluteMdx: (absoluteFilePath: string) => Promise<any>;
@@ -0,0 +1,12 @@
1
+ interface CodeBlock {
2
+ language: string;
3
+ code: string;
4
+ }
5
+ export declare const readMpxPrompt: (promptPath: string, params?: any) => Promise<string>;
6
+ export declare const readMpxYaml: (promptPath: string, params?: any) => Promise<any>;
7
+ /**
8
+ * Read a prompt file from the prompts directory
9
+ */
10
+ export declare function readPrompt(promptPath: string): string;
11
+ export declare function extractCodeBlocks(markdown: string): CodeBlock[];
12
+ export {};
@@ -0,0 +1,63 @@
1
+ export declare class DeepWiki {
2
+ private client;
3
+ private toolParams;
4
+ private toolName;
5
+ private repoName;
6
+ constructor(repoName: string);
7
+ read_wiki_structure(): this;
8
+ read_wiki_contents(): this;
9
+ ask_question(query: string): DeepWiki;
10
+ callOnce(): Promise<any>;
11
+ listTools(): Promise<{
12
+ [x: string]: unknown;
13
+ tools: {
14
+ inputSchema: {
15
+ [x: string]: unknown;
16
+ type: "object";
17
+ properties?: {
18
+ [x: string]: object;
19
+ } | undefined;
20
+ required?: string[] | undefined;
21
+ };
22
+ name: string;
23
+ description?: string | undefined;
24
+ outputSchema?: {
25
+ [x: string]: unknown;
26
+ type: "object";
27
+ properties?: {
28
+ [x: string]: object;
29
+ } | undefined;
30
+ required?: string[] | undefined;
31
+ } | undefined;
32
+ annotations?: {
33
+ title?: string | undefined;
34
+ readOnlyHint?: boolean | undefined;
35
+ destructiveHint?: boolean | undefined;
36
+ idempotentHint?: boolean | undefined;
37
+ openWorldHint?: boolean | undefined;
38
+ } | undefined;
39
+ execution?: {
40
+ taskSupport?: "optional" | "required" | "forbidden" | undefined;
41
+ } | undefined;
42
+ _meta?: {
43
+ [x: string]: unknown;
44
+ } | undefined;
45
+ icons?: {
46
+ src: string;
47
+ mimeType?: string | undefined;
48
+ sizes?: string[] | undefined;
49
+ theme?: "light" | "dark" | undefined;
50
+ }[] | undefined;
51
+ title?: string | undefined;
52
+ }[];
53
+ _meta?: {
54
+ [x: string]: unknown;
55
+ progressToken?: string | number | undefined;
56
+ "io.modelcontextprotocol/related-task"?: {
57
+ taskId: string;
58
+ } | undefined;
59
+ } | undefined;
60
+ nextCursor?: string | undefined;
61
+ }>;
62
+ getToolParams(): any;
63
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Chunk Size Library - Startup Tests
3
+ * Simple core functionality validation
4
+ */
5
+ export {};
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Chunk Size Library - Auto-Chunking Utility for Large Files
3
+ *
4
+ * Provides intelligent pagination-style chunking for large text content.
5
+ * Handles UTF-8 character boundaries and provides pagination metadata.
6
+ *
7
+ * Design: Zero external dependencies, streaming-aware, memory efficient
8
+ */
9
+ /**
10
+ * Metadata for a single chunk
11
+ */
12
+ export interface Chunk {
13
+ /** 0-based chunk index */
14
+ index: number;
15
+ /** Chunk content (UTF-8 safe) */
16
+ content: string;
17
+ /** Total number of chunks */
18
+ total: number;
19
+ /** True if this is the final chunk */
20
+ is_last: boolean;
21
+ }
22
+ /**
23
+ * Options for chunk creation
24
+ */
25
+ interface ChunkOptions {
26
+ /** Chunk size in bytes (default: 4096) */
27
+ size?: number;
28
+ }
29
+ /**
30
+ * Chunker instance for managing content chunks
31
+ */
32
+ interface Chunker {
33
+ /** Get a specific chunk by index */
34
+ getChunk(index: number): Chunk;
35
+ /** Get all chunks as array */
36
+ getChunks(): Chunk[];
37
+ /** Stream chunks with callback (memory efficient) */
38
+ streamChunks(callback: (chunk: Chunk) => void): void;
39
+ /** Get total chunk count */
40
+ getTotalChunks(): number;
41
+ /** Check if index is valid */
42
+ isValidIndex(index: number): boolean;
43
+ }
44
+ /**
45
+ * Create a chunker instance for the given content
46
+ *
47
+ * @param content - Text content to chunk (UTF-8)
48
+ * @param options - Chunking options
49
+ * @returns Chunker instance with pagination interface
50
+ *
51
+ * @example
52
+ * const chunker = createChunker(largeFileContent, { size: 8192 });
53
+ * const chunk0 = chunker.getChunk(0);
54
+ * const allChunks = chunker.getChunks();
55
+ */
56
+ export declare function createChunker(content: string, options?: ChunkOptions): Chunker;
57
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Extract base64 images from MCP response and store as files
3
+ * Stores images in /tmp/.assets/ with filename: {nodeId}.{ext}
4
+ */
5
+ export declare function extractAndStoreBase64Images(content: any[], nodeId: string | undefined): Promise<string[]>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Pagination Metadata - Shared utility for chunked content retrieval
3
+ *
4
+ * Simple, reusable types and helpers for paginating large content
5
+ * across fetch-page, chromium-code, and other elicit methods.
6
+ */
7
+ /**
8
+ * Pagination info for a single chunk
9
+ */
10
+ export interface Pagination {
11
+ chunk_index: number;
12
+ next_chunk_index: number;
13
+ total_chunks: number;
14
+ is_last: boolean;
15
+ chunk_pagination_guide: object;
16
+ }
17
+ /**
18
+ * Get pagination metadata for a chunk
19
+ *
20
+ * @param content - Content to chunk (string or array)
21
+ * @param chunkIndex - Current chunk index (0-based)
22
+ * @param maxChars - Max characters per chunk
23
+ * @returns Pagination metadata
24
+ */
25
+ export declare function getPagination(content: string | any[], chunkIndex: number, maxChars?: number): Pagination;
26
+ /**
27
+ * Check if content requires chunking
28
+ *
29
+ * @param content - Content to check (string or array)
30
+ * @param maxChars - Max character limit
31
+ * @returns true if content exceeds limit
32
+ */
33
+ export declare function needsChunking(content: string | any[], maxChars?: number): boolean;
34
+ /**
35
+ * Get specific chunk from content
36
+ *
37
+ * @param content - Full content (string or array)
38
+ * @param chunkIndex - Which chunk to retrieve (0-based)
39
+ * @param maxChars - Max characters per chunk
40
+ * @returns The requested chunk content (string or array)
41
+ */
42
+ export declare function getChunk(content: string | any[], chunkIndex?: number, maxChars?: number): string | any[];
43
+ /**
44
+ * Generate smart guidance for file retrieval when chunk_size is enabled
45
+ * Helps AI models know to use chunking when they encounter large files
46
+ *
47
+ * @param options - Optional configuration for guidance generation
48
+ * @returns Guidance object with chunking strategy and examples
49
+ */
50
+ export interface FileRetrievalGuidanceOptions {
51
+ maxChars?: number;
52
+ description?: string;
53
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "version": "0.0.0",
3
+ "name": "@modality-counter/core",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/modality-ai/core.git"
7
+ },
8
+ "homepage": "https://github.com/modality-ai/core",
9
+ "description": "",
10
+ "keywords": [
11
+ "modality-counter"
12
+ ],
13
+ "author": "Hill <hill@kimo.com>",
14
+ "license": "ISC",
15
+ "peerDependencies": {
16
+ "modality-mcp-kit": "^1.2.2",
17
+ "react": "^19.2.3",
18
+ "react-dom": "^19.2.3"
19
+ },
20
+ "dependencies": {
21
+ "@mdx-js/esbuild": "^3.1.1",
22
+ "hono": "^4.11.3",
23
+ "modality-ai": "^0.2.1",
24
+ "modality-kit": "^0.15.3",
25
+ "modality-safe": "^0.3.3",
26
+ "node-html-markdown": "^2.0.0",
27
+ "remark-frontmatter": "^5.0.0",
28
+ "reshow-build": "^1.3.2",
29
+ "ucfirst-js": "^0.2.0",
30
+ "valibot": "^1.2.0",
31
+ "xdm": "^3.4.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/bun": "^1.3.5",
35
+ "@types/react": "^19.2.7",
36
+ "@types/react-dom": "^19.2.3",
37
+ "typescript": "^5.9.3"
38
+ },
39
+ "exports": {
40
+ "types": "./dist/types/index.d.ts",
41
+ "require": "./dist/index.js",
42
+ "import": "./dist/index.js"
43
+ },
44
+ "types": "./dist/types/index.d.ts",
45
+ "main": "./dist/index.js",
46
+ "module": "./dist/index.js",
47
+ "scripts": {
48
+ "build:clean": "find ./dist -name '*.*' | xargs rm -rf",
49
+ "build:types": "bun tsc -p ./",
50
+ "build:src": "bun build.ts",
51
+ "build": "bun run build:clean && bun run build:types && bun run build:src",
52
+ "dev": "bunx concurrently 'bun --watch tsc -p ./' 'bun build:src -- --watch --sourcemap=inline'",
53
+ "test": "bun run build && bun test",
54
+ "prepublishOnly": "npm t"
55
+ },
56
+ "files": [
57
+ "package.json",
58
+ "README.md",
59
+ "dist"
60
+ ]
61
+ }