agentleFS
flisk-shflisk-sh/flisk/cli/AGENTS.md

flisk / cli

AGENTS.md49 starsChanged 36 days agoMITView on GitHub

This document defines the coding standards and API conventions for the Flisk CLI package. All contributions should follow these guidelines to maintain consistency.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

14 rules. About 0 are common, 9 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use a camelCase prefix for clarity:

    line 28
  2. Distinctive:

    Use explicit named exports instead of wildcards:

    line 56
  3. Distinctive:

    Always provide explicit return types:

    line 148
  4. Very specific:

    All user-facing errors should use the FliskError class:

    line 167
  5. Very specific:

    Use the errorFactories object for common errors:

    line 184
  6. Distinctive:

    Use consistent validation result pattern:

    line 196
  7. Distinctive:

    Use descriptive names without redundant suffixes:

    line 218
  8. Very specific:

    Place shared types in src/types/index.ts

    line 231
  9. Distinctive:

    Place component-specific types in the component file

    line 232
  10. Very specific:

    Use ? for optional properties and provide defaults where sensible:

    line 236
  11. Very specific:

    Place tests in a __tests__/ folder next to the source they cover.

    line 285
  12. Distinctive:

    Use descriptive test names:

    line 297
  13. Distinctive:

    Use JSDoc for public functions:

    line 316
  14. Distinctive:

    Use inline comments sparingly, only for complex logic:

    line 332

≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Flisk CLI Agent Guidelines

API Conventions & Standards

This document defines the coding standards and API conventions for the Flisk CLI package. All contributions should follow these guidelines to maintain consistency.


Naming Conventions

Functions and Variables

CategoryConventionExample
FunctionscamelCasediscoverResources(), isPortAvailable()
VariablescamelCaseconst resourceCount, let projectRoot
ConstantsUPPER_SNAKE_CASEconst CACHE_TTL = 5000
Private functionscamelCase with underscore prefix_internalHelper() (if needed)

Types and Classes

CategoryConventionExample
ClassesPascalCaseFliskError, TemplateEngine
InterfacesPascalCase, descriptiveDiscoveredResource, ResourceMetadata
Type aliasesPascalCaseResourceStatus, FileType
Factory objectscamelCaseerrorFactories (not Errors)

Boolean Properties

Use a camelCase prefix for clarity:

  • is* for state: isEnabled, isAvailable
  • has* for possession: hasDockerfile, hasTiltfile
  • can* for capability: canReload
  • did* for past actions: didPass, didComplete

Examples:

// ✅ Good
interface CheckResult {
  didPass: boolean;
  isSkipped?: boolean;
  isWarning?: boolean;
}

// ❌ Avoid - No prefix, so it is unclear the value is a boolean
interface CheckResult {
  passed: boolean;
  skipped?: boolean;
  warning?: boolean;
}

Export Patterns

Public API Surface

Use explicit named exports instead of wildcards:

// ✅ Good - Explicit exports
export type {
  DiscoveredResource,
  DiscoveredStack,
  ResourceMetadata,
} from './types/index.js';

export {
  discoverResources,
  discoverStacks,
  findProjectRoot,
} from './utils/services.js';

// ❌ Avoid - Wildcard exports
export * from './types/index.js';
export * from './utils/services.js';

Export Organization

Group exports by category with comments:

/**
 * Component exports for Flisk CLI UI
 */

// Main UI components
export { TabBar } from './TabBar.js';
export { ResourceTable } from './ResourceTable.js';

// Type definitions
export type { TabId } from './TabBar.js';
export type { FileNode } from './FileTree.js';

// Utility constants
export { TOOLTIPS } from './Tooltip.js';

Function Signatures

Parameter Ordering

  1. Required data parameters first
  2. Optional data parameters next
  3. Options object last
// ✅ Good
function processResource(
  name: string,                    // Required data
  config: ResourceConfig,          // Required data
  options: { verbose?: boolean } = {}  // Options last
): ProcessResult

// ❌ Avoid - Mixed ordering
function processResource(
  options: { verbose?: boolean },
  name: string,
  config: ResourceConfig
)

Options Object Pattern

For functions with 3+ parameters or multiple optional parameters:

// ✅ Good - Options object
function runTilt(
  command: string,
  args: string[] = [],
  options: {
    verbose?: boolean;
    inheritStdio?: boolean;
    timeout?: number;
  } = {}
): Promise<TiltCommandResult>

// ❌ Avoid - Too many positional parameters
function runTilt(
  command: string,
  args: string[],
  verbose: boolean,
  inheritStdio: boolean,
  timeout: number
): Promise<TiltCommandResult>

Return Types

Always provide explicit return types:

// ✅ Good
export function findProjectRoot(startDir: string = cwd()): string | null {
  // implementation
}

// ❌ Avoid - Implicit return type
export function findProjectRoot(startDir: string = cwd()) {
  // implementation
}

Error Handling

Use FliskError for CLI Errors

All user-facing errors should use the FliskError class:

import { FliskError } from '../utils/errors.js';

// ✅ Good
throw new FliskError(
  'Resource not found',
  ['Check the resource name', 'Run flisk resources to list all'],
  1  // exit code
);

// ❌ Avoid - Generic errors for user-facing issues
throw new Error('Resource not found');

Error Factories

Use the errorFactories object for common errors:

// ✅ Good - Using factory
errorFactories.resourceNotFound(name).display();
errorFactories.notInProject().display();

// ❌ Avoid - Creating FliskError manually for common cases
new FliskError(`Resource "${name}" not found`, [...]).display();

Validation Results

Use consistent validation result pattern:

// ✅ Good
interface ValidationResult {
  valid: boolean;
  error?: string;
}

function validateResourceName(name: string): ValidationResult {
  if (!name.trim()) {
    return { valid: false, error: 'Name is required' };
  }
  return { valid: true };
}

Type Definitions

Interface Naming

Use descriptive names without redundant suffixes:

// ✅ Good
interface DiscoveredResource { ... }
interface ResourceMetadata { ... }

// ❌ Avoid - Redundant suffixes
interface DiscoveredResourceInterface { ... }
interface ResourceMetadataType { ... }

Type Placement

  • Place shared types in src/types/index.ts
  • Place component-specific types in the component file
  • Export types explicitly using export type

Optional Properties

Use ? for optional properties and provide defaults where sensible:

interface CLIOptions {
  verbose?: boolean;  // Optional, defaults to false
  timeout?: number;   // Optional, has default
}

function runCommand(options: CLIOptions = {}) {
  const verbose = options.verbose ?? false;
  const timeout = options.timeout ?? 5000;
}

File Organization

Directory Structure

src/
├── types/
│   └── index.ts       # Shared type definitions
├── utils/
│   ├── services.ts    # Resource discovery utilities
│   ├── tilt.ts        # Tilt command utilities
│   ├── errors.ts      # Error handling
│   ├── validation.ts  # Validation utilities
│   └── formatting.ts  # Formatting utilities
├── commands/
│   ├── resource.ts    # flisk resource command
│   ├── stack.ts       # flisk stack command
│   └── ...
└── components/
    ├── TabBar.tsx     # UI components
    └── ...

File Naming

  • Commands: [command-name].ts (e.g., resource.ts)
  • Utilities: [category].ts (e.g., services.ts, tilt.ts)
  • Components: [ComponentName].tsx (PascalCase)
  • Tests: __tests__/[filename].test.ts next to the source files

Testing

Test Location

Place tests in a __tests__/ folder next to the source they cover. A few older tests still sit beside their source file; follow the folder pattern for new tests:

commands/
├── resource.ts
├── stack.ts
└── __tests__/
    ├── resource.test.ts
    └── stack-routers.test.ts

Test Naming

Use descriptive test names:

// ✅ Good
describe('resource name validation', () => {
  it('should accept valid kebab-case names', () => { ... });
  it('should reject names with underscores', () => { ... });
});

// ❌ Avoid - Vague names
it('works', () => { ... });
it('test 1', () => { ... });

Documentation

JSDoc Comments

Use JSDoc for public functions:

/**
 * Discover all resources from the project
 *
 * Scans the filesystem for service.json files and parses them.
 *
 * @returns Array of discovered resources sorted by name
 */
export function discoverResources(): DiscoveredResource[] {
  // implementation
}

Inline Comments

Use inline comments sparingly, only for complex logic:

// Calculate next available port from the configured range
const portRange = PORT_RANGES[resourceType];
const assignedPort = findNextPort(existingPorts, portRange);

Common Patterns

Resource Discovery

export function discoverResources(): DiscoveredResource[] {
  const projectRoot = findProjectRoot();
  if (!projectRoot) {
    throw errorFactories.notInProject();
  }
  // ... implementation
}

Command Action Wrapper

export const commandName = new Command('command')
  .description('Description')
  .option('-v, --verbose', 'Enable verbose output', false)
  .action(async (options) => {
    await runCommand(async () => {
      // Command implementation
    });
  });

Result Type

interface Result<T, E = string> {
  success: boolean;
  data?: T;
  error?: E;
}

function doSomething(): Result<Resource, string> {
  try {
    const data = process();
    return { success: true, data };
  } catch (err) {
    return { success: false, error: err.message };
  }
}

Resources

  • Type definitions: cli/src/types/index.ts

Last Updated: 2025-01-30 by Agent #11 (The API Harmonizer)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.