Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

Parameters (-p) and selectors (-s) are now logged to stderr when the CLI runs, making it easier to debug and verify what values were used.

Changes

  • Logging: Added one-time logging of parameters and selectors in context.Run() after the task is found

    • Format: msg=Parameters params="key=value,..." and msg=Selectors selectors="{key=val, ...}"
    • Always logs (no zero checks) - empty params show as params="" and empty selectors show as selectors="{}"
    • Logging occurs after findTask() to capture task_name selector and any selectors from task/command frontmatter
    • Resume mode selector (resume=true) is included when -r flag is used
  • Tests: Added TestLogsParametersAndSelectors covering all scenarios (with params, selectors, resume mode, empty)

  • Security test fix: Updated TestExpanderSecurityIntegration to check only stdout (prompt) for parameter re-expansion, not stderr (logs)

Example

$ coding-context -p issue=123 -p user=alice -s env=prod task-name
time=... level=INFO msg=Parameters params="issue=123,user=alice"
time=... level=INFO msg=Selectors selectors="{env=prod, task_name=task-name}"
...

# Even with no CLI params/selectors, task_name is always added
$ coding-context task-name
time=... level=INFO msg=Parameters params=""
time=... level=INFO msg=Selectors selectors="{task_name=task-name}"
...
Original prompt

Log the parameters and selectors used. Make sure this is not duplicated.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Log parameters when set (non-empty) to stderr
- Log selectors when set (non-empty) to stderr
- Ensure logging happens exactly once in Run method
- Add comprehensive unit tests for logging behavior
- Tests cover all scenarios: with params, selectors, resume mode, and empty cases

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
}

// Log selectors if any are set
if len(cc.includes) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can change after the task is found?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, selectors are modified after the task is found. The findTask() method adds task_name as a selector (line 107) and merges selectors from task frontmatter (line 129). Commands can also add selectors (line 227).

Fixed in 3fe95e3 - moved logging to after findTask() is called so we capture the complete selector state including task_name and any task/command frontmatter selectors.

}

// Log parameters if any are set
if len(cc.params) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a zero check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the zero check in 3fe95e3 - now always logs parameters and selectors even if empty (params="" and selectors="{}").

The TestExpanderSecurityIntegration test was checking that sensitive parameter
values don't appear anywhere in the output. However, with the new parameter
logging, the parameter values legitimately appear in stderr logs.

Updated the test to only check the actual prompt output (stdout) for sensitive
data re-expansion, not the logging output (stderr). This preserves the security
check while allowing legitimate parameter logging.

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copilot AI changed the title [WIP] Log parameters and selectors used without duplication Log parameters and selectors on startup Dec 24, 2025
Copilot AI requested a review from alexec December 24, 2025 02:22
- Move parameter/selector logging to after findTask() is called
- This ensures we capture task_name and any selectors from task/command frontmatter
- Remove length checks - always log even if empty (per review feedback)
- Update test expectations to reflect always-logging behavior
- task_name selector is always added during findTask

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
@alexec alexec marked this pull request as ready for review December 24, 2025 02:28
Copilot AI review requested due to automatic review settings December 24, 2025 02:28
Copilot AI changed the title Log parameters and selectors on startup Log parameters and selectors after task is found Dec 24, 2025
@alexec alexec enabled auto-merge (squash) December 24, 2025 02:28
Copilot AI requested a review from alexec December 24, 2025 02:28
@alexec alexec merged commit 5633e5b into main Dec 24, 2025
5 checks passed
@alexec alexec deleted the copilot/log-parameters-and-selectors branch December 24, 2025 02:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds diagnostic logging to output parameters and selectors during the context assembly process. The logging occurs after the task is found to ensure all selectors from task/command frontmatter are captured.

Key changes:

  • Added INFO-level logging of parameters and selectors in context.go after task resolution
  • Added comprehensive table-driven unit tests for the new logging functionality
  • Updated security integration test to distinguish between parameter logging (stderr) and prompt output (stdout)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/codingcontext/context.go Added two log statements to output parameters and selectors after task is found, ensuring all additions from frontmatter are captured
pkg/codingcontext/context_test.go Added comprehensive table-driven test TestLogsParametersAndSelectors covering various scenarios including resume mode and empty parameters/selectors
integration_test.go Updated TestExpanderSecurityIntegration to separate stderr (logs) from stdout (prompt) when validating that sensitive parameters don't appear in the generated prompt

Comment on lines +1872 to +1873
expectParamsLog bool
expectSelectors bool // Always true since task_name is added
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expectParamsLog and expectSelectors fields are always set to true in all test cases, making them unnecessary. Since the PR description indicates that logging always occurs (even when empty), these boolean fields add complexity without value. Consider removing these fields and simplifying the test to always verify that exactly one log message appears for each type.

Copilot uses AI. Check for mistakes.
Comment on lines +1950 to +1967
// Verify parameters logging - always exactly once
if tt.expectParamsLog {
if paramsCount != 1 {
t.Errorf("expected exactly 1 Parameters log, got %d", paramsCount)
}
} else {
if paramsCount != 0 {
t.Errorf("expected no Parameters log, got %d", paramsCount)
}
}

// Verify selectors logging - always exactly once
if tt.expectSelectors {
if selectorsCount != 1 {
t.Errorf("expected exactly 1 Selectors log, got %d", selectorsCount)
}
} else {
if selectorsCount != 0 {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else branches in this verification code are unreachable since expectParamsLog and expectSelectors are always true in all test cases. This is dead code that should be removed along with the boolean fields, or the test cases should be updated to actually test scenarios where logging does not occur (if such scenarios exist).

Suggested change
// Verify parameters logging - always exactly once
if tt.expectParamsLog {
if paramsCount != 1 {
t.Errorf("expected exactly 1 Parameters log, got %d", paramsCount)
}
} else {
if paramsCount != 0 {
t.Errorf("expected no Parameters log, got %d", paramsCount)
}
}
// Verify selectors logging - always exactly once
if tt.expectSelectors {
if selectorsCount != 1 {
t.Errorf("expected exactly 1 Selectors log, got %d", selectorsCount)
}
} else {
if selectorsCount != 0 {
// Verify parameters logging - expected count depends on test case
expectedParamsCount := 0
if tt.expectParamsLog {
expectedParamsCount = 1
}
if paramsCount != expectedParamsCount {
if expectedParamsCount == 1 {
t.Errorf("expected exactly 1 Parameters log, got %d", paramsCount)
} else {
t.Errorf("expected no Parameters log, got %d", paramsCount)
}
}
// Verify selectors logging - expected count depends on test case
expectedSelectorsCount := 0
if tt.expectSelectors {
expectedSelectorsCount = 1
}
if selectorsCount != expectedSelectorsCount {
if expectedSelectorsCount == 1 {
t.Errorf("expected exactly 1 Selectors log, got %d", selectorsCount)
} else {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants